5 ms·
With reflection and code generation coming to C++26, and the already existing constexpr/consteval machinery, C++ will be able to do all of this.
by HeliumHydride 2y ago
With reflection and code generation coming to C++26, and the already existing constexpr/consteval machinery, C++ will be able to do all of this.
- dwattttt 2y agoBash scripts and (optionally) an assembler can do this. That's not really the point.
- pipeline_peak 2y ago> Bash scripts and (optionally) an assembler What do you mean by that ?
- dwattttt 2y agoIn much the same way as "being Turing complete means you can do anything", it just being possible to do compile-time execution isn't the reason Zig is exciting here. C++ adding the same features means it'll be possible, but it has a much larger intersection of alternative features to introduce edge cases with, and _many_ implementations that will have this feature with varying quirks: all of this means C++ will have to do a _much_ better job than Zig does here to achieve nearly the same result.
- rowbin 2y agoThanks for that. I loathe replys like "but lang/framework/... can do/will be able to do something similar/does something else which I like better/...". Well, it's not about that. It's about how easy it is to use, how good it is from preventing you to shoot yourself in the foot, sometimes how performant it is, ...
- benatkin 2y agoIt's suggesting that Zig is convenient and that C/C++ won't be. I think both will be nice.
- carlos22 2y agoWell C++ has a history of not really being convenient and makes it easy to shoot you in the foot.
- logicchains 2y agoThat's something different, code generation. The point is that C++26 will have compile-time reflection without any need for an external code generation tool, similar to Zig.
- kstrauser 2y agoWith the main difference being that if you start Zig today, you’ll get to use that a good decade before it’s reliably available in C++. Hmm. Actually, now that makes me want to learn Zig.
- kevin_thibedeau 2y agoConsteval is usable today for a lot of scenarios that would require code generation tooling in years past.
- dwattttt 2y agoHow does consteval interact with thread_local? Defined (although I'm not sure what definition could make sense), error, or the dreaded "No diagnostic required"?
- flohofwoe 2y agoIn the end, generics, comptime and code generation are just different steps on the 'stamping out specialized code and data' ladder though (e.g. all three are useful).
- int_19h 2y agoErgonomics matters, though. In C++, this feature is bolted onto the language decades after it was originally designed. Zig is designed around this from the get go (which is why it doesn't have e.g. templates as a distinct feature).
- edflsafoiewq 2y agocomptime simplifies and unifies much of that machinery into a clean, conceptual framework.
- rochak 2y agoGood. Keep on adding stuff to an already bloated language.
- logicchains 2y agoCompile-time reflection will remove countless of lines of bloat from real C++ code bases due to eliminating the need to manually write formatting, hashing and serialisation implementations for classes.
- riwsky 2y ago…10 years from now
- fredrikholm 2y agoIf not more; the words "modern" and "C++11" are still used in conjunction despite the fact that 2014 was a long time ago.
- pjmlp 2y agoAll programming languages either die, or become bloated, as any software product. I bet a Fortran 77 developer will think the same of Fortran 2023, a COBOL 60 developer of COBOL 2023, a K&R C developer from C23, a 1975 Scheme developer from R7RS, a Python 1.0 developer from Python 3.13,... even Go 1.0 developers from 1.24 with generics, generators,...
- tialaramex 2y agoOne trick that can help you here is Rust's Editions (and the proposed but never implemented C++ Epochs). This lets the language throw away bad ideas, without throwing away the code people wrote in the era when we didn't realise that's a bad idea.
- pjmlp 2y agoKind of, because epochs only cover grammar changes and some kinds of semantic changes. It doesn't cover standard library, scenarios with binary libraries doing cross calls across epochs and several others. I still don't see it any different from a language version switch like in many other languages, specially in JVM and .NET ecosystem.
- brabel 2y agoThe examples in thist post seem very similar to how you do metaprogramming in the D language. That has existed for years yet you rarely hear about that.
- pjmlp 2y agoWith a much better ecosystem, 40 years of IDE tooling, frameworks, OS support. Which is what people always forget when comparing language grammars.
- 9dev 2y agoI'm not sure if you actually want to call "copy these header files into your local file system" an ecosystem at all. The last 40 years have brought heaps of improvements in software development ergonomics. Zig is growing just fine, as other languages like Rust or Go.
- pjmlp 2y agoThat is what script kiddies do when using compiled languages. Rust has had an almost usable implementation for affine types, and being the second coming of Ada, to win the hearths of the industry, including all major OS vendors and hyperscallers. Go got lucky with Docker and Kubernetes rewrites, and their adoption across the industry. So far Zig is basically Modula-2 with C like syntax, and compile time execution, relies on the same tooling that C and C++ have had for decades for use-after-free, doesn't support a binary libraries ecosystem by design, and really Bun isn't going to be the killer project that triggers a Rewrite in Zig movement. It remains to be seen if Zig 1.0 happens, and how its adoption story at scale will be like.
- vkazanov 2y agoI agree that zig is taking too long to be finalised. And rust has made certain questionable life choices. But people really, REALLY want to get off c and c++ for all the numerous reasons everybody knows.
- pjmlp 2y agoThey might want, yet while Khronos keeps publishing standards using C and C++, GCC/LLVM/CUDA/.NET/Java/V8/Metal make use of C++, Nintendo/PlayStation/XBox rely on C++, ... they are going to stay around no matter what.
- katzenversteher 2y agoReminds me of "Der Untergang". Mit dem Angriff C++26 wird das alles in Ordnung kommen!
- flohofwoe 2y agoC++ could do generic programming long before Zig even was an idea, but writing generic code in Zig is still much more straightforward - also Zig is usable now, while C++26 features will probably land in real world C++ compilers around 2036 ;)