Advertisement

Why C instead of C++?

Started by May 11, 2002 07:14 AM
24 comments, last by J-the-Bear 22 years, 9 months ago
quote:
Original post by Dalkiel
there's loads of C++ programmers who don't understand a word of C. everybody should begin with C through IMO.

There's also loads and loads of "C++ programmers" who understand nothing but C. Bad habits learned from having C as a first language seem to be very hard to shake.





[edited by - Arild Fines on May 12, 2002 10:50:37 AM]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:
Original post by Arild Fines
Original post by Dalkiel
there''s loads of C++ programmers who don''t understand a word of C. everybody should begin with C through IMO.

There''s also loads and loads of C++ programmers who understand nothing but C. Bad habits learned from having C as a first language seem to be very hard to shake.


i meant "C++ programmers", not "C++ish (or in other words, C)programmers". if ''they do understand nothing but C'', then they are C programmers.

C++ programmers (programmers with at least some knowledge of C++ with or without OOP) can understand C++ and/or C. but in any case, they do understand some C++, C being an extra (kinda).

everybody should begin with C because there''s more documents (papers,books,tutorials,etc) written in C than C++ and that said, it''s easier and faster to learn from those docs. well it''s my *opinion*, everybody has their own way to learn things. mine was C, then C++ and its OOP.
"Shadow of annoyance Ne''er come hither! ...And when He falleth, He falleth like Lucifer, Ne''er to ascend again..."
TOT
Advertisement
If you work on really big projects then C++ is a hell of a lot better. OO (object oriented) code is much easier to read and understand once you''ve got the hang of it (i know you can do most of the stuff in C but it''s just nasty). C++ is obviously going to be slower if you use the advanced features. But try to write equivalent code in C and it''ll be a mess and just as slow. There are probably more documents to learn COBOL than C but that doesn''t mean you should learn it first. Obviously you have to learn C-ish C++ before you learn classes, templates etc. but why bother learning printf when you can use cout.
quote:

but why bother learning printf when you can use cout.




Because printf() is actually better at separating different layers of data (format string and inserted data) and is thus cleaner and easier to read. But I''ve already had my printf vs. cout flamewar this month, so I''m not going to continue on this topic.

A C++ programmer who doesn''t understand C must be a real idiot and shouldn''t be a programmer in the first place. The syntax of C++ only adds onto C. There may be some minor differences, but those do not make C code incomprehensible for a C++ programmer. Now if somebody doesn''t know how to use printf() - well, that''s possible, but I wouldn''t count that as not being able to read the language. It''s just one stupid function call, and even though it''s part of the language (as per the standard), the language can very well live without it (e.g. GUI programs don''t - or shouldn''t - use printf() or cout).

Of course, C++ code tends to be slower than classic C code. For example, virtual function calls do take longer than direct function calls because of the function pointer indirection. However, you''ll get the same speed penalty if you write OOP code in C - which is very possible, though it tends to get very messy.

Also, modern compilers typically support C and C++ equally well, so the support argument doesn''t really count anymore.
Even exceptions don''t make programs slower; they can even make them faster (less conditional jumps in the default execution path). However, they do increase the binary size because of the exception handler tables.

But all the OOP, ADT etc... goodness aside: sometimes, you just need to step back and view the big picture. I''ve recently joined an open-source game project which is heavily OOP. The map is represented as a class, and every field or node of the map is a class of its own, and is treated like one. Now this is just stupid because if you''ve just got a Field * to use you''re lacking essential additional information (such as the coordinates of the field inside the map).

It all boils down to sensible software design. C++ and OOP are no magic tools to make software design better. They can only help you implement the more advanced designs.

And now back to the original question: C tends to be used more with OpenGL because OpenGL was built for C, as stated before. I would like to mention that this was very clever indeed. Even in the days of OOP and C++, I would recommend that an API like OpenGL be built in a procedural way. Sometimes, power and efficiency comes from simplicity.

cu,
Prefect

Return to the Shadows
Widelands - laid back, free software strategy
Thanks for all the information.
Didn''t intend to start a flame war or anything.
I do some programming in C and C++ so it just interested me.
I find C++ handier if I''m linking multiple files as I don''t have to go running around putting in lots of externs.
Thanks to everyone who replied.

"If all else fails, lower your standards."

"If all else fails, lower your standards."
quote:
Original post by Dalkiel
there''s loads of C++ programmers who don''t understand a word of C. everybody should begin with C through IMO.


And, before they begin with C, they should start with BCPL. And before that ML, and before that binary code, and ulitmately - Give them a silicon plate and a chisel!

or??

#define Email Lex & Yacc Function Pointers Virtual Terrain Knowledge Base Real Programmers
"Strong typing is for the weak minded!"

This topic is closed to new replies.

Advertisement