3 ms·
For those curious, the way one would do this in a language with a better type system (or objects) would be some sort of opaque object/type which you can't peer
by gwern 15y ago
For those curious, the way one would do this in a language with a better type system (or objects) would be some sort of opaque object/type which you can't peer into, and which provides a function/method to extract the String within and which also sanitizes it along the way.
So for Java, you might have a class with the String stored as a private variable and the obvious getter/setter methods. In Haskell, you'd have a newtype with similar functions. (Can this be done in C? I don't know.)
A close approximation to Joel's example (string sanitation) in Haskell with newtypes: http://blog.moertel.com/articles/2006/10/18/a-type-based-solution-to-the-strings-problem http://blog.moertel.com/articles/2006/10/18/a-type-based-sol...