4 ms·
Wait until they learn that machine code is not exactly how the computer works either. The hardware is doing things to your code you might not expect.
by spicymaki 7y ago
Wait until they learn that machine code is not exactly how the computer works either. The hardware is doing things to your code you might not expect.
- ForHackernews 7y agohttps://blog.erratasec.com/2015/03/x86-is-high-level-language.html https://blog.erratasec.com/2015/03/x86-is-high-level-languag...
- ThrowawayR2 7y agoAgreed, The example the author uses in his previous post on the topic talks about cache-unaware code but it's perfectly possible to write cache-unaware code in machine language as well. I'd say "C is not how the computer works ... but it's much, much closer than nearly every other language."
- pdimitar 7y agoI feel your statement is actually much closer to the danger. C is pretty close to the hardware indeed and that misleads people into thinking that C is actually exactly how the hardware works. It's a very easy trap to fall into and I've seen many colleagues do just that.
- dpc_pw 7y agoM............................................C M..............................................Java Look. C is much closer to how the machine (M) works.
- snazz 7y agoJava’s GC and lack of pointer arithmetic should push it a little further to the right, no?
- stonemetal12 7y agoI don't see why it would. Given what modern CPUs do to make memory fast and safe, pointer arithmetic is a ridiculous simplification that has no bearing in reality.
- scottLobster 7y agoGive that Java is written in C++ which is in turn an extended version of C, I'm not sure that chart is entirely to scale.
- TomMarius 7y agoThat is no argument in this discussion, IMHO - what does it change? The discussion is about the language (and in case of Java, the runtime) and it's machine abstraction, which is nearly the same for Java and C, even if JVM was written in Lisp.
- deleted 7y ago[deleted]
- toolslive 7y ago> Java is written in C++. I think you're talking about the JVM. Anyway, some processors have native support: https://en.wikipedia.org/wiki/Jazelle https://en.wikipedia.org/wiki/Jazelle
- saagarjha 7y agoJazelle is very dead, FWIW.
- scottLobster 7y agoSo no disrespect to your colleagues, but they work in C and don't understand the relationships between C --> ASM --> Machine Code --> Hardware? That's... disturbing. Hope they're not building medical devices.
- pdimitar 7y agoMy point was that many people who just now come into C fall into the trap of thinking that it [almost] exactly mimics hardware. Which is an easy mistake to make if you are new to the thing because it's taught as if it's a panacea and sadly many people believe those university courses. As for former colleagues, oh well, we all learn and grow. I chose to bail out because something as non-deterministic as a C's code stability when cross-compiled for anything more than two systems turned me off. Different strokes, different people.
- umvi 7y agoIt's turtles all the way down. We tend of think of everything as an ideal model in a vacuum, forgetting that in real life that the implementation details are often gory with caches and microcode and fault tolerance and all sorts of hidden details put in there to make things easier to work with or faster.
- xgiok78xh 7y agoIt’s not how the hardware works. It’s how the hardware is modeled. Hardware works as physics allows, at energies we can’t comprehend. A computer is designed to a spec we can (sort of) comprehend. Spectre and such being evidence we don’t fully comprehend it. It’s a recursive back and forth of this is a structure, this is the favored algorithm for that structure. The hardware is the structure. Physics provides the algorithms for operating on that structure. Thinking like one can see inside the machine always struck me as absolutely ridiculous. It exists in the world defined by physics. Crawling into our imagination, linking abstract pictures from textures together arbitrarily, doesn’t mean we’ve discovered something new. We know all kinds of stuff can be modeled on a compute because reality already gave us the math model. We’re just brute forcing implementation looking for simple models for things we already have
- deelowe 7y agoEven binary code isn't "how the computer works" these days.
- aequitas 7y agoNever has been. Deep down 1's and 0's are still analog voltages, subject to capacity and inductance, on a tiny wire between transistors. Without proper timing you end up reading the voltage half way between ascending from 0 to 1 and who knows what value you end up with.
- mark-r 7y agoIf you violate the timing for a flip-flop circuit, you can put it into a metastable state where the "digital" output varies between 0 and 1 for a very long time.
- globuous 7y agoHence the massively upvoted SO thread ;p : https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array https://stackoverflow.com/questions/11227809/why-is-processi...
- mpweiher 7y agoRight. But machine code is the interface that the hardware provides to the rest of the world, meaning you can ignore that the hardware is doing something different. And in fact, you don't really have access to what the machine is doing. Or maybe you can get at all those virtual renamed registers? I can't, I can just access the architectural registers. Now if you care about performance, you might not want to ignore the real machine, but it really bis the hardware's job to work like the machine code tells it to. And when it doesn't, that's considered a bug^H^H^H exploit.