7 ms·
I see the keyword as a feature, not a crutch ;) It guarantees that this area of code will always be evaluated at comptime, and otherwise fail to compile. Compi
by flohofwoe 2y ago
I see the keyword as a feature, not a crutch ;)
It guarantees that this area of code will always be evaluated at comptime, and otherwise fail to compile. Compilers (or rather their optimizer passes I guess) already try to fold a lot of code into a constant if it can be evaluated at compile time, but it will silently fall back to runtime evaluation when a variable slips into the code later. With a keyword I can at least say "please fail when that happens".
- WalterBright 2y agoD guarantees that code that is an implementation of a constant-expression is evaluated at compile time. There really is no purpose to adding a keyword.
- drjeats 2y agoIn the most common cases, Zig does exactly what D does here as well. Constant expressions are folded at compile time like any reasonable systems language. It's akin to writing C++ where you slap constexpr on everything. Zig agrees with D that constexpr is silly :) The one thing is Zig doesn't have D's notion of function purity, so I suspect there are cases where D could either infer that an expression is const where Zig can't, or at the very least D's compiler could do it faster. Not to dismiss D's contributions to systems programming languages, of course. Clearly a ton of inspiration of being pulled from y'all's work.