5 ms·
C++: "model of the hardware" vs. "model of the compiler" (2018)
- gsliepen 1y agoEarly programming languages had to work with the limited hardware capabilities of the time in order to be efficient. Nowadays, we have so much processing power available that the compiler can optimize the code for you, so the language doesn't have to follow hardware capabilities anymore. So it's only logical that the current languages should work the limitations of the compilers. Perhaps one day those limitations will be gone as well for practical purposes, and it would be interesting to see what programming languages could be made then.
- lmm 1y agoIsn't that the tail wagging the dog? If you build the language to fit current compilers then it will be impossible to ever redesign those compilers.
- gsliepen 1y agoWhy would that be impossible? Most programming languages are still Turing complete, so you can build whatever you want in them.
- rcxdude 1y agoMaybe, but if you don't consider the existing compilers you run the risk of making something that is unimplementable in one of the existing compilers, or perhaps at all. (C++ has had some issue with this in the past, which is I think why it's explicitly a consideration in the process now)
- flohofwoe 1y ago> Nowadays, we have so much processing power available that the compiler can optimize the code for you, so the language doesn't have to follow hardware capabilities anymore. That must be why builds today take just as long as in the 1990s, to produce a program that makes people wait just as long as in the 1990s, despite the hardware being thousands of times faster ;) In reality, people just throw more work at the compiler until build times become "unbearable", and optimize their code only until it feels "fast enough". These limits of "unbearable" and "fast enough" are built into humans and don't change in a couple of decades. Or as the ancient saying goes: "Software is a gas; it expands to fill its container."
- adrianN 1y agoAt least we can build software systems that are a few orders of magnitude more complex than in the 90s for approximately the same price. The question is whether the extra complexity also offers extra value.
- flohofwoe 1y agoTrue, but a lot of that complexity is also just pointless boilerplate / busywork disguised as 'best practices'.
- Trex_Egg 1y agoI am eager to have an example to explain how a "best practices" is making the software unbearable or slow?
- flohofwoe 1y agoSome C++ related 'best practices' off the top of my head: - put each class into its own header/source file pair (a great way to explode your build times!) - generally replace all raw pointers with shared_ptr or unique_ptr - general software patterns like model-view-controller, a great way to turn a handful lines of code into dozens of files with hundreds of lines each - use exceptions for error handling (although these days this is widely considered a bad idea, but it wasn't always) - always prefer the C++ stdlib over self-rolled solutions - etc etc etc... It's been a while since I closely followed modern C++ development, so I'm sure there are a couple of new ones, and some which have fallen out of fashion.
- j16sdiz 1y agoThe problem is: "the platform" is never defined. When you decouple the language from the hardware and you don't specify an abstraction model (like java vm do), "the platform" is just whatever the implementer feels like at that moment.
- simonask 1y agoIt's not really about "limitations" of the hardware, so much as it is about the fact that things have crystallized a lot since the 90s. There are no longer any mainstream architectures using big-endian integers for example, and there are zero architectures using anything but two's complement. All mainstream computers are Von Neumann machines too (programs are stored; functions are data). All bytes are 8 bits wide, and native word sizes are a clean multiple of that. Endianness will be with us for a while, but modern languages don't really need to consider the other factors, so they can take significant liberties in their design that match the developer's intuition more precisely.
- gsliepen 1y agoI was thinking more about higher-order things, like a compiler being able to see that your for-loop is just counting the number of bits set in an integer, and replacing it with a popcount instruction, or being able to replace recursion with tail calls, or doing complex things at compile-time rather than run-time.
- flohofwoe 1y agoAt least the popcount example (along with some other 'bit twiddling hacks' inspired optimizations) is just a magic pattern matching trick that happens fairly late in the compilation process though (AFAIK at least), and the alternative to simply offer an optional popcount builtin is a completely viable low-tech solution that was already possible in the olden days (and this still has the the advantage that it is entirely predictable instead of depending on magic compiler tricks). Basic compile time constant folding also isn't anything modern, even the most primitive 8-bit assemblers of the 1980s allowed to write macros and expressions which were evaluated at compile time - and that gets you maybe 80% to the much more impressive constant folding over deep callstacks that modern compilers are capable of (e.g. what's commonly known as 'zero cost abstraction').
- deterministic 1y agoNope. Performance really matters. Even today. And even for web applications! Just remember how you feel using a slow sluggish website vs. a snappy fast one. It's night and day.
- bluetomcat 1y agoWhat a mess of an article. A pretentious mishmash of scattered references with some vague abstract claims that could be summarised in one paragraph.
- flohofwoe 1y agoSort of fitting though, because C++ coroutines turned out quite the mess (are they actually usable in real world code by now?). I think in the end it's just another story of a C++ veteran living through the inevitable Modern C++ trauma and divorce ;) (I wonder what he's up to today, ITHare was quite popular in game dev circles in the 2010s for his multiplayer networking blog posts and books)
- TuxSH 1y ago> C++ coroutines turned out quite the mess (are they actually usable in real world code by now?). They are, they are extensively used by software like ScyllaDB which itself is used by stuff like Discord, BlueSky, Comcast, etc. C++ coroutines and "stackless coroutines" in general are just compiler-generated FSMs. As for allocation, you can override operator new for the promise types and that operator new gets forwarded the coroutine's function arguments
- simonask 1y agoThey are compiler-generated FSMs, but I think it's worth noting that the C++ design was landed in a way that precluded many people from ever seriously considering using them, especially due to the implicit allocation. The reason you are using C++ in the first place is because you care about details like allocation, so to me this is a gigantic fumble. Rust gets it right, but has its own warts, especially if you're coming from async in a GC world. But there's no allocation; Futures are composable value types.
- pjmlp 1y agoThe C++ model is that in theory there is an allocation, in practice depending on how a specific library was written, the compiler would be able to elide the allocation. It is the same principle that drives languages like Rust in regards to being safe by default, in theory stuff like bounds checks cause a performance hit, in practice compilers are written to elide as much as possible.