News for hackers. Stuff that matters.
Re:A quest for safe text formatting API by smasher164 on Saturday June 19, 2021 @11:38PM (#27566882)
Should mention type-safe printf in dependently-typed languages like Idris[0] or F*[1]:

[0]: https://zgcoder.net/ramblings/typesafe-printf/ [1]: https://fstarlang.github.io/general/2017/11/23/sprintfstar.h...

Re:A quest for safe text formatting API by tyingq on Saturday June 19, 2021 @10:27PM (#27566559)
"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.

Re:A quest for safe text formatting API by flakiness on Saturday June 19, 2021 @11:26PM (#27566837)
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

Re:A quest for safe text formatting API by TinkersW on Sunday June 20, 2021 @03:44AM (#27568003)
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.

Re:A quest for safe text formatting API by flakiness on Sunday June 20, 2021 @08:35AM (#27569390)
That's good to know. I think I have a fight-or-flight response for every C++ new features :-/
Re:A quest for safe text formatting API by dnautics on Sunday June 20, 2021 @12:55AM (#27567196)
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
Re:A quest for safe text formatting API by juloo on Sunday June 20, 2021 @05:48AM (#27568556)
Printf is type-safe in Haskell and OCaml. The format-string is not a regular string, it must be literal and is type-checked specifically.
Re:A quest for safe text formatting API by tome on Sunday June 20, 2021 @06:00AM (#27568620)
Which printf in Haskell are you thinking of? This one doesn't fit your description, for example:

https://www.stackage.org/haddock/lts-18.0/base-4.14.1.0/Text...

Re:A quest for safe text formatting API by havermeyer on Sunday June 20, 2021 @09:56AM (#27569992)
absl::StrFormat provides compile-time safety: https://abseil.io/docs/cpp/guides/format