4 ms·
Any sort of language that allows you to define custom types (e.g., objects) and type-hint parameters allows you to do this. You can accomplish this same thing i
by nucleardog 7y ago
Any sort of language that allows you to define custom types (e.g., objects) and type-hint parameters allows you to do this. You can accomplish this same thing in PHP even (the type checking is at runtime, but same idea).
Types are not restricted to just a description of how the data is represented in the computer, otherwise we would need nothing but primitives.
When you perform calculations with physical measurements containing units you don't simply throw away all of the type information while performing calculations -- you perform the same operations on the units both as part of the answer and as an essential check that you've done the right thing. You should do the same thing with your data.
See, e.g., https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/ https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...
- iainmerrick 7y agoYou can accomplish this same thing in PHP even Sure, you can, but the key question is, is it typically done in popular frameworks? (Maybe it is! I’m not a PHP user) I should have distinguished between Elm the language and Elm the web framework; I guess it’s really the framework I’m talking about. (the type checking is at runtime, but same idea). That’s not the same at all.
- ashearer 7y agoEven the Joel article makes what's arguably a mistake: he says that input from users is "unsafe" and must be escaped on output, while strings from elsewhere shouldn't. That may avoid security exploits, but it still results in incorrect output when a predefined value really does need to be escaped. The issue isn't whether a value originated from the user. It's the units/data type, as you said, such as plain text vs. HTML.