110 points · by ingve · 6y ago · 61 comments
#include <iostream>
int main () {
std::cout << "Hello world\n";
}
>Which on my system expands to about 33000 lines of code.Really great rant! Much underrated.
> So maybe we need to ask fundamental questions about the compilation model and examine some beliefs we hold (For example “Compilers and build system need to be kept separated”. Do they? To what extent?).
I think you just put your finger on why Google is a monorepo - Blaze/Bazel kinda suck horribly (they feel super dated and could have been made much friendlier if they'd been designed from the ground up knowing what the pain points are, and esp if they weren't basically an ad-hoc set of new languages/syntaxes), but they're also awesome. The huge benefit is that you can make tools that work across everything and track monstrous dependency graphs.
But also languages like rust and swift and before them OCaml and Haskell show that the current prevalent C/C++ ABI is not powerful enough. And in principle, there is not much of a difference between the reason for header-only libraries in C++ and rust not having a composable ABI. It is always about the lack of information one can pass through the ABI.
Interestingly, one does not even need to exchange the definition of a rust function or that of a C++ template for monomorphisation. One could easily define an extensible library that will create the new specialisation for any given input. One would only need to "freeze" the compiler that was used to create the library and ship it with that library. Ok, easier said than done, of course.
Can complex binary interfaces be useful though?
People still write software in C. Not because it's a particularly good language but because there is a simple binary interface: symbols and calling conventions. Libraries built from this code can be used from virtually every other language. People actually rewrite stuff in C just to obtain this property.
Complex binary interfaces restrict software reusability. If it's too complex, it will be extremely difficult to build and maintain the links between programs.
Modern languages approach this problem by getting rid of the links. All code and interfaces are visible to the compiler, the resulting binary image is a perfectly optimized version of the whole program and nobody cares about the machinery the compiler outputs. Nothing else can interface with these programs though... I don't see people calling Rust functions from Python without using the C ABI.
With ELF I can take a debugger and attach it to a rust binary as well as a C++ or go binary.
Also, we want to be able to interface different languages in an efficient manner. Now with a universal executable file format that becomes possible, but requires us to have a way to combine different object files.
From here on, I think it becomes obvious that we should have compilation units. A language that does not allow the definition of such a standardized object is a bad citizen, IMO. Rust, for instance does allow it, but is severely hampered by the limitations of the C-ABI.
Additionally, I don't see how removing translation units precludes multi-language integration.
If a template function is guaranteed to be exception-safe, and it’s called with a type whose move constructor isn’t noexcept, then the function needs to fallback to the copy constructor to maintain exception-safety.
This happens a lot with the standard library.
The whole section is gold
The removal of such things seems to be driven by dogma as much as good reasons, of which there definitely are.
You could have lispish ast transforms (rust, julia, elixir) You could have comptime (zig, elixir)
both of these are far nicer than preprocessor.
Thanks for pointing me at AST transformers.
It is the only advanced tool available in C and C++, where people hate it. But for some reason Java developers are great fans (even though reflection is available), and their generators will always accept XML. It's still the first time I see a C# developer asking for it.
Read the paragraph following point 3. in the following link, and laugh or cry (your choice): https://man7.org/linux/man-pages/man3/pthread_cleanup_push.3...
Thinking in terms of strings of text instead of the abstract syntax tree is literally the roman numerals of computer science.
As an example of what I mean, in Java and C++, class properties are typically accessed by getters and setters, since you might want to change the internal structure of a class without changing the interface. In Python and C#, you can get the same benefit by changing a member variable to a property. As a result, the boilerplate of getters/setters isn't needed.
There are other things too. But thanks for the link, will read up.
Be careful what you wish for.
If it's repetitive boilerplate, you could probably use T4 to generate it for you.
Are you able to share your use-case for one in C#?