Why the C Programming Language Sucks
giantfublog.wordpress.com
giantfublog.wordpress.com
And, before that, the assembly languages were addressing that problem with machine code.
No doubt in 10 years (whom am I kidding -- 10 months) whatever replaces Javascript will make the same complaints about it that this does about C.
Personally I find C pretty elegant for what it is, and it's the only thing I would use for serial comm programming, and since that's what I do mostly...
C is an abstraction of a system. It has memory, file handles, and other things that a system has. That's why people write OSes in C. When you're writing an OS, what are you doing other than managing a resource? The 1/2/3 are necessary when they are the whole point of the language.
Of course it sucks to write something like a website in C when you can use a high level language like Python which has libraries containing plausible abstractions for web pages.
Of course you can.
It's just a question of convenience, and whether the resulting style would align with idiomatic C. In my imagined implementation, it would look more like awkward JavaScript.
There are many many C codebases that are internally consistent but don't look much like textbook C. Sometimes C is the best choice even when it's less convenient.
But really, bashing C shows a complete lack of understanding of the history of computing. I wouldn't be surprised to find another post expounding on just how horrible assembly is.
It may not provide enough abstractions to match your awesome Ruby on Rails application for your next great startup but that is OK. Lets try to remember that C was invented to avoid writing Unix in assembly, which all previous OS'es were written in. So abstraction-wise it supplies enough abstraction for its time and usage.
As for actual zero-cost optimization, Chandler Carruth who works on Clang at Google gave a talk at the 2012 LLVM Developers' Meeting warning people that C++ zero-cost abstractions are more myth than reality, and things developers expect to be zero-cost are often in-fact not. He goes into detail about how the optimizers work and what the challenges are.
http://llvm.org/devmtg/2012-11/videos/Carruth-OptimizingAbst...
I do know other languages. I have used professionally, Perl, Python, Ruby, Scheme, Java, Objective-C, Lisp, Dylan, and others. I have been teaching myself Haskell in my bits of spare time for years now. I would love to be able to write some of these algorithms in my embedded work in Haskell, or an EDSL, and I think that is possible, but the fact remains that a lot of programming in the embedded space is all about managing state, and managing peripherals, which involves a lot of interrupt handlers, very low-level programming with event queues and tasks, and often a minimal OS (I'm using FreeRTOS right now) or, often, no OS at all (as in some code I've written professionally for Arduino boards and low-end Atmel microprocessors).
I am perfectly aware of C's imperfections and weak type systems, many of the safety pitfalls involved in working directly with machine words and pointers, and the relative lack of checking that most compilers do for you (compilers will often be perfectly happy to compile code that will mix signed and unsigned types in unsafe ways, or do widening or narrowing in unsafe ways, due to C's rather baroque rules for integral promotion and things like that). The partial equivalence (or, one might better say, automatic conversion under certain circumstances) between arrays and pointers is a source of endless confusion to newbies and the details of just how it works are a source of difficulty even to many experienced programmers. But after 30 years programming in C and 40 years programming altogether I can bang that shit out and make it readable and write good comments explaining what I am doing and very often my shit runs properly on the first try.
So from my perspective C is a great language. It has been the backbone of my whole career, although in truth I would love to do a lot more with Haskell.
C++ by comparison, which I've also used professionally, a lot -- does not even feel like language these days, but more some kind of endless, nightmarish research project where the best approach is to make sure you are not coming anywhere near the cutting edge.
Had Pascal filled the role, we'd have long posts about Why the Pascal Programming Language Sucks. You know, aside from the one Brian Kernighan wrote.
Only really posting this because I want to do my part to clear the 'goto' stigma that seems common in the younger programmers. It still exists because it can still do good ( sometimes :) )