03.06 - Reader Comments

Started by
15 comments, last by Teej 22 years, 9 months ago
The following article threads are reserved for forum material only:
  • Selected C Topics
  • Tricks and Techniques
  • Algorithms in C
  • Please post any questions or comments here instead.
Advertisement
RE: C vs C++

This post is a bit of a question and a bit of a catalyst for comment and discussion. Let me set the scene: I, like most people, originally learned programming in procedural languages. Eventually I learned object-oriented programming by way of C++, though I didn't have much time to spend on it before my career took me into Python and Java.

Both Python and Java were a joy to program in, and I became more and more adept over the years at thinking of software architecture in very object-oriented terms.

Now that I'm sitting back down in front of Visual C++ to program games, I've hit the obvious question of "C vs C++" which Teej wrote about. For me, programming games in C++ only seems to make sense. I start to think of the architecture of a game or a game engine and I see objects that represent in-game objects, game rules, interfaces to DirectX (or any other library I wanted to use, making cross-platform development easier), etc. I see these objects talking to one another though implementation-independent interfaces. I see some of them running simultaneously inside of their own threads, communicating via messages. In my mind, it looks beautiful.

Is my vision unattainable? Is it simply naive? After having been spoiled by the lush and powerful OOP stylings of both Java and Python, I find that C++ feels clunky and awkward by comparison. This is obviously due in part to my relative "rustiness" with C++, but it's not something I felt with the other languages.

Is this an argument against the use of C++? Perhaps. But, for me, it also seems an argument against the use of C. Now that I have this vision of OOP game development, I find it hard to conjure a similar vision in procedural terms. Each time I try, it, too, seems awkward and clunky. I feel like there's so much more that I can get out of C++. If I were programming for the Palm Pilot I can see where C would work beautifully. But I have all this computing power in front of me -- is object overhead really that cumbersome? Isn't it negligible, especially considering the benefits it provides, both in what it allows you to do and how it allows you to do it?

I'm not advocating the forum use C++, but I'd love to hear any comments people have on this.

Edited by - silicon_jesus on April 28, 2001 8:24:06 AM
I prefer C++ to C, even though I don't have much experience with C and I don't have terribly extensive experience with C++. The bonus of C++ versus C, to me, is that you can do everything that C can do, only easier. You don't need to change your style of thinking in order to incorporate object oriented program, because C++ isn't completely object oriented. I do agree with Teej's choice of C for a "Beginners" tutorial, though. It seems like virtual functions, friend functions, inheritance, opperator overloading, etc, etc, would cause any games that we created to become more complex, and less easy to understand for people who haven't had any experience using them before. Using C++ without the complex functions, however, would be a waste, as you'd be practically programming in C anyway.

Silicon: All of the things you listed sound definately possible, (although I hear multi-threading is complicated in C++, it is definately possible). A lot of people don't like C++ as much as they do Java because Java is more object oriented and it removes a large amount of the more complicated things that C/C++ deal with. What I've heard about Java is that it can do all of the things that C++ can do and vice-versa, but it is easier to manage at the price of a small amount of control. I don't know if this is true, as I'm a novice C++ programmer at best and I have no Java experience, but I definately think that you should stick with C++.

Edited by - RandomGamer on May 2, 2001 4:49:00 PM
It seems to me that programming games before you can write simple programs is like putting the cart before the horse. Frankly, if you can''t write a computer program, then you are going to become very frustrated trying to write a computer game.

Many of the problems that people have posted suggest that they should really go back to square one and get a few basic books on programming fundamentals. When they understand how to deal with basic things like linker and compile errors, and are able to create the kind of programs that introductory books deal with, then they will be ready to write really simple, 2-D games.

