by humanrebar · 4y ago · 0 comments
- Transpiling to C++ means it will work wherever C++ works. On any toolchain. With relatively little effort. It shouldn't be hard to add CMake and bazel support, for instance. Even mostly dumb makefiles should be workable.
- Approaching the community this way could avoid fracturing the community more than it already is.
- Targeting specific success metrics (like CVE causes) could provide focus around design and requirements
- Seems simpler and easier to learn and teach.
Cons:
- The pitch assumes C++ modules are implemented, ready to use, and reasonable accessible.
- There will be a lot of tooling to reinvent: static analyzers, syntax highlighters, etc.
- At least for a while, debugging cpp2 problems will involve juggling multiple parallel realities: cpp2 code, C++ code, and actual program behavior (i.e. compiled binaries).
- Doesn't address other major C++ ecosystem problems like build times, packaging, build systems, etc. cpp2 could make them slightly worse.
The main reason to use it in production is that it's not meant to be used in production and makes no attempt to be suitable for production use or avoid breaking changes, so the stuff in your cons list doesn't really apply. It's kind of like looking at someone's scale model of a proposed city layout and say that a pro is that tiny plastic houses are cheap to manufacture at scale but a con is that the houses may be too small to live in.
But all of your points will become relevant if cppfront eventually gets to a state where it's a serious transpiler meant to be used in production.
I will say that it's impressive how much of this has already made it into C++ language specs. But given that Sutter has chosen to release this now, I get the sense that of what remains, large portions cannot continue to simply be done that way.
Besides, the C++ community seems to overlap with academia by way of its feature updates, reveling in complexity (e.g. "C++20 ranges are totally awesome: memory-safe and performant iterators!").
He also demos error messages, and was able to get errors from a cpp compiler (msvc) that point to his cpp2 file with a line number and readable error.
This approach is similar to Rust's editions. IIUC, nearly all of the differences been editions are compartmentalized in the frontend, deprecating syntax and rewriting old edition code to rustc's current IR.
Here's the guide explaining the most significant hack:
https://doc.rust-lang.org/edition-guide/rust-2021/IntoIterat...
There was a proposal to do Editions for C++, Epochs, https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p18... but it was not accepted.
Can you explain?
The array type doesn't have an iter() method. It will coerce into a slice, which does have an iter() method, but doesn't care whether it's an array we're slicing.
As far as support in compiled libraries is concerned, that would depend on how those features are implemented in C++23 anyway.
I assume that as long as the cpp2 syntax is clean, you could improve on compile times. In theory, cpp2 files could compile much more quickly that C++, so as you migrate code to cpp2 your builds speed up?
It all depends on how well Sutter has thought through the cpp2 language design I suppose.
Big reasons people look for non-C++ solutions include better build times, dependency management, etc.
- https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p14...
- https://vector-of-bool.github.io/2019/01/27/modules-doa.html
Are there any notable new updates related to this controversy?
Imagine writing something using OpenSSL, it might look kind of weird or breaking the flow of the new syntax, just because of its legacy.
Only if you only use this Cpp2 thing. Because the C++ you write may not play nice with the C++ this transpiles into.
It also means you don't really benefit from any of the new semantics. Why do all of that static analysis work to establish safety, and then throw the results away by writing out clunky old C++? It all makes very little sense.
It's a bit more complicated than, say, typescript to JavaScript, but in spirit is not so very different, right?