2 ms·
It seems like the ability to declare a parameter to be a constant string (no runtime computation allowed) would have been useful here, or in any printf-like API
by skybrian 5y ago
It seems like the ability to declare a parameter to be a constant string (no runtime computation allowed) would have been useful here, or in any printf-like API. If you really want to do that, it could be using a different function.
- ericbarrett 5y agoI think Go's log package, and similar, have the best take on this: log.Print(fixed_string) log.Printf(format_string, args...) Simple, unambiguous.
- skybrian 5y agoWell, almost. If you change Print with one argument to Printf, the compiler doesn’t complain. Maybe lint or vet will warn about it. If it were a special type then the compiler could do it.
- rixed 5y agoJust for the record, it is possible to type check format strings with regard to their actual arguments. OCaml does this, for instance, probably since its inception ~30 years ago or so.