4 ms·
C's popularity is due to the fact that it is predictable within certain bounds (single thread or limited concurrency). No GC pauses, no weird runtime crashes d
by bsder 9y ago
C's popularity is due to the fact that it is predictable within certain bounds (single thread or limited concurrency).
No GC pauses, no weird runtime crashes due to a strange constructor, no gigantic exception chains, etc.
The only languages in the TIOBE index that can even try to make that claim are: C at #2, C++(if you subset it) at #3, Objective-C/Swift(#18/#11), Assembly at #14, Ada at #29, and
maybe FORTRAN(#35).
That's not a lot of options if you need runtime predictability. Basically C, C(with additions), C(with additions), assembly(hack, spit), Ada (okay), and FORTRAN (God help you).
Even now, that means C or Ada--and the first free Ada compiler was 1992.
Yes, Rust is coming. But it's got a way to go yet.
- Volt 9y agoThe fact that there are these other languages with the same properties means that predictability isn't the real reason, right? It's that it also is sparse in its specification and easy to implement a compiler for.
- benlorenzetti 9y agoC's popularity is due to the fact that it is predictable within certain bounds (single thread or limited concurrency). Your post, and reading a discussion further down about Rust's reference counting, has made me realize something primitive that Rust is getting right--a real move forward--which even those who don't enjoy the default "safety switch" being flipped from C (like me) may agree. The C model for memory in time and space is so clean for heap data and the function call stack for one thread (plus global registers), but C has no community-understood/concurring model when it comes to concurrency. Rust, older C++ libraries, C malloc implementations, and other are all alluding toward the simple memory model for multiple threads, which is reference counted pointers, IMO. Basically use a separate type of pointer for heap data, where the max size of the heap is divided by whatever binary power of 2^p processors exist. Rust folks or other languages are welcome to add more ownership semantics or whatever, but the whole family of languages could benefit by this extension to the lingua Franca of C. We may not even need to add a new nominal pointer type to C, just by fiat understand and expect shared, free store objects to always live inside the lowest 1/p th portion of the word address space.
- eadmund 9y agoOnce upon a time it was common to write non-consing Lisp code precisely in order to get predictable behaviour; I think that it worked pretty well. Non-consing code won't have GC pauses; it won't have weird runtime crashes; and it probably wouldn't have gigantic exception chains unless it needs them.
- fulafel 9y agoIsn't this a circular argument: C is popular because no other language on the top popularity chart does <x>. There are many languages with the these properties and better safety, but they aren't popular like C.
- bsder 9y agoReally? I'd love their names. I'm not being snarky here. I'd love to have a nice language alternative to C.
- fulafel 9y agoI'm going to link to pjmlp's comment who knows more about these: https://news.ycombinator.com/item?id=14700251#14701140 https://news.ycombinator.com/item?id=14700251#14701140 I was more referring to the historical perspective of how C became popular, many have fallen by the wayside. Though there are certainly current alternatives to C besides those on TIOBE. Also there are real-time extensions to current GC'd languages like Java. (Though standard C isn't very predictable timing-wise either, or suited to real-time work)
- bsder 9y agoAnd, with the exception of Ada and Pascal, most of those language have been dead for at least 20 years--for various good reasons. And, please do remember that Apple switched away from Pascal when writing its operating systems in spite of an enormous code base. That's pretty damning--apparently C's "undefined behavior" didn't seem to matter. So, we're back to: the only alternative to C is Ada. > Though there are certainly current alternatives to C besides those on TIOBE. Let me make it easy. Give me a list of languages that have been used to build an operating system in a product in the last 20 years. It doesn't have to be Linux, even a small RTOS counts. I'll start the list: C family--C, C++, ObjC/Swift Forth(?)--probably counts as it runs on pretty bare metal Ada--not sure anybody has used it to build an OS, but I don't debate that they could Rust--has a feature set of articles about this Pascal--the original Lisa and Macintosh OS (probably stretching that 20 year limit a bit). And?
- mike_hearn 9y agoThe idea that C is predictable is in my view a sign of someone who hasn't got to know C really well. The trends around undefined behaviour will hopefully put a bullet in the head of this idea for good. It's extremely hard to look at C and reason about what an optimising compiler will turn it into. Malloc is not more predictable than a GC pause. Both malloc and free can take unpredictable amounts of time. If anything it's less predictable because modern GCs at least have pause time targets, but mallocs never do. You just don't notice it because people don't tend to measure malloc latency. In turn that's because malloc pauses only affect memory allocation operations, they don't stop every thread, which is a benefit it's true, but it's not about predictability and more about UI latency. C not having exceptions doesn't make it more predictable. It just means that if something goes wrong you get a useless and probably corrupted core dump. The number of times I've been able to fix a bug in a piece of managed code given only a stack trace from the end user is huge. The number of times I've been able to fix a bug given "Segmentation fault" with no other info is zero.
- bsder 9y ago> The trends around undefined behaviour will hopefully put a bullet in the head of this idea for good. It's extremely hard to look at C and reason about what an optimising compiler will turn it into. Sure when you turn on -Oinfinity. Nobody does that in embedded unless they are hard pressed on some metric (RAM size, generally, or CPU flops occasionally). Overall, though, C is really fairly predictable. Unsigned arithmetic does what you expect--the fact that signed arithmetic doesn't under higher optimizations is a fairly recent phenomenon (and not an uncontroversial one). Variables go where you expect. Pointers act like you expect. Casting and precedence sometimes sneak up on you, but parentheses generally manage that. Const has issues at the boundary cases. Trying to stuff something into ROM and then telling the rest of the system that "really-no-you-cant-cast-that" can make things tricky with "incompatible pointer" issues. Floating point arithmetic, though, is just a disaster. > Malloc is not more predictable than a GC pause. Ayup. And what's the first thing real-time embedded folks do? Throw out malloc (which is library, not language, but that's pedantic). Real-time-embedded systems tend to allocate all memory statically, up-front. Or they use a custom malloc that they control the behavior of. > C not having exceptions doesn't make it more predictable. It just means that if something goes wrong you get a useless and probably corrupted core dump. Predictable and useful are orthogonal. And, the fact that I can't attach to running state of a crashed program is a failure of TOOLS not the language. The fact that I can't attach to a system that crashed, examine the state, fix what I need to, and continue is a fault of the people who make C IDE's. There is no reason other than lack of monetary incentive that this cannot be done.