I apologize if you find this post discouraging; BUT, writing a computer game is NOT a good way to learn how to program.
I would like to say that C++ is not just "C with classes". I still makes a lot of "modular" programming when I create games but I don''t go back to C. When I first learned C++, I was thinking that C was just "C++ without classes" but it''s not true, there is a lot details that are changed. For example, in C++, we don''t see this kind of instruction:
typedef struct tagPoint {
int x;
int y;
} Point;
...because we don''t need to repeat "struct" with each Point declaration. Many people think that they are programming in C while they compile with a C++ compiler (mostly visual c++) and use a lot of the C++ improvements.
alexk7
Here are three excellent references for programming in C++:

(1) "Thinking in C++" 2nd edition (vol. 1 & 2) by Bruce Eckel. These FREE, on-line books are available from www.mindview.net.

(2) C++ Primer Plus by Stephen Prata (Waite Group Press). List price for the hardcover edition is about U.S. $49.99.

(3) C++ How to Program - Introducing Object-Oriented Design with the UML" 3rd edition by Deitel and Deitel. List price is about U.S. $(one arm and a leg).

If you master any one of these books, you will be a proficient C++ programmer. If you are a beginner and have deep pockets, I recommend (3) above - it is first class (and the price reflects the quality).

Programming in C/C++ and programming Windows applications are two different things. Once you can program in C or C++, you can apply your skills to developing Windows applications. Here are two recommendations:

(1) "Programming Windows" 5th edition by Charles Petzold. This is the "classic" book on Windows programming.

(2) "Tricks of the Windows Game Programming Gurus" by Andre Lamothe. If you know how to program elementary applications in C or C++, this book will help you to apply your knowledge to Windows and to develop 2-D games.
Alexk7: I agree that the line between C and C++ is blurred; moreso than I let on in the article. As you could imagine, this article was a pain to write because of all the ''flowers in the garden getting trampled on'' in the process. It''s easier to simplify and call C modular and C++ OOP, even though it''s closer to the truth to say that C today is merely C++ without using function pointers in structs (or classes). I don''t think you''ll find a C programmer not using ''//'' for comments, even though it''s a C++ addition.

C is the easier language to start out with in game development, and C++ becomes more of an ideal when the game code gets large and unweildy. I myself wonder at times if the overhead involved in using virtual functions etc. is really that much of a consideration anymore, and I''m sure that most of us deep down would rather go the OOP way in the end (minus some of the craziness that goes on with more complicated facets of the language).

There is one factor however that I can''t overlook for the time being, and it''s a side-effect of programming in C++ and the way we apply our abstract thinking... we make little mental rules on how classes act together and how other classes arbitrate their communication, and what ends up happening (almost always) is that there''s an inherint increase in overall traffic. Umm, how do I describe it? Well, for instance, the calling method validates data on its end, and the callee again validates the incoming data. State information needs to be validated because of the nature of objects in general, and it''s the overall etiquitte that we throw into our object coding that introduces so many extraneous calls. This is the nature of the beast I''m afraid, and it''s one of those overlooked ''wrenches'' in the paradigm.

I will say one thing -- I use C++ for damned-near everything except for game development. Perhaps I need to take that final leap myself...

Teej

i aint been having luck with extern, ill decxlare it in two.cpp and make it 12, then i''ll include two.cpp, in one i''ll do extern int i, then ill do a printf, and it comes up as 0.

-kaptan

"If you cant handle the heat, Get off the car hood"
-kaptan"If you cant handle the heat, Get off the car hood"
sorry to waste space, i fixed the other problem, but why do i get unresolved externals sometimes, sometimes it happens when i make a new project, sometimes when i make a new source file and let the compiler ask me to make a project and i selct yes, its odd well thanx.
-kaptan"If you cant handle the heat, Get off the car hood"
RE: C v C++

I have been struggling with this for a while as well. I think that what i have decided is this: C is obviously faster and easier to learn/use in a lot of case. C++ is more controlable and better when projects get larger. So, why not just use C++ when it is to your advantage(i.e. classes) and use C when it is to your advantage(i.e. speed)?
if(!You_Like_Game_Dev){ return Loser;}else{ return Cool;}

This topic is closed to new replies.

Advertisement