4 ms·
The problem has nothing to do with objects. The problem is, how do you type check something like sprintf without ad hoc type rules?
by toxik 3y ago
The problem has nothing to do with objects. The problem is, how do you type check something like sprintf without ad hoc type rules?
- __ryan__ 3y agoI don’t think I’m following well enough to provide a meaningful response. This is not meant as an argument against what you’re saying, because I know you were just giving an example, but I found this and thought you may find it interesting: https://www.hacklewayne.com/a-truly-strongly-typed-printf-in-typescript https://www.hacklewayne.com/a-truly-strongly-typed-printf-in...
- jitl 3y agoTypescript can check sprintf though using template string types: https://www.hacklewayne.com/a-truly-strongly-typed-printf-in-typescript https://www.hacklewayne.com/a-truly-strongly-typed-printf-in...
- nine_k 3y agoMeanwhile, both Rust [1] and Haskell [2] manage to implement statically type-safe string interpolation. [1]: https://willcrichton.net/notes/type-safe-printf/ https://willcrichton.net/notes/type-safe-printf/ [2]: https://hackage.haskell.org/package/formatting https://hackage.haskell.org/package/formatting
- Spivak 3y agoYes but the Rust example is an ad hoc type rule implemented behind the macro. You can make it type-safe but you lose the ability to have a formatting language in the string itself.
- mirekrusin 3y agoRust has explicit support for it in the compiler, which is not great. Zig does it the right way - it's defined in zig itself, no special cases in compiler like in Rust.