10 comments

[ 5.1 ms ] story [ 29.7 ms ] thread
"Formatting facilities in languages other than C are usually type-safe. For example, in Python you get an exception when trying to format a string as an integer"

Seems like that section could use more examples. A fair amount of dynamic languages won't bomb if you try to format a string as a number with their s/printf equivalent. They coerce the string into a number, with sometimes unexpected (though documented) results. Perl, PHP, and awk all do this.

First heard about consteval. This is cool, but every time C++ adds new and obscure features like this I cannot stop feeling helpless. Rust-like macros are fine, and old languages like Java have linter checks that provides type safety to the format string [1].

Aren't these enough? Apparently no.

There could be a world where people stick with this kind of "pragmatic" solution and stay away from without doing spec-puzzle-solving. C++ is not that world and I've accepted that, but let's make sure the other side holds the majority vote.

[1] https://errorprone.info/bugpattern/FormatString

consteval isn't really obscure or confusing, it does more or less what you would expect based on the name.

There are plenty of esoterically templates shenanigans in C++ but this isn't one of them.

That's good to know. I think I have a fight-or-flight response for every C++ new features :-/
Zig's std.fmt is pretty fantastic doing compile-time type resolution, and has an API used across many parts of the zig std library