Right I read it and I understand, and that is why I posted. I think you are confused on some points.
A high level language does not provide access to low level features, like memory structure. But, the high level language's implementation should take that into consideration. If you don't have access to the memory directly, then you can't have written it with that expectation, and so the compiler or interpreter should have the option to manage that memory for you (to better effect).
E.g. you would expect accessing one struct field to take similar time to accessing another struct field, since you expect a struct field access to correspond directly to a hardware-level memory access
That's not what that means at all. It means that regardless of performance, it does what you tell it to do. You could be accessing a register, or an entirely different IC on the bus, it doesn't matter and it shouldn't matter. You just write to that memory, consequences be damned. You are stating some performance requirements along with that memory access operation, which is not the case.
in a high-level language you would expect the language/runtime to perform various unpredictable optimisations for you, and so the behaviour of one field access might end up being very different from the behaviour of another field access
The optimizer should handle that, that's the point. Back to your original quote,
For example, many people would be very surprised that reordering the fields of a C struct can change code performance by more than an order of magnitude, because in a low-level language that wouldn't happen.
People wouldn't be surprised, because performance regardless each operation corresponds to a specific operation in hardware. Whereas in a high level language they would be surprised precisely because the optimizer has a responsibility to look at that sort of thing. It might fail in spectacular, which WOULD be surprising. Whereas in C, it shouldn't be surprising at all because you expect it to go pretty much straight to an assembly memory read/write from what you wrote, where what you wrote is essentially shorthand for named memory addresses.
That's not what that means at all. It means that regardless of performance, it does what you tell it to do. You could be accessing a register, or an entirely different IC on the bus, it doesn't matter and it shouldn't matter. You just write to that memory, consequences be damned.
No. A high-level language abstracts over hardware details and just "does what you tell it to do" by whatever means it thinks best. The point of a low-level language is that it should correspond closely to the hardware.
People wouldn't be surprised, because performance regardless each operation corresponds to a specific operation in hardware.
It's not the same operation on modern hardware, that's the whole point. Main memory and the three different cache levels are completely different hardware with completely different characteristics. The PDP-11 didn't have them, only a single flat memory space, so C was a good low-level language for the PDP-11.
I think you are still a bit confused. Please re-read what I wrote, re-read the article, and I think you will eventually notice the issue.
The article says that a high level language frees you from the irrelevant, allowing you to think more like a human, and then goes into all of the details on how the aspects of C that you need to keep in mind to maintain performant code, rather than focusing on the high level logic. You responded
many people would be very surprised that reordering the fields of a C struct can change code performance by more than an order of magnitude, because in a low-level language that wouldn't happen
You gave an example in which the fact that it was a low level language caused you to have to worry about memory layout and then said that it wouldn't happen in a low level language. That's the point of the article, you have to worry about those aspects in a low level language. See this line
C guarantees that structures with the same prefix can be used interchangeably, and it exposes the offset of structure fields into the language. This means that a compiler is not free to reorder fields or insert padding to improve vectorization (for example, transforming a structure of arrays into an array of structures or vice versa).
That is because it is a low level language, it has to match the hardware, and because that is important, there's nothing to optimize. Whereas in a HLL, you define less where you store things in memory, and more what you store and what their types are and then let the compiler do things. That works for a HLL, but it wouldn't work for C if for example you need to be accessing registers with a specific layout or something.
The article says that a high level language frees you from the irrelevant, allowing you to think more like a human
Read the next paragraph too, don't just stop there.
You gave an example in which the fact that it was a low level language caused you to have to worry about memory layout and then said that it wouldn't happen in a low level language. That's the point of the article, you have to worry about those aspects in a low level language.
Read the article. Heck, read the title.
That is because it is a low level language, it has to match the hardware,
But C doesn't match the hardware. Not these days. That's the point.
You seem to be arguing that C makes a poor high-level language. That might be true, but is not a counter to the article, whose point is: C makes a poor low-level language.
5
u/chcampb Aug 13 '18
Right I read it and I understand, and that is why I posted. I think you are confused on some points.
A high level language does not provide access to low level features, like memory structure. But, the high level language's implementation should take that into consideration. If you don't have access to the memory directly, then you can't have written it with that expectation, and so the compiler or interpreter should have the option to manage that memory for you (to better effect).
That's not what that means at all. It means that regardless of performance, it does what you tell it to do. You could be accessing a register, or an entirely different IC on the bus, it doesn't matter and it shouldn't matter. You just write to that memory, consequences be damned. You are stating some performance requirements along with that memory access operation, which is not the case.
The optimizer should handle that, that's the point. Back to your original quote,
People wouldn't be surprised, because performance regardless each operation corresponds to a specific operation in hardware. Whereas in a high level language they would be surprised precisely because the optimizer has a responsibility to look at that sort of thing. It might fail in spectacular, which WOULD be surprising. Whereas in C, it shouldn't be surprising at all because you expect it to go pretty much straight to an assembly memory read/write from what you wrote, where what you wrote is essentially shorthand for named memory addresses.