I have no emotion towards C. It is an old language and certainly an imperfect one. The thing is you just need to come up with something better. Maybe someday that can be Rust or another language. But you need something to replace it.
This will not be a quick change. C is interoperable, and the industry is moving slowly.
In spite of all your arguments even today most important software powering modern computing are written in C, this speaks volume about its simplicity.
I am sure there will still be critical software powered by C 40 years later. Rust will take another decade or two to reach that level of simplicity and ease of use still not sure if it will cross the threshold to replace C, when an average developer needs to spend years just understanding basic syntax, use of language and its traits.
C is like English, Hindi or simplified Chinese not very pure with flaws and ambiguity, still became lingua Franca of the majority world due to simplicity.
I have to disagree emphatically that C is outmoded. It may lack some of the polish and novelty of Rust et al, but it's still a fine language. More importantly, it's an industry standard, has been for ages, and will be for ages. So many of the resource and reference material out there (not just for low level / systems programming but especially for it) presumes a working knowledge of C that a person would do himself a disservice by not picking up the language.
I get that this is not a popular opinion these days, but I like C. Quite a bit, actually. I can get stuff done reasonably quickly, don't have to futz around with multiple inheritance (C++) or where to call out to C anyway (python). There is so much more tooling behind C than Rust, or Go, or Zig (though I've been looking at Zig as a replacement). C isn't as bad as everyone makes it out to be, for personal stuff. I'd be a little more careful in group projects, but there's a reason it's still around. You do have to be careful and do a good design, but you should be doing a design anyway.
Some day, C will be deposed. Something better will show up and gain traction. On that day, I will happily switch to the new better thing; but for now, C meets my requirements pretty well.
It is about as expressive as a "portable assembly language" can be expected to be, it has pretty weird syntax [1], it has neither hygienic macros nor a module system, using "include files" instead. And a bunch of undefined behaviors on top of that.
Well, it was the unifying language despite all these shortcomings, because Unix. This is very much like JS is an ugly unifying language of sorts today, because the browser.
I very much hope that maybe something like Rust will take the place of the close-to-metal portable language. C made some sense when you had a 16-bit CPU @ 10 MHz and 128 KB of RAM for a development machine, and ed on a teletype as the IDE. Now we can do better.
C is the glue interface that connects all the different languages together. I wouldn't want to see anything new added to the language that complicates this lingua franca.
I liked C in the 80s, 90s and 2000s. It was a neat and simple language, but that changed as compilers got more aggressive with their optimizations and exposed just how complicated and unintuitive the spec actually is (and the impossibility of avoiding UB). C was a good learning experience for language committees (as was C++), but it's time to move on.
I also liked C++ in the 90s, but soon grew to despise it. When they tried to revamp it and make it safer to use, I was hopeful, but that's now gone. It's too complicated, the error messaging sucks, and there are too many different ways to do the same thing (which ever changing best practices). In a way, CMake and C++ are two peas in a pod.
This is why I now pin my hopes on rust and zig. I want to write low level code, but not in C or C++. I want a build system that's not Makefiles, CMake, or (shudder) gradle.
There are better alternatives to C if a friendly language is what you want. C has its niche and I don't see C changing, and I've yet to see a "dialect" be really successful. If you're willing to switch to "friendly C", why wouldn't you already be switching to Rust, or D, or even Haskell?
The problem is that nobody new to the scene wants to write C anymore. It's not a secure language, it has no convention and is full of hacks. On top of that it has undefined behaviors and is supported differently by different systems.
Nowadays people want to write in Go, Rust, Swift, etc.
It feels like there's room for a better C today. I don't mean a really different language. I'm thinking something that is semantically C, and 99% syntactically C, but that a much better story around macros, builds, modules, linking, volatile pointers, and all of the other C foot guns. Not C++ or Rust (though I love Rust). I'm thinking just a smoothed out C. And done in a way where a codebase can incrementally move from C to better C, one file at a time.
It's 2017. It's about time we had a better, well designed language (ie Rust, but I'm not sure if it's well designed enough, depends on what you want it for, too). There have been many advances in language research since the 70's that could be very useful for the kind of work C is used for. Saying we should stick to C because it's well established is like saying we should stick to assembly if it was well established. Except it's not portable, but close enough.
I'm in the same boat. Took me a while to accept that I am a C programmer at heart, it suits me the best. I feel like I'm in full control and I can move fast with it. Not all razors are on us though, especially if moving around compilers since there are here and there undefined behaviour parts and it's easy to throw knives around.
I also wouldn't recommend starting a new thing with it if the whole team wasn't well-versed with it. On the other side of spectrum, today's world is well-served with python, c++ and rust (that battle is ongoing, I like both), java, heck even JS. There's something special about C though and I've yet to see something replacing it's place. Closest was D1, but that came and went.
This is my view as well, from the same industry. However, the quality of the tools available in C to deal with its issues far exceed those in any other language. I would love to drop C from all my systems, but the alternatives simply aren't there.
I've been writing C on and off since 1990, across embedded systems, game consoles, massive SGI supercomputers, and modern kernels.
C is not fading away because of it's portability and low overhead. It has some nasty behaviors, as the original post shows, but you hit those once in a blue moon. The language is not unsound because of it, it just has some warts like any other language.
I don't particularly enjoy writing C, as it's too low level for my liking and I have to write too much code to do basic things (slist_* makes me shudder), but the reason that I have used it is due to its tremendous portability and direct compilation to machine code. That still matters in some places.
In places where memory is precious, or realtime performance precludes things like memory managers, C will continue to thrive, beside languages like Rust which are great for different goals. There's room for both.
C, in my opinion, has stood the test of time on its simplicity, portability, and the ubiquity of the C standard library, tiny as it may be.
The problem is that there isn't anything to replace C, that would be acceptable enough. C has become a quasi protocol, and used in exchanges between languages. One could argue it's better for newer languages to embrace and excel in interop with C, while providing more advantages, being safer in comparison, or greater ease of use. As is arguably the case with Vlang, Dlang, Nim, etc...
If anything, C may still be going strong for another 20 to 30 years.
Unfortunately, no one will agree exactly on which aspects of C to change and which to keep - that's why we now have hundreds of languages used by less than 10 people each.
E.g. while I applaud the idea, I found many aspects of your example code snippets ugly and un-C-like. This is not to say that I'm worthy of judging your work, but that a) so much of it is a matter of taste rather than objective thought and b) humans can adapt to literally anything, given time to get used to it.
It's clear that C is a dated language that leads to numerous security problems. It is inevitable that we will switch to OS's written in Rust or similar safe languages, or will see most of Linux rewritten.
Oh that's what I was nodding at with my "I wouldn't call C a simple language" comment. You are 100% correct. I assume--maybe wrongly but I don't think so--that the natural progression of the C programmer is:
- whoa cool everything is a number! Make that light blink, wipe that SDRAM chip, whiz bang!
- What the fuck is a torn read (insert any C gotcha in here)?! Everything is garbage!
- I know, I'll encapsulate "The right way to do things" in a library/new language.
- Never mind, I've decided to build websites (insert popular tech job here) for a living, but be super grouchy about it
The corollary to "I think Rust's complexity makes it impossible to delight me" is "I think C's brittleness makes it impossible to delight me." It has notes of innocence lost, nostalgia, a "simpler time", etc. Are those days gone forever, as the Dan say? Dunno.
agreed, much of the bickering is on ABIs and FFI stuff which you could argue is hard due to ABI differences it supports. this is not a C problem, but a complexity C exposes. C does do that a lot, but thats also a strength. There are really no sound alternatives to C for low level system programming (OS core functionality, or embedded stuff). there's C++ ofcourse but regarding the complaints it suffers the same. Rust doesnt solve anything there, its impossible still to actually build a modern OS in rust for example. (maybe if most your core is wrapped in unsafe and you run on only a single core device...).
If C is such a problem id like to see some alternatives which offer what C does but less painfully.
C is only useful in certain domains, but within the domains where C is really good, theres no others. (unless you want to go assembly mode... good luck :) can be fun)..
anyhting that is less painful, exposes less complexity and is usually therefore less generally applicable.
A lot of the pains of C are lack of understanding how to use it because using it requires deep knowledge of it, and the target platform.
that being said, i do get userland applications and C dont really mix anymore. that is a fair point imho.
I could see C replaced with something like Rust, but I don't see it disappearing just because hardware gets faster. Companies will just make devices smaller, and it makes sense to write things in C once if that means everyone gets a faster experience. However, I sure don't want to maintain all that code!
I am paid to work at a higher level (Go, PHP and JS) I take any opportunity to write a little C, in fact I would say that I romanticize the chance, the challenge is great.
Are you currently in the embedded field, is it your experience that it is getting phased out?
This will not be a quick change. C is interoperable, and the industry is moving slowly.
reply