3 ms·
> Is there any language that separates the concept of a string and a user-facing string? Not quite, but Nim has a concept of a tainted string, which comes from
by captainmuon 10y ago
> Is there any language that separates the concept of a string and a user-facing string?
Not quite, but Nim has a concept of a tainted string, which comes from outside your (web) application and has to be escaped or explicitly casted into a regular string (the Python web framework Django has something similar). You could use the same mechanism of "distinct types" to create a user facing string vs an internal string if you want. I used this in a little Unicode related experiment to create a number-of-bytes and number-of-chars type, and made my strings take these as index, so I would never confuse them. Pretty neat language feature I thought.
- hoytech 10y agoFYI: According to wikipedia: "Perl supported tainting from at least 1989 as the -T switch was included in Perl 3." https://en.wikipedia.org/wiki/Taint_checking https://en.wikipedia.org/wiki/Taint_checking
- captainmuon 10y agoYeah, I had a hunch that the concept goes back a bit :-) Nim does have something new though, its "distinct" types are more general than just tainted strings, and can be used whenever you have the same raw data type, but different meaning (and want the compiler to prevent accidential mixing). Of course, Haskellers will say that's old and boring...