Stop Hating on C!

It seems most computer science programs out there don’t teach C programming anymore, instead focusing exclusively on higher-level languages such as Java or Scheme. I would say there’s actually quite a bit of C hate going around. People would like to claim that C simply isn’t a language worth learning, that C is badly designed, that it’s overly complex and extremely error-prone, that it’s unpredictable and brittle.
You can hate on C as much as you want, but the truth is that it’s a programming language that’s survived for 40 years, delivers unparalleled performance and powers the core of almost every computer system in existence. C isn’t just used for low-level kernel and driver hacking either. Even today, almost all games programmed for the PlayStation 3 and other consoles are programmed in C and C++. Suck on that, haters!
C isn’t badly designed, or overly complex. It has a very simple grammar, predictable semantics and accomplishes its design goals very well. The C language is meant to be a platform-neutral abstraction layer over assembly language. C allows you to make function calls and manipulate pointers or other machine data types in a consistent way across different platforms, without having to worry about how these operations are going to be implemented in terms of machine code.
Surely, the language could be improved in various ways (no header files, anyone?), but its beauty stems from the fact that it’s a very thin abstraction layer over the hardware. As such, it’s a very good representation of what actually happens behind the scenes and does not have hidden costs or performance penalties. Languages such as Java, Scheme and JavaScript most certainly have their place, but they are rather far removed from the internal workings of any CPU, and thus far, cannot compete with the performance attainable by C programs.
I believe this message, posted anonymously on 4chan, says it best:
I don’t think C gets enough credit. Sure, C doesn’t love you. C isn’t about love–C is about thrills. C hangs around in the bad part of town. C knows all the gang signs. C has a motorcycle, and wears the leathers everywhere, and never wears a helmet, because that would mess up C’s punked-out hair. C likes to give cops the finger and grin and speed away. Mention that you’d like something, and C will pretend to ignore you; the next day, C will bring you one, no questions asked, and toss it to you with a you-know-you-want-me smirk that makes your heart race. Where did C get it? “It fell off a truck,” C says, putting away the boltcutters. You start to feel like C doesn’t know the meaning of “private” or “protected”: what C wants, C takes. This excites you. C knows how to get you anything but safety. C will give you anything but commitment
In the end, you’ll leave C, not because you want something better, but because you can’t handle the intensity. C says “I’m gonna live fast, die young, and leave a good-looking corpse,” but you know that C can never die, not so long as C is still the fastest thing on the road.
As far as C and its derivatives being worth learning, it seems that might depend on your area of expertise. There are certainly millions of programs and libraries written in C out there, and this alone might justify wanting to learn C. The other reason is that once you truly master C, you will have an understanding of computers that goes far beyond that of most programmers out there. Once you understand pointers, memory allocation and integer arithmetic, you will have a basic, intuitive understanding of the beast that makes your computer tick, and no programming language will ever scare you again.
I think that even if you never do a major project in C, or C++, you should definitely learn the basics of both of those languages. Many strict high-level language programmers have difficulties when it comes to understand exactly what the computer is actually doing. All languages are ultimately bound by the hardware, so it makes strong sense to understand what is happening at that level, even if your language of choice is mainly shielding you from it.
it’s a shame other languages try to hide the hardware layer from the programmer with weird claims like “you don’t have to worry about null pointers, we have just references” or “we have a garbage collector, you can’t leak memory” etc. in the end all those claims are painfully proved to be wrong and instead of learning some standard language, people waste their time on proprietary languages that they stick to just because they’re too lazy to get used to something better (and by better I mean “free like in beer”).
It’s also a shame that companies like sun/oracle and microsoft try to force their languages into the field. If they would truly believe in the quality of the languages they created, then they would open their systems and allow everyone to choose the tools they want to use. But instead, they come with lies like “it’s for security”, like a different source code wouldn’t end up on the same VM with the same bytecode.
I’m proud of those engineers, that refuse to be a mindless minion, just like everyone fights against censorship on the internet, we engineers need to fight the censorship of tools we use.
It is strange that most Universities do not teach C. We have a basic C course, but that doesn’t even count towards a CS major. Luckily we talked one of our professors in teaching an Advanced C course this summer. I am excited to pick it up and learn!
C has become, somewhat like my mother tongue in the computer world. Some people say that “C is not object oriented”, but they do not realize that object orientation is not a property of a language, but the property of the design of the problem, other “OOP” languages just provides some language constructs which help implement the code a bit easily. Such people also write a couple of unstructured classes, basically C code packed inside the class methods and call it “Object Oriented Programming” because “it has classes!”. Whatever prototypes and final codes i need to write i make them in C, and follow an object oriented desing. I have never heard someone say C as complex. Although some people unable to understand pointers and the power of pointers may say such “lol” stuff.
My opinion, learn C++/Java/Python etc. but definitely learn C.
Yes, definitely OOP is a function of the design and not the language. In school we did a project using OOP in assembly language: a lack of high-level constructs didn’t stop us from using virtual functions and inheritance.
On that note I can link to my article about what polymorphism is (with examples written in C). http://mortoray.wordpress.com/2011/08/09/how_polymorphism_works_part1/
I certainly agree that knowing how C works is one of the best way to become a better programmer; having a more intimate understanding of what an abstraction actually costs will allow a programmer to decide if the cost of doing an operation in his program is too high for the value it provides.
With that said, I think it’s high time that the search for a complement to C switched into high gear. I don’t want to say replacement, because that is never going to happen, but I would like to see more project like Clay, Habit, Deca, and to a lesser extent, Rust, Go or D. These projects could be used in projects were C is usually the default, or even only option.
There are *so* many embedded devices in our lives: thermostats, medical equipments, cars, industrial machinery, etc. I would like to see a language that retains most of C’s minimalist philosophy, while improving on some fronts. A stronger type system would certainly be at the top of my list. Other improvements could be a better module system, like you said, a macro system that is smarter than just textual replacement, and perhaps changing some behaviours (switch statements break by default, use a fallthrough statement to keep the normal C behaviour), etc. Most of these changes would alter how the programmer interacts with the language, and hopefully disallow some of the more dangerous errors in C, while still retaining C’s control, performance and predictability.
I say let em keep hating. It only makes the real C programmers more valuable.