Where is C

Started by
57 comments, last by mikeman 17 years, 8 months ago
Quote:Original post by memento_mori
well C++ has tiny insignificant differences (syntax-wise) from C..

Syntax means practically nothing. They are similar syntax-wise, so what?

Quote:Although it really is a totally different languages, the programming concepts are all the same (as it is with almost all languages),

Far from the truth C advocates the procedural programming paradigm, which is generally considered inferior to the OO programming paradigm. C++ is a multi-paradigm language, but many consider it an OO language because many of the added features in C++ aids in OOP. The concepts aren't even close to similar. C++ also adds proper support for generic programming.

Quote:but even the syntax is almost the same..

The syntax is about the only thing which is the same (and that they both have the C standard library).

Quote:the only new concepts introduced are Objects ... that is classes and structures.

Have you even considered templates, the type system, type safety, the C++ library, namespaces, cv-qualifiers, exceptions, RTTI etc.?

Quote:Without those it is very hard to write a fully structured program and you will have truble maintaining and remembering your functions after your game jumps over the 1000 lines...

No, a well-written procedural program can easily be managed even though it's over 1 million lines of code (I believe some C projects are over 10M lines of code, but I don't have any references).

Quote:use classes WHENEVER you can.

No, whenever it's appropriate to do so. Don't do this:
class string_utils{  static std::string to_upper_case(const std::string& in);};

That is just forcing procedural code to be OO. Instead learn proper OO practices, and you will automatically use classes and objects instead of functions in almost all cases.


Some interresting links about C++:
Why C++ is not just an Object Oriented Programming Language (by the author of C++)
Learning Standard C++ as a new language (also by the author of C++)
Advertisement
Quote:Original post by CTar
No, a well-written procedural program can easily be managed even though it's over 1 million lines of code (I believe some C projects are over 10M lines of code, but I don't have any references).


I do.

The in-flight systems on the Airbus A340 are worth 132,000 lines of C code. Note that if said code crashes or otherwise causes an error, people die. Also note that this code has been proven to be exempt of any runtime error (that is, it cannot fail at all, short of a hardware failure).

Red Hat Linux (7.1) contains 30 million lines of code. 71% of these are written in C, which amounts to 21.3 million lines of C code. The separation of one big bundle into many subprojects (many of them being, in fact, reusable subprograms) that are then integrated with each other is an example of good code management that emerged by itself from a large number of developers.

The Linux kernel (2.6) is at around 4 million lines of code, with an immense proportion being C (the rest being scripts and makefiles).

Many game engines, emulators, rendering algorithms, statistical simulations, drivers, and just about anything that values efficency over everything else will use C (or at least primarily the C subset of C++). This is because certain parts of the C++ language (i.e. the oft-cited virtual functions, etc.) can be slightly less efficent. This usually isn't a big deal, but there are cases where this would be a big deal.
Quote:Original post by chigga102
I ... wanna know where C stands as compared to other languages as to popularity, and ease of use with the More popular APIs like opengl, Directx, SDL and Allegro based on facts not on your opinions. THANKS


I think you will find there is still more software today written in C than in C++, and certainly more than in other languages. Even much of the software written using a C++ compiler is written as C code.

I spent years writing pure C code (and many more writing FORTRAN). It's not hard, and the language is just a tool. I now write C++ code, and I find it painful and awkward having to go back and read C (or even FORTRAN). Compared to C++, the C language lacks expressiveness and requires more thinking in the language domain than in the problem domain. Since my time is expensive, that means C costs more than C++.

You should feel fine simply proceeding as a C programmer, lots of folks do it. Enjoy it now, because once you walk on the dark side of C++, you won't want to go back.

Stephen M. Webb
Professional Free Software Developer

Quote:Original post by memento_mori
well C++ has tiny insignificant differences (syntax-wise) from C..
Although it really is a totally different languages, the programming concepts are all the same (as it is with almost all languages), but even the syntax is almost the same..


No. One is Structered the other one is Object Oriented (in a simple case). C++ is actually multi-paradigmed. The programming concepts are not the same in "almost all languages".... Take a look at LISP.

To the original poster, C is great for firmware or device drivers. Small utility programs that have limited space and can't afford the overhead of virtual functions etc....
Quote:Original post by Anonymous Poster
Many game engines, emulators, rendering algorithms, statistical simulations, drivers, and just about anything that values efficency over everything else

Most of those you just mentioned value stability just as high as performance, and reliability is also a factor. Also game engines will be worth more if they are developed quickly because they are more "cutting-edge", so you shouldn't code them in asm even though you could code perfect asm code, it'ld take too long.

Quote:will use C (or at least primarily the C subset of C++). This is because certain parts of the C++ language (i.e. the oft-cited virtual functions, etc.) can be slightly less efficent.

Less efficient than what? If the feature is coded in C the code will be hard to read and slower because the compiler can't perform high-level optimizations. A good C++ programmer knows how to avoid the performance pitfalls of C++, and can code more efficient C++ than C because the C++ compiler can take advantage of the fact that he more clearly expressed his intent.

Quote:This usually isn't a big deal, but there are cases where this would be a big deal.

In those few cases (about 0.1 %), you should just be aware of the performance penalties some C++ abstractions can have, profile your code, and look at the assembly output. If that isn't enough, then C isn't enough either. Many C++ idioms which are hard (harder than C++, where they are already hard) to realize in C, stuff like expression templates, partial specialization, etc. And to quote Bjarne Stroustrup:
Quote:I never saw a project for which C was better than C++ for any reason but the lack of a good C++ compiler.
lol i didnt mean it was absolutely impossible to write code without OO, but i meant it was much harder to maintain and structure well...

especially if you are a beginner.. after all how did people write code before C++, or even before C... and how do people write assembly code.. :P

but yeah in general OO is the main new concept (templates and namespaces you call those "concepts" ??)

and even though some people like to hold up on the details i guess everyone agrees that bad programming habits are very hard to unlearn, and you will acquire bad habits from learning C (unless you don't plan on learning C++ afterwards which would really be a loss for you)...
and that explains why many people refuse to give up on some ..outdated.. languages IMO
Quote:The programming concepts are not the same in "almost all languages".... Take a look at LISP.


that's why i said "ALMOST"... I don't know LISP, but I do know COBOL and FORTRAN and I have to say they are pretty different with all these goto stupid jumps, but then again .. how many people do you find today who use those languages?
My appologies, but I still stand firm. Programming languages are not "almost all the same".... maybe the flow constructs remain similar, but that's where I would draw the line. There are still differeneces between COBOL and BASIC... and many other languages.... I would say very few are similar. COBOL was desigend for mainframe buisness logic. BASIC was designed for generic programing.
Quote:Original post by CTar
Quote:will use C (or at least primarily the C subset of C++). This is because certain parts of the C++ language (i.e. the oft-cited virtual functions, etc.) can be slightly less efficent.

Less efficient than what? If the feature is coded in C the code will be hard to read and slower because the compiler can't perform high-level optimizations. A good C++ programmer knows how to avoid the performance pitfalls of C++, and can code more efficient C++ than C because the C++ compiler can take advantage of the fact that he more clearly expressed his intent.


Quoted for emphasis.

This topic is closed to new replies.

Advertisement