Deprecated: Function create_function() is deprecated in /var/www/blog/inc/libs/clearbricks/common/lib.l10n.php on line 640

Deprecated: Function create_function() is deprecated in /var/www/blog/inc/libs/clearbricks/common/lib.http.php on line 249
Why C is a good language - or why you're wrong thinking C++ is better - Grumpycoder
Flux RSS

Why C is a good language - or why you're wrong thinking C++ is better

I've recently had a discussion with some friends over at Google+ which finally made me understand why there's so many people out there who don't understand why C is superior to C++, even though there's so many people who say so. So let me share this epiphany with you.

The reason why some programmers think C++ is superior to C is because they're bad programmers. Alright, let me rephrase this so you don't immediately start flaming me. The reason why some programmers think C++ is superior to C is because they (most of the time) don't have the same mindset. And if they do have the same mindset as pro-C people, then they are not aware that there's people out there who don't. But allow me to develop.

Basically, I came to realize that a lot of programmers out there do not get the concept of "pay only for what you use". Which, inherently, make them "bad" programmers. I say "bad" as in "they can't write code that is efficient". These programmers might come up with very nice (as in, pretty) pieces of software. They also might come up with very stable piece of software. But they can't come up with code that is at least as efficient than code written by the programmers who know exactly the advantages of C over C++.

The main issue at hand is "quality of life". I now understand that there is a lot of programmers out there who are only "consumers". They consume compilers and languages (and, as an extend, processors) as they see fit for their convenience and not as they see fit for the efficiency of the final software. They only want to "get the job done", and do it in the most efficient manner for the number of lines they have to write, or the easiness of the code they write.

But a "real" programmer will actually be aware of the generated code. They do not care about their quality of life, as long as the generated software is slim and efficient. These programmers will know exactly what kind of assembly code is going to be generated as they write the source code. They are perfectly aware of each and individual cost of their line of code in terms of generated code size and speed. And C is the only language that fully provides this ability. Linus original argument can be translated into "if you are a C++ advocate for the sole reason it's easier to use for some programmers, then I don't want you to contribute to git, because you're most likely to be not aware of code efficiency, and thus, you're most likely to contribute non-efficient code into a project where efficiency is the main selling point."

Now, in an environment where the code is fully controlled, and where code contributors are fully respected and trusted, then C++ might be acceptable, because then one can trust them to do the right choices, and dodge the various pitfalls that C++ will present them. But in the case of open-source softwares, such as the Linux kernel, or git, where you can't possibly fully review every and each contribution being made, because there's so many, then C presents the advantage of fencing yourself against common bad programming practices that Object-Oriented programmers tend to be plagued with.

If you're a "good" programmer (as in, you know exactly what is the efficiency cost you're paying with the code you're currently writing) who still is a C++-advocate, then you're just ignoring the fact that there is bad programmers out there (as in, programmers who don't know or care about the efficiency of their code). Whilst I'm not saying it's absolutely impossible to do code in C++ that is as efficient as C code, I'm saying it's way easier to do insanely horribly non-efficient code in C++ than in C, because of the various pitfalls it presents to programmers. So if you're a "good" C programmer, you're probably a "good" C++ programmer too (as in the code you'll write in C++ will be as efficient as the code you'll write in C) . But if you're a "good" C++ programmer to start with (as in, you know how to do pretty things in C++, and write some insanely convoluted Object-Oriented C++ code), then it's not guaranteed you'll be able to write efficient code.

Of course, the notion of "good" and "bad" programmer diverges depending on the actual goal that's being desired for the job. But then C++ is still a horrible language on a lot of fronts: it's a bad Object-Oriented language - there's plenty of other languages out there who are doing a much, much better job than C++ to create Object-Oriented idioms - and it's a language that introduces so many pitfalls on top of C that the average programmer will write C++ code that is much, much less efficient.

In conclusion, if you don't like C, and prefer more modern languages, then I'm not saying you're a "bad" programmer as it's very probably you'll write code that is pretty, and runs nifty GUIs and even may be useful. However, I'm saying that if you don't see the advantages of C over other languages, then it means you don't clearly understand the philosophy behind C, and what it actually means to write code that's going to be as efficient as possible. Start learning about compilers. Learn about assembly. Learn about processors, cache lines, and other branch-predictions thingies. Then you'll understand why C is superior.

Fatal error: Uncaught Error: [] operator not supported for strings in /var/www/blog/inc/core/class.dc.postmedia.php:61 Stack trace: #0 /var/www/blog/inc/core/ dcPostMedia->getPostMedia(Array) #1 /var/www/blog/cache/cbtpl/29/59/2959320ca61719bec433f91e69098e86.php(137): dcMedia->getPostMedia('32', NULL, 'attachment') #2 /var/www/blog/inc/libs/clearbricks/template/class.template.php(268): include('/var/www/blog/c...') #3 /var/www/blog/inc/public/class.dc.template.php(231): template->getData('post.html') #4 /var/www/blog/inc/public/lib.urlhandlers.php(122): dcTemplate->getData('post.html') #5 /var/www/blog/inc/public/lib.urlhandlers.php(523): dcUrlHandlers::serveDocument('post.html') #6 /var/www/blog/inc/libs/clearbricks/url.handler/class.url.handler.php(166): dcUrlHandlers::post('2012/03/02/Why-...') #7 /var/www/blog/inc/public/lib.urlhandlers.php(187): urlHandler->callHandler('post', '2012/03/02/Why-...') #8 /var/www/blog/inc/public/prepend.php(156): dcUrlHandlers->getDocument() #9 /var/www/blog/ind in /var/www/blog/inc/core/class.dc.postmedia.php on line 61