top | item 34183738

50 years of C, the good, the bad and the ugly [video]

156 points| enduku | 3 years ago |streaming.media.ccc.de

254 comments

order

antirez|3 years ago

A different take on the matter: I write code mainly artistically, and I found that C is one of the best languages available to code as a form of art. It allows to be both brutal and honest, or abstract and deceiving. Not many languages are so semantically powerful.

WastingMyTime89|3 years ago

It’s mostly semantically very poor to be honest. C really is a nicer assembly in a lot of way. It’s extremely limited. You have branching logic, functions call, pointer arithmetic, a way to define data structures which are really memory layouts and that’s pretty much it. I guess you can appreciate that as an aesthetic statement but what you wrote would apply equally to any language with more complex semantics.

low_common|3 years ago

Can you share some examples of your "art"? I'm trying to wrap my brain around the concept of writing code for any reason other than work or trying to build something.

nikbackm|3 years ago

C++ should be even better in those categories.

antoniuschan99|3 years ago

What are your goto sources of knowledge for C? I’m learning it to write embedded stuff and so far it’s mainly the k&r book, one from no starch press, and a udemy course. Thanks!

xigoi|3 years ago

Can you expand on that?

coldcode|3 years ago

I bought a C compiler at my job in 1984 because I thought it was the future, then spent nearly a decade writing MacOS apps in C. I even added object extensions to it (for our use) in 1989 because C++ was not an option yet.

I worked with Objective-C in the late 90s and again in the 2010s, which is basically C with funky object stuff.

I don't miss it at all. C is very low level and so easy to write bad code in if you don't have solid discipline, the language doesn't help at all, which was not really a design decision back then. The first C compiler we used didn't even support prototypes.

I exclusively use Swift now.

pjmlp|3 years ago

What about MPW, MacApp and Metrowerks PowerPlant?

Koshkin|3 years ago

Only a mother could love Swift's syntax. The classic K&R C, on the other hand, was the very definition of simplicity and elegance. (Objective-C is a whole another topic, of course.)

fjfaase|3 years ago

His final conclusion is that C has to go, just like COBOL, Fortran, and PL/I. I wonder how long it will take before C will be gone totally when you realize how much COBOL and Fortran are still around. Not so long ago, I came along a module for Python 'SciPy.interpolate' that happens to be programmed in Fortran.

hgs3|3 years ago

C is the best abstraction for many problem domains and that isn't going to change. I understand why folks coming from higher-level languages would dislike it, but for anyone coming from assembly it's a godsend.

The speaker discourages C for new projects, but that says more about the problem domains they work in than C itself. C is what it is because the hardware and assembly language are what they are. Folks who want a safer C should design a new hardware architecture with a "safe" assembly language and a new low-level language that targets it.

Decabytes|3 years ago

I think it will go when we have a sufficiently popular and useful systems programming language that will replace it. It has to be a language that isn't just C with some extra bits, which is why SafeC and CheckedC aren't more popular. I actually think the closest language will be Zig. It's a much simpler language than Rust and people who like C really value that simplicity. It also removes a lot of Cs baggage that make it annoying to program in. But since Zig 1.0 is unlikely until 2026 I'd say we wouldn't start seeing Zig majorly displace any C programs until about ten years after 1.0, which would be 2036. Rust 1.0 was in 2015 and we are just starting to see it in the Linux kernel ~ 8 years out, so that seems like a good timeline. Then just give it another 40 years and I could see a future where Zig and Rust replace all code where C is currently used. Sure there might be some ancient legacy systems that use C, but just like COBOL, would not be something that you would come across unless you wanted to.

jvanderbot|3 years ago

There are certainly some key libraries that use Fortran still. But I wouldn't say it's still "around". As a language for new projects, it's extremely niche. That's probably what "go" means in your comment.

I assume you're being facetious with the "recently came across", since scipy is so common, but I will add that nearly every math-intense library is a clever wrapper for some Fortran code.

I would be perfectly happy to see many hardened C libraries become the foundation of the next gen systems/ embedded languages. It does bother me slightly when we abandon the past entirely and attempt to "rewrite it in X"

Sakos|3 years ago

Is that even possible as long as the Linux kernel is written in C? I wonder if telling people not to learn C will have a long-term effect on being able to find competent contributors to the kernel.

jillesvangurp|3 years ago

In a way, it's already happening. Many big tech companies are now defaulting to other languages than C and are actively discouraging the use of C or C++ for new code. They still have a big vested interest in maintaining existing code of course. That's not going to disappear overnight obviously.

kovac|3 years ago

Can C really completely go away as long as there's embedded programming? Are there any other alternatives for that domain?

pjmlp|3 years ago

It won't go away, but just like it happens with COBOL, Fortran, and PL/I, you won't see anyone dreaming of coding C until the end of their working days.

Or maybe they will, given how much consultants in those languages happen to be paid, as no one else wants to touch them.

Tozen|3 years ago

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.

flohofwoe|3 years ago

A good bet is that a technology will be around at least as long as it has been around (I think there's also a 'named law' for it). So I fully expect C to be around in one way or another for the next 50 years, it probably won't be as important anymore, just as COBOL or Fortran are not as important as they used to be.

One reason for C to disappear completely would be if computer architectures would change so much that current programming languages no longer even map to those new architectures (e.g. all the existing programming languages would need to be dumped anyway).

jcranmer|3 years ago

My prediction is that C will die off as a language long before Fortran and COBOL. What keeps a language like Fortran alive is that it is used in an application niche where rewriting is done at best ship-of-Theseus style, and the friction of using a new language for a component far outweighs the benefits of doing so (weather models are a good example here). For COBOL, it remains in applications where the cost of a switch or rewrite includes a low risk of catastrophic, and therefore expensive, failure (see Southwest Airlines for a very public and recent example of such a failure).

C does have a similar kind of niche at first glance: systems programming is of course conservative, rewriting everything is unlikely, and of course, C is the language used for ABI. Except on closer inspection, that moat is remarkably shallow. Being the language of ABI means that every competitor language has some way to speak C guaranteed, so the friction of rewriting systems software Ship-of-Theseus-style is much lower (though still nonzero). Systems software is rewritten from scratch on a much higher cadence: in the last 20 years or so, most of the userspace system glue for Linux has been replaced (e.g., systemd, iproute2, pulseaudio, wayland). And we've learned over the past few decades that there's no practical way to fix C's fundamental unsafety issues with software engineering practices, and C's committee is too conservative to consider retrofitting the necessary features to be able to fix unsafety at a language level (to say nothing of getting people to use it).

There is already a small clutch of languages that can serve C's niches that don't have the same fundamental unsafety issues, and right now, we're sort of at an experimental stage of system software trying them out. It's not unreasonable to believe that within a decade or so, one or more of these languages would be considered a standard, safe choice for implementing new systems software--and the use of C in new projects will start dropping. At some point, the proliferation of non-C systems projects will make people point out that having these components talk through C's ABI is too limited in functionality, and a system will change its ABI from C to some other language. And once it is no longer the language of ABI, C will lack its moat that keeps it alive, and it will start dying, though its death will be a slow, agonizing death.

AstixAndBelix|3 years ago

We can replace COBOL with a Java backend to keep the enterprise feeling going, but what would C's replacement be in this case?

sylware|3 years ago

C syntax is already way too rich and complex, not to mention the bazillions of gcc extensions required to compile the linux kernel.

Namely, if it has to be "replaced", that would be with something with a much simpler syntax, which will require a bit more of finger power. We don't want to find ourself locked-in by very few compiler vendors (open source or not), that only because it is not reasonable to code a real-life alternative with a small team of averagely skilled devs in a reasonable amount of time.

This language should build on C though: no enum/typedef/_generic/switch/etc, only 1 loop keyword (loop{}) only explicit sized types, no integer promotion, no implicit casts (except maybe void* pointers but number literal casts should be) but explicit casts (compile-time and runtime, without that horrible c++ syntax), explicit compile-time const (we have only runtime consts which could be optimized as compile-time consts), enforce extern for functions (and don't try to put the binary format, elf/coff/etc, semantics into the language syntax or worse, the OS interface semantics), etc.

With enough discipline (and compiler warnings), we could get close to such language.

I did not check the latest and greatest rust syntax, but is what's above its explicit goals?

That said, I am a "everything in 64bits RISC-V assembly with x86_64/arm64 legacy ports kind of guy"... if RISC-V is successful (I wish). We could think of high-level language interpreters (coded in assembly, for instance a RISC-V coded python/lua/javascript/etc interpreters).

stephc_int13|3 years ago

The more I learn about new and less new languages (Zig, Jai, C#) the more I like C and its true simplicity.

The language has a few irritating historical artefacts and the stdlib API is completely outdated and full of bad design, but there it is still versatile enough for my needs.

matheusmoreira|3 years ago

> the stdlib API is completely outdated and full of bad design

It is also completely unnecessary on Linux. I switched to freestanding C and discovered it was a much better language. Made programming fun again. All I needed was one system call function and some entry point code.

It's gotten to the point that it bothers me that gcc could potentially generate calls to mem* functions even in freestanding mode.

warmwaffles|3 years ago

The simplicity is a blessing and curse. I enjoy writing C and sticking to a hard discipline of writing unit tests for all functions where possible. Abusing `assert/1` in debug mode. But concurrency is a hard thing to build. Identifying critical sections, making sure they have mutex locks where necessary. I want to love Rust but it's hard for me to get used to the syntax. I've started using it and failed multiple times because it's terse. Inevitably I will try again and hope it pans out.

adamrezich|3 years ago

I like C89 for its simplicity too but after using the Jai beta for over a year I have a hard time seeing myself ever going back.

pjmlp|3 years ago

> The combination of BASED and REFER leaves the compiler to do the error prone pointer arithmetic while having the same innate efficiency as the clumsy equivalent in C. Add to this that PL/1 (like most contemporary languages) included bounds checking and the result is significantly superior to C.

https://www.schneier.com/blog/archives/2007/09/the_multics_o...

"Multics B2 Security Evaluation"

https://multicians.org/b2.html

But naturally ignoring it was more fun,

> Although we entertained occasional thoughts about implementing one of the major languages of the time like Fortran, PL/I, or Algol 68, such a project seemed hopelessly large for our resources: much simpler and smaller tools were called for. All these languages influenced our work, but it was more fun to do things on our own.

https://www.bell-labs.com/usr/dmr/www/chist.html

zozbot234|3 years ago

"Speaking as someone who has delved into the intricacies of PL/I, I am sure that only Real Men could have written such a machine-hogging, cycle-grabbing, all-encompassing monster. Allocate an array and free the middle third? Sure! Why not? Multiply a character string times a bit string and assign the result to a float decimal? Go ahead! Free a controlled variable procedure parameter and reallocate it before passing it back? Overlay three different types of variable on the same memory location? Anything you say! Write a recursive macro? Well, no, but Real Men use rescan. How could a language so obviously designed and written by Real Men not be intended for Real Man use?"

FpUser|3 years ago

He says something like

>"if you want to write new program in C now think long and hard and pick something else"

I would not use plain C to write enterprise backend servers. I happily use modern C++ for that.

For some very low power microcontrollers however I absolutely would. Amount of high quality free tooling and libraries beats everything else.

From a practical point of view: I've written enough firmware for very lowly microcontrollers like AT90USB1286. Runs like a charm (oldest for 10 years already), did not not require even single bug related update and zero complaints from customers. Changing the language in this particular case would bring no benefits but extra expense.

Gibbon1|3 years ago

> I would not use plain C to write enterprise backend servers. I happily use modern C++ for that.

I tend to think unless perform/$ is really important one should use a managed language for that, that isn't Javascript.

But yeah, not really sure what some other language would buy me in the small embedded space that earns me my beer money. I recently had an issue where the corporate spyware was convinced make/gcc were up to no good resulting in minute and a half compile times instead of the usual 10 seconds. I spent a bunch of time with IT getting that fixed. Well that's the build time I'd get with Rust. So Rust is a big nope. C++ is not that slow but still slow. And C++ without malloc is well who are we trying to kid here.

tails4e|3 years ago

I often wonder why c did not deprecate the bad bits, like the dodgy string functions should at least be behind a switch to enable, like --enable-strcat or something. Even the printf bug when passing a single argument is easily fixed by requiring two arguments at a minimum, etc. Then leveling up the std library to force the use of bounds checked strings and buffers, again hiding the unsafe ones behind switches or unsafe keywords. This woukd allow backwards compatability, while making newer code safer by default.

stephc_int13|3 years ago

The C language and the C stdlib are not the same things. You can use C without the stdlib.

You simply have to build or use a different framework offering similar or better APIs.

pjmlp|3 years ago

WG14 never cared that much about security, as simple as that.

jokoon|3 years ago

I'm trying to build a language that translates directly to C. I will just implement some features of the language in C, with some headers I can already find.

It feels like it's the best way I want to do this. That way, a C compiler can do a lot of work I really don't want to do, C already has backends, optimizers, etc etc.

All I want is a C-like language with native strings, hash map and list, tuples python indentation, vector math, and nothing else, and make it as simple as possible.

I'm a bit tired of new language trying to do new things, I just want something less verbose than C, but not as powerful as C++, with the feeling of python.

Tozen|3 years ago

or Vlang (https://vlang.io/), which can compile to C, and has a C2V transpiler.

jacquesm|3 years ago

Great talk. Borland should have rated a mention though, their C compiler really popularized C development on Windows.

pjmlp|3 years ago

Most sane Borland customers were using C++ alongside Object Windows Library, not raw C alongside Win16.

Even Petzold embraced C++, even if superficially,

"This third edition has several changes. First, all programs are now compilable with either the Microsoft or the Borland compiler. All make files are generic and use environment variables for compiler flags, link libraries, and so forth. Second, all programs are now compilable in C++ mode. Although I don’t use any C++ specific features, compiling first in C++ mode is helpful if C++ features are to be added later to the code"

-- https://archive.org/details/programming-windows-31-3rd-ed/pa...

FpUser|3 years ago

It is a real shame Borland went form the company providing best and affordable development tools ever to some big enterprise would have been but nobody needed it and to oblivion.

JonChesterfield|3 years ago

I maintain that C is fine and optimising compilers converting 'bad' C into dangerously broken binaries is not fine. We don't need to replace C to make it safe, we need to take the edge off undefined behaviour justified compiler rewrites.

Kototama|3 years ago

Saying C is fine, does not make it fine though. The facts speak for themselves: even the best programmers in this world which are extremely conscious about security have vulnerabilities in the software they wrote because of C. There were two remotes vulnerabilities in OpenBSD since it's creation, more recently there was a vulnerability in the ping utility of FreeBSD, etc.

C without undefined behaviors is not C anymore by the way. It would be something else.

rightbyte|3 years ago

I believe the main culprit is that the compiler guys want to optimize away Cpp templates, where programmer intent is not as explicit as in C.

jecel|3 years ago

An important part of C history is that in the early 1980s the IBM PC and clones became the most popular computer in the world and it was not really compatible with C. You could say your program was "tiny" and limit it to 64KB or fill your code with "near" and "far" pointers (if using Microsoft tools) or use @ instead of * (if using QNX tools), but the cost was not being able to port to/from the VAX/68000 world. All this went away with the 386, but without this problem it is likely that C would have overtaken Pascal even sooner.

It is not hard to say what is unique about C: it and Forth are the only high level languages with seamless access to memory. If other languages offer it at all, like PEEK and POKE and Basic, it is far more awkward and interrupts your flow. That might be a good thing - the ESPOL compiler mentioned in the talk would print a big fat warning "YOU MUST KNOW WHAT YOU ARE DOING!" after any line in your code doing C-like tricks.

Koshkin|3 years ago

C is like your wife: you love her; you are afraid of her a little; sometimes you wish she was someone else.

andsoitis|3 years ago

Speaker asks: "What can and should replace it?" (i.e. if you started a new project today, what language should you pick instead of C, because C would be the wrong choice).

He goes on to list the following options (and says C++ does not count), but we'll only know far in the future which would have been the right pick:

- Rust

- Go

- Zig

- V

- Nim

- Swift

- ...

pjmlp|3 years ago

The problem with C++, is that while it offers the language features to write safer code than C, it is also copy-paste compatible with C (most of it anyway).

So while a security conscious group can write C++ code that takes advantage of those features, other group can basically compile C++ code that is hardly any different from C.

So it is a better option than raw C, if it is the only viable alternative (like in HPC), but for security conscious scenarios one of the others is a better answer, if available.

timbit42|3 years ago

None of them are the wrong pick. They're all better than C.

vivegi|3 years ago

I was in college early '90s in CS&E (Comp Sci & Engg) and we were taught Pascal first, COBOL and then C. Pascal and COBOL in the second year and C in the third year. C++ was already there, and gaining traction and I taught myself C++ (through the Annotated C++ Reference by Stroustrup). By the time I graduated most jobs were expecting C/C++ coding skills and my first job involved coding in C++.

Nothing compares to the raw power and control we get with C.

Around '97-98 Java was all the rage. Then Bill Gates did his internet pivot and we had .NET arriving in the '00s. The allure of being able to program in any framework language and interoperate looked like a good thing.

Over the last 20+ years I had been in the .NET world and just this year I went back to writing in C and it all came back. It is quite refreshing to be completely responsible for every aspect of your code's working. While it is sometimes tedious, nothing beats the power and control of working close to the machine abstraction.

Just my 2cents.

wheelerof4te|3 years ago

The most complicated and the most simple language at the same time.

davidhyde|3 years ago

I wonder what form a “typescript for c” language would take and if it would be as revolutionary as typescript was for JavaScript applications. I would assume that all the existing c tooling could still be used.