Argue all you want about what defines a high level or a low level language... But most people look at this relatively.
If c is a high level language, what the hell does that make something like JavaScript or F#?
If c isn't a low level language, what is below it? Most programmers these days don't touch any form of assembly anymore.
So yea, this is true depending on your definition of these words, but people will continue to refer to c as a low level language because, relative to the languages most of us actually know and use, it's one of the lowest.
That is indeed what the author starts out by saying: imagine a spectrum where assembly is on one end and the most advanced computer interface imaginable is on the other. Then he goes on to talk about out of order execution and cache and how they don't map to C even though assembly has no concept of OoO or cache either.
So really what he's saying is that C is a low-level language...for a different (and much simpler) system than what your code is actually running on. What you're actually running on is kind of a PDP-11 hardware emulation layer on top of a heavily-parallelized multi-core architecture with complex memory and cache layouts. Maintaining that hardware emulation layer is becoming a burden, and is starting to result in exploits and regressions.
Maintaining that hardware emulation layer is becoming a burden
I think a better way to describe it is that it's an increasingly leaky abstraction. And those leaks are becoming so bad that we should consider whether it's even the right abstraction to use anymore.
Then he goes on to talk about out of order execution and cache and how they don't map to C even though assembly has no concept of OoO or cache either
I've made the same observation down below, where I was having fun with some trolls (hence got downmodded).
This article is a more a "Programming Language Problems" than a "C Language Problems" article. I'm not sure what the author's intention was to deride C for having all these problems when literally every other language, including assembly, has these problems because these are processor problems.
How is that a C problem as opposed to a programming language problem?
Look, I get the point that the author is trying to make WRT to spectre-type attacks, but the how is this a C problem and not a Programming Language problem?
It doesn't matter what programming language you use, you are still open to spectre. It doesn't even matter if you go off and design your own language that emits native instructions, you're still going to get hit by errors in the microcode that lies beneath the published ISA.
The only way to avoid this is to emit microcode and bypass the entire ISA entirely, at which point you can use any high level language (C included) that has a compiler that emits microcode.
Chances are, even if you did all of the above, you'd find there's no way to actually get your microcode to run anyway.
So, given the above, why does the article have such a provocative title, and why is the article itself written as if this is a C problem? It clearly isn't.
I'm not sure what the author's intention was to deride C for having all these problems
He's challenging the assumption that people have that C is "close to the metal". That's definitely something people believe about C, as opposed to other programming languages, but he points out that it's no longer particularly true.
At the end of the article, the author takes a shot at suggesting some alternative approaches (Erlang-style actor model code, immutable objects, etc.
Right, exactly. That's his point. People think other languages are high-level, but C is close to the metal. But the metal C was close to is long gone, and there's now many layers of abstraction between you and the hardware--and those layers are starting to leak.
He didn't claim other languages are lower-level, and this wasn't a hit-piece on C. It's just an interesting realization. I'm detecting a fair bit of wounded pride in this thread.
Even using assembly is high level in this description as the processor itself will reorder and execute assembly instructions in parallel
There aren’t any low level languages, assembly is a set of instructions that must maintain data dependence ordering, but can be executed in parallel or any order desired that improves performance. Processors don’t even have x86 registers as they map and rename registers internally where data dependence allows
Seriously, the issue is that because CPUs want to maintain backwards-compatibility, they end up messing with your machine code. It's been years since all the x86 assembly you write won't be run in the order you think it would.
You can't program the CPU directly now, only Intel and AMD can.
the issue is that because CPUs want to maintain backwards-compatibility, they end up messing with your machine code
Backwards compatibility is a reason, but not the only reason. If you were to design an ISA today, you'd still hide a lot of the underlying uArch details from the programmer's perspective, and the end result probably wouldn't be terribly different from x86.
As it turns out, the processor has a lot of runtime information that a compiler cannot determine ahead of time. Attempts try to and expose more of the underlying pipeline, like Intel's Itanium, generally haven't proven to be that successful.
I'd say Itanium had great potential, but then you have to wonder if it's usually worth it to get so close to the metal. It gets really complicated, and you might as well go the ASIC route if you want something really optimized. I've worked on some TI high performance chips, the documentation was about the size of the 8086 (being RISC helps) but still not something most people would want to write assembly for when they give you a compiler that does a pretty good job and they also give you hints to let the compiler help you.
There was a whole section showing how to optimize a loop (with the generated code) and in the end, if you let the compiler do its job you get the same result with no headache. Seriously, I don't want to remember if my variable is in ALU A or ALU B (one didn't have some of the less used operations).
You - and most people on this thread - seem to be focusing on the everyday Intel/AMD computers. Yeah, the translation of C to those is pretty straightforward. But it isn't to the JVM, for example. To the JVM and others, pointers are a high level abstraction, since it has no instructions for direct addressing. Also, to the JVM, Java is a pretty "low level" language, since it's translation to JVM's bytecode is pretty straightforward.
One may argue "but the JVM is a virtual machine", well, we do have physical implementations (e.g., Jazelle). So why "low level" would imply "closer to Intel" but not "closer to the JVM"? Closer to the random access machine instead of any other kind of register machine? What about the SECD?
Also noteworthy: the C standard gives absolutely no guarantees about direct addressing (as in int *ptr = 0xB8000), as one would expect to work in plain assembly for accessing VGA memory. Picturing C as a low level language makes programmers make bad assumptions and write undefined behavior (according to the standard, you can't even compare two pointers that didn't come from the same array with < or >... a low level language sure would allow that).
If c is a high level language, what the hell does that make something like JavaScript or F#?
Also high level languages.
The point of the article is that if you ever think something like "I'll use C instead of JavaScript/F#, it'll be more work but my code will correspond exactly to machine behaviour and that will make it easy to understand the performance", that thought is wrong and you'd be better off just using JavaScript/F#. It's similar to the "it tastes bad so it must be good for me" fallacy - since C is so much harder to program in than JavaScript or F#, people assume there must be some counterbalancing benefit, but that's not actually true.
I think it's fair to look at it relatively in which case C is pretty low level. The only thing lower you can go is assembly/byte code.
If he gave a decent definition of 'low level' and contrasted it with C, then I wouldn't have too much of an issue. But he gives a fairly hand wavy definition and spends minimal time arguing why C doesn't go by this definition.
239
u/Sethcran May 01 '18
Argue all you want about what defines a high level or a low level language... But most people look at this relatively.
If c is a high level language, what the hell does that make something like JavaScript or F#?
If c isn't a low level language, what is below it? Most programmers these days don't touch any form of assembly anymore.
So yea, this is true depending on your definition of these words, but people will continue to refer to c as a low level language because, relative to the languages most of us actually know and use, it's one of the lowest.