10 ms·
This is another article overanalyzing the success of C, when in fact the reason for the success of C is very simple and obvious: Unix was free and in a lucky po
by pcwalton 9y ago
This is another article overanalyzing the success of C, when in fact the reason for the success of C is very simple and obvious: Unix was free and in a lucky position in 1973; Unix got popular; C is the language of Unix; therefore C got popular. There is no inherent benefit in C that, for example, a somewhat modified version of Pascal or Algol wouldn't have inherited. And these kinds of articles always ignore the fact that in the past decade or so, C and C++ have been declining in popularity. By and large, new programmers are not learning C the way they were in the '90s. For better or worse (personally, I think, for the better), they're starting with JavaScript, Python, Ruby, or even PHP.
I'm highly skeptical of the conclusion that what we need is a new safer implementation of C, too. Switching to a new compiler is a very high burden for a lot of projects, and at the end of the day they're still left with all the problems of C, like header files, no namespaces, terrible standard library, etc. etc. (Even adding compiler switches is a high burden, which is why Linux distros took so long to widely deploy basic things like -fstack-protector.) By contrast, switching to a new language (or incrementally writing new components in a new language, which is how this always goes in practice) is also a very high burden, but the benefits are larger: you don't have to deal with all the problems of C.
In my view, this is why safer versions of C have repeatedly failed over the years, while new languages have flourished. Migration to a new language or a new compiler is expensive no matter what, so teams will only do it if they see enough benefit to justify the expense of doing so. Merely adding some amount of safety to C isn't worth it, but the large safety and productivity gains you can get from a different language can be.
- quickben 9y agoYou are ignoring the fact that many problems can't be solved in the higher level languages. Also, for some, having the c/c++ level of control is prefered.
- bluejekyll 9y agoThis doesn't have to be zero sum. We don't need to choose between safe and unsafe. Safety should be a default, with unsafety being something you opt into. C/C++ are both unsafe. Rust is safe by default, and for the cases where you want/need the C/C++ level of access to the system, you can opt into unsafe. I believe Rust is more safe than Go and Java as well, because of the type safety in the threading model. There are existing applications in C out there, there will be for a long time. Personally I frown upon anyone starting a new project in C or C++, or any unsafe language, especially when you have such a strong language in Rust that exists with a very healthy and growing community around it.
- gens 9y agoI don't like to be told what programming language i should use. You can scoff all you want, but i will be using C for most of my projects.
- bluejekyll 9y agoI don't "tell" people, what language to use. But I do encourage them to look at new languages, especially ones that fit in the same place as one that they like. I love C. It was my first programming language. I love the syntax, I love the semantics. Years ago, I left it though, because I could deliver higher quality applications with fewer unknown bugs with Java, but I always wanted to find a reason to go back to C. And for some projects I did, and it was important (and in each case I'd run into some error or bug that took weeks to track down). When I grabbed Rust 2 years ago, it was like getting everything I loved about C paired with everything I love about Java, and none of the stuff I hate in either. Feel free to use whatever language you wish, and I hope schools continue to teach C (though that seems to be dwindling), but I highly encourage people to checkout Rust and see what it's like to not worry about pointer management all the time.
- Const-me 9y agoWhen I checked out Rust a year ago, I immediately discovered it has no SIMD (SSE, AVX, Neon). That it has no sane ways to implement a graph structure. Also that it’s hard to compose data structures into higher-level specialized ones. Also, I highly encourage people who worry about pointer management all the time to checkout modern C++.
- pcwalton 9y ago> That it has no sane ways to implement a graph structure. Sure it does. I work with graphs in Rust all the time. They may not be "sane" in your view because they're different from the way you implement them in C++, but I could equally well say that there's no "sane" way to implement a safe owning pointer in C++ (since there's no memory-safe way to do so). > Also, I highly encourage people who worry about pointer management all the time to checkout modern C++. Modern C++ has no protection against the most pernicious memory management errors, particularly use-after-free.
- dig1 9y ago> Switching to a new compiler is a very high burden for a lot of projects ... By contrast, switching to a new language ... is also a very high burden, but the benefits are larger I guess switching to a new compiler (or newer version of the same vendor) is much less burden than switching to the new language. Don't forget that all "new safe languages" are simply new. Why people like C is familiarity: known practices and known issues to avoid ironed out through 30 years of usage. Although Rust/JavaScript/your-favorite-new-language brings on table fixes for known C issues, they introduces many unknown things. Remember Java? It promised compile-once/run-everywhere, automatic memory management approach, but introduced bloat, extremely hard to catch GC leaks no one talks about, JVM implementation differences (Oracle JVM vs IBM JVM vs OpenJDK speed) and JVM security issues only few can fix. > why safer versions of C have repeatedly failed over the years I guess this will be like giving to skilled hunter a toy water gun - simply a different mindset. Imagine unsafe python with pointers and mallocs; how python devs would deal with it?
- pcwalton 9y ago> I guess switching to a new compiler (or newer version of the same vendor) is much less burden than switching to the new language. If that were true, then Linux distros wouldn't still be using GCC. Switching to a new compiler (like clang) is a huge burden. Both switching compilers and switching languages are enormously expensive, to be sure. But I think people (especially people in academia) consistently underestimate the cost of switching compilers and overestimate the cost of writing new components in a different language. > Don't forget that all "new safe languages" are simply new. Why people like C is familiarity: known practices and known issues to avoid ironed out through 30 years of usage. Most programmers haven't been programming for 30 years. New programmers, by and large, don't even know C anymore. The problems with C haven't been so much "ironed out" as ignored since C99. > Remember Java? It promised compile-once/run-everywhere, automatic memory management approach, but introduced bloat, extremely hard to catch GC leaks no one talks about, JVM implementation differences (Oracle JVM vs IBM JVM vs OpenJDK speed) and JVM security issues only few can fix. You bring up Java as though it were a failure! Java has in fact been beating C++ in total usage for years. If I could point to one thing that was responsible for kickstarting the slow decline of C++ that has continued to this day, Java would be it.
- AnimalMuppet 9y agoI've used both C and Pascal in embedded systems. Pascal is painful compared to C. A "somewhat modified" version might help, but I doubt it would be enough. To steal a phrase from my friend Michael Pavlinch: Pascal was like picking your nose with boxing gloves on. A modified boxing glove isn't really going to solve the problem. For that matter, once we weren't on Unix but rather on the PC, and we had a nicely-modified Pascal (Turbo Pascal), why did C/C++ win there, too?
- mjw1007 9y agoBasically because Microsoft picked C++ to be the main language for Windows development. Turbo Pascal was all very well but from Microsoft's point of view it was Not Invented Here.
- WalterBright 9y agoC++ wasn't invented at Microsoft, either. The DOS C++ train had already left the station (Zortech C++) and Microsoft wasn't about to be left behind. (Zortech didn't invent C++, either, I don't want to give that impression.)
- pjmlp 9y agoActually if I remember correctly they were the very last PC C compiler vendor to add support for C++.
- pcwalton 9y ago> For that matter, once we weren't on Unix but rather on the PC, and we had a nicely-modified Pascal (Turbo Pascal), why did C/C++ win there, too? Turbo Pascal was quite successful in its day. But Microsoft chose C, and the rest is history. Absent Microsoft's decision, Pascal might still be around. If you look at early Mac development, for instance, Pascal was actually preferred. C only ended up winning due to being better known, which was a result of the critical mass of programmers trained on Unix and Microsoft's offerings.
- camus2 9y ago> For better or worse (personally, I think, for the better), they're starting with JavaScript, Python, Ruby, or even PHP. These higher level languages are still built with C(Python,PHP) or C++(V8 Javascript engine) though, so C is still a language of choice for that task, and writing a library in C allows integration with all these high level languages at very little cost. So there is still incentive for people using higher level language to write C. I mean, PHP is useless if the goal is to share code with Python or Javascript.
- pcwalton 9y agoThere's an incentive to learn assembly language, too. C is useless if the goal is to, for example, write constant-time crypto implementations. I'm not saying there is no reason for anybody to learn C, just that most programmers aren't learning C anymore.
- kahlonel 9y agoDid you even the read the article? How are you comparing JS, Python (or any language "gaining popularity" in your metrics) to C, when the author clearly describes the set of problems only solvable in C?
- nickpsecurity 9y agoGreat overview. To support it on the design side, the video below shows the evolution of the language from CPL to BCPL to B to C. In it, you see they don't start with what's great for analysis, safety, or efficiency so much as what can compile on terrible hardware. Thompson's modifications are a mix of arbitrary and what will make it work on a PDP. Ritchie enhances a bit for operating systems. This is start contrast from the careful design of languages like Ada or Modula-3 balancing expressiveness vs safety vs performance. No surprise a bunch of problems followed. And same ones today, 30+ years later, in average app even with better tooling available since the language itself defaults on making simple stuff require extra work to do safely. Not necessary as Wirth, Morrisett, and others showed. https://vimeo.com/132192250 https://vimeo.com/132192250
- iainmerrick 9y agoThere is no inherent benefit in C that, for example, a somewhat modified version of Pascal or Algol wouldn't have inherited. I happen to like C and think it has a lot going for it, but you're definitely right about this. The original Mac OS was written in Pascal (and assembly), not C. And Turbo Pascal was deservedly popular for a good while. In an alternate universe, Pascal rather than C could be the incumbent legacy systems language.
- WalterBright 9y agoPascal suffered because its standard was woefully incomplete, and every implementation added mutually incompatible proprietary extensions. Turbo Pascal and all the TP developed code died when DOS died.
- pjmlp 9y agoTurbo Pascal did not die, it was reborn as Delphi and only decreased its market share because many key developers ended up going to Microsoft, while Borland management decided enterprise customers were more important than indies.
- speedplane 9y agoWhat year did Borland make that call? I remember my HS programming class in the late 1990s used a Borland compiler and development environment. I don't recall it being "enterprisey" at the time. That being said I was in HS, and likely associated the word "enterprise" with starships more than big companies.
- pjmlp 9y agoWhen they re-braded themselves as Inprise, 1996. https://en.wikipedia.org/wiki/Borland https://en.wikipedia.org/wiki/Borland
- speedplane 9y ago
- WalterBright 9y agoC got popular because it turned out to be ideally suited for DOS, which was by far the dominant target for programmers for over a decade. For example, C could deal with near/far pointers. No other language could. Early C implementations were also usable on DOS, early [other language] implementations were unbelievable unusable, and believe me I tried. There were many diverse, usable, and cheap C implementations available.
- Koshkin 9y agoThe popularity of C had absolutely nothing to do with DOS. The most popular languages on early PCs were BASIC and Pascal. The popularity of C is linked to UNIX, from where it was brought to DOS. The far/near pointers did not play especially well with C view of pointers as integers of some fixed size. The 32-bit flat memory model made C programming somewhat closer to what it used to be in UNIX.
- WalterBright 9y ago> The popularity of C had absolutely nothing to do with DOS. You might want to read popular programming magazines from the early 80s, and the attention given to C on DOS. (It was enormous.) At one time, I counted 30 C compilers available for DOS. What other platform came remotely close to that? > The most popular languages on early PCs were BASIC and Pascal. BASIC was indeed popular, but generally not for professional programming. Pascal had nowhere near the penetration of C in the early days (1982, 1983, etc.). Microsoft Pascal 1.0 was unusable, the top C compiler was Lattice C. > The popularity of C is linked to UNIX, from where it was brought to DOS. Unix was nowhere remotely as popular as DOS. > The far/near pointers did not play especially well with C view of pointers as integers of some fixed size. As a DOS C compiler writer, I can attest that near/far mapped very well onto C semantics. The C Standard in 1989 was very careful to not upset that. > The 32-bit flat memory model made C programming somewhat closer to what it used to be in UNIX. That was much later. But since you brought it up (!), 32 bit DOS extenders were in wide use on DOS, and were programmed with C. I don't recall Pascal ever existing on them, but perhaps I misremember. C was also popular on the 16 bit DOS extenders, I don't remember Pascal on those, either.
- emmelaich 9y agoA "somewhat modified version of Pascal or Algol" would be just C with a different syntax. C is remarkable for what it doesn't have. It sits at a nice local optimum point that a portable assembler must occupy.