eli5: How is C still the fastest mainstream language?

876 views

I’ve heard that lots of languages come close, but how has a faster language not been created for over 50 years?

Excluding assembly.

In: 2072

19 Answers

Anonymous 0 Comments

I think you may have answered your own question without realizing it.

Assembly runs on bare metal, directly driving machine code. The obvious issue is that it requires knowing every function of the processor’s architecture instruction set, and it’s really not portable to other architectures.

There’s a lot of history that’s important to understanding the next bit here, and I’ll try to make it easy.

1970s. Dennis Ritchie was trying to build an OS for the 18-bit PDP-7 processor, doing so in assembly. However, the 16-bit PDP-11 soon came out and because of the speed increase, it was worth mostly restarting (as there really wasn’t a way to switch between the 18-bit and 16-bit). This would set the stage.

Ritchie switched to the PDP-11, and partway through development, realized that coding directly in assembly would tie the OS to this one processor. Recognizing that it would mean making a new OS for every processor, and that hardware was speeding up, he pivoted to making a programming language that would run everything through a compiler for the assembly language syntax for the PDP-11. He then built the OS, named UNIX, in this language, named C.

Because C doesn’t do much. It mostly condenses common machine code instructions into simpler strings (imagine if asking to display a single character in 28 pixel height Arial font meant manually directing the display pixel by pixel, with specified subpixel brightness vale for each one, rather than just telling the language to refer to a library for the pixel mapping and font vectors).

But then there were other processors. And he wanted UNIX to work on them. So the answer was to make compilers for different processors that were compatible with the programs coded in C.

This way you could make source code in C, and as long as you had a compiler for C (which was light to make as it was built on a very simple PDP-11), your source code would run.

Now here’s what matters.

The PDP-11 was CHEAP. Only about $20,000 at the time, which was $50,000 less than the PDP-7. While it wasn’t preferred for mainframes or similar, it was cheap enough to get into the hands of researchers, academics, and smaller companies entering the computational space. Hundreds of thousands of units sold, and the instruction set became so well-understood among the field that companies like Intel and Motorola built their architecture on the same instructions. The 16-bit 8086 microprocessor from Intel, installed in the original IBM PC (which was the first real personal computer), and the 32-bit Motorola 68000 (Sega Genesis, Mac 128K, Commodore Amiga) both were built up with instruction sets that were really just that from the PDP-11. It also meant compiling for C was nearly plug-and-play: even if those newer processors had a lot more instructions available, C programs would still work because they’d address the original PDP-11 instructions.

This led to more programming in C, because those programs were inherently portable. And if new instructions were found on new processors that completed a function more efficiently than the PDP function, it was easy enough to just re-mapp the C compiler for that processor to use that instruction.

68000 processors carried forward, and the 8086 gave us the endlessly undying x86 architecture. A C compiler continues to work on both.

The important bit is the x86 architecture. The IMB PC was a godsend. It standardized home computing as something reasonable for any small business. Operating systems sprung up. UNIX spawned a BUNCH of children, most importantly Linux, its million derivatives, Windows, later versions of Mac OS, came along, all built in C.

And that’s sort of where the story gets stuck. There’s no drive to walk away from C. It’s so well-adopted that it’s driven processor development for decades. The processors are built based on how they can best interface with C. **It’s impossible to do better than that.**

ARM and other reduced instruction set platforms can’t get away from it, because portability matters. So you can compile for C, so you can stuff Java on the RISC chip. As such, RISC architectures are going to continually be compatible with the most basic C implementation; they’re essentially just modified PDP-11 architecture stuffed onto faster hardware at this point.

So while COBOL and ARGOL and other languages are similarly efficient, the architecture they best run on isn’t popular enough to make the languages popular.

You are viewing 1 out of 19 answers, click here to view all answers.