Hacker News new | past | comments | ask | show | jobs | submit login
Introduction to C++ with Game Development (devmaster.net)
31 points by octopus on July 1, 2011 | hide | past | favorite | 18 comments



The example on the bottom can hardly be called C++

  #include "stdio.h"
  
  void main()
  {
  	printf( "Hello world!\n" );
  	getchar();
  }
- main() should return int, not void

- std::cout should be used instead of printf

- std::cin should be used instead of getchar()


I think the STL was too buggy to be used much back in those days. Besides, there's nothing wrong with C style C++.

Edit: I must be tired: this is a tutorial on C++, and thus should use C++ style. Also, despite the old-style windows, this article is quite new.


iostream is not part of the STL, just the standard library.


You're right that it should be int main() to be valid C++:

    2 An implementation shall not predefine the main 
    function. This function shall not be overloaded. It shall
    have a return type of type int, but otherwise
    its type is implementation-defined.
But note:

    5 A return statement in main has the effect of leaving 
    the main function (destroying any objects with auto-
    matic storage duration) and calling exit with the 
    return value as the argument. If control reaches the
    end of main without encountering a return statement, 
    the effect is that of executing
    return 0;
The other two points I disagree with. =P


Thank you for pointing that out. It appears that the author of the article subscribes to the atrocious concept of C/C++, rather than realizing that they're two separate languages.


- Who cares

- No

- No

And you didn't even complain about "stdio.h".


> - Who cares

Compilers care, or should. "void main" is illegal per the spec, and if your compiler happens to do anything useful with that, it's purely out of luck.


If you call it C++, then you should care.


Not really. People who feel the need to point out a use of void main every time they see it have nothing important to talk about.


On the other hand, people who write void main clearly have nothing to teach about C++, because that plainly isn't C++.


Apparently they do, because they're teaching it. But I guess you don't care about that, it's more important that you inform everybody about this distinction whereby you have a definition of C++ that requires more rigorous adherence to one of the standards, because it's very important that people be informed of this. We wouldn't want beginners to write programs that use "void main" and work perfectly fine. For that would be bad. No, this tutorial should be retitled. It should be retitled to "Game Programming with a language that's not exactly C++ but is acceptable to Microsoft's C++ compiler." Because that's a correct title. It would have been a perfectly fine tutorial that would introduce students to C++ programming, but right now it's horrible.

I was so glad to learn that people here are aware that C++ says main should return int. Because I was sitting here, wondering if somebody on Hacker News knows that main should return int. And then Ives came along to say, "I do!" That resolved my question. But then as a special treat, somebody else came along to point out that the iostreams library is not part of the STL. Or is it? I sure wouldn't want to forget the distinction between The SL and The STL. For they are different things. I think.

Confession time: One time, I learned that I had once learned some C++ from a tutorial that had used "void main." I felt doomed. I had just gotten over the phase where I thought it was okay not to correct somebody when not every part of every clause of every sentence they said was correct. But then I found that I liked using void main. And then before you knew it, I started writing <stdlib.h> instead of <cstdlib>, and then I used C99 header files, and then I used variable length arrays, and I used vector::data, and I liked it. The next thing you know I found myself running two threads at the same time, wouldn't you believe it? Now I know that what I was using was not C++, but that what I used was an abomination.


Learning to program C++ via game development strikes me as remarkably akin to learning to maintain a car by starting on a Ferrari. (Well, aside from the notion that a Ferrari is enjoyable to drive, anyway.)

C++ is tricky enough. Game development introduces additional layers of ugliness and complexity that I think can distract from actually learning to write good, secure, safe C++.


On the other hand it is one of the fields where the use of C++ is completly warranted. It is fun and offers challenging problems. I started programming like that and I sure liked it.


You're talking about two different issues. If you're maintaining UDK or something, then yes, C++ is absolutely required. But people who maintain UDK aren't learning to program anymore. They know how to write solid C++ in their sleep, so they can focus on the challenges that game development throws at them.

What eropple was saying - and I completely agree - is that C++ is a difficult language to learn on, especially when writing games. I say this as someone who learned C++ mostly by working on games. The language can tend to distract you from the problems you're trying to solve, and vice versa. The time I spent hunting segfaults could have been used building a more stable codebase or getting my product to the players.


Completely warranted? If you're doing very-high-end stuff, yes. For the majority of indie-esque games and the stuff you'll be capable of doing when learning to program, and learning to write sane code during your formative stages? Not so much.

C# with OpenTK (or SlimDX, or XNA) or Python with PyGame are both superior choices for that sort of thing.


To be fair not everyone is making indie games. Although I wouldn't suggest starting out with C++, and wouldn't suggest it to people wanting to make games for PC as a single developer in a small team, if you eventually want to be a programmer working on AAA PC, console or mobile games you have to know C++ well in order to get hired, even if you primarily work in a different language. C++ is also still required for higher end indie stuff. I don't see that changing any time soon.


If they're not making indie games, or are making "higher end indie stuff," they wouldn't be reading an article like this.


Eh not necessarily. Someone in high school or college could be reading this article because they want to work on AAA games in the future and need a decent starting point, not because they want to start making indie games right now. You have to learn somehow and the game industry still hires junior programmers.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: