5 ms·
I don't think a type system can help you with decoding a file with the wrong charset.
by BiteCode_dev 5y ago
I don't think a type system can help you with decoding a file with the wrong charset.
- pvorb 5y agoThe compiler can raise a warning about bad characters. It can't detect all problems, but it certainly can help with some. It's not the type system, but many dynamic languages are interpreted instead of compiled.
- dotancohen 5y agoThose bad characters are fed into the program long long after the compiler has done its job.
- pvorb 5y agoNot necessarily? I'm talking about constant string literals in source code which can be validated at compile time.
- morelisp 5y agoA type system can refuse to turn a `bytes` into a `utf8str` until it's been appropriately parsed. (It doesn't even need to be a very good or strongly-enforced type system - Go makes it dangerously easy to convert between `[]byte` and `string` by other-type-system standards, and yet everything works pretty well. It's enough to hitch your thinking and make you realize you need another step.)
- BiteCode_dev 5y agoHow does the type system knows the bytes are utf8 and not CP850?
- morelisp 5y agoThe same way you can parse a string into an integer and it knows you got an either[integer, err].
- deleted 5y ago[deleted]
- BiteCode_dev 5y agoSo it doesn't, and it's not about the type system. Any decode operation in python 3 raise an exception or return string. It's about the runtime error handling making it mandatory to deal with the error and won't let you panic at run time for this specific error.
- morelisp 5y agoI'm sorry you don't see exceptions as part of a type system yet.