Can Types Replace Validation?
blog.ploeh.dk
Can Types Replace Validation?
1–10 of 35 posts
Re: Can Types Replace Validation?
#2Re: Can Types Replace Validation?
#3You prove that a string originating from the user was HTML escaped - by calling the HTMLEscape function which attaches the proof - and then later in the code whenever you output it in the template it won't be escaped anymore because it's proven to be escaped.
Re: Can Types Replace Validation?
#4Another interesting idea I've read, I think in a Haskell context, is proofs attached to values. You prove that a string originating from the user was HTML escaped - by calling the HTMLEscape function which attaches the proof - and then later in the code whenever you output it in the template it won't be escaped anymore because it's proven to be escaped.
I don't understand why I find this stuff fascinating.
https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspon...
Re: Can Types Replace Validation?
#5Re: Can Types Replace Validation?
#6Re: Can Types Replace Validation?
#7Granted, the python typing system is very limited, and to get complete validation, you'll need more than types as python type hints can't express complex rules.
Also, as the articles mentions, the validation will occur at runtime, it can't in any way make sure the program is valid from mypy checks alone.
Still, it's really nice to define your input data types and contraints in one go.
Re: Can Types Replace Validation?
#8Re: Can Types Replace Validation?
#9But it comes very very close: https://blog.hediet.de/post/how-to-stress-the-csharp-compile...
Re: Can Types Replace Validation?
#10> Normal type systems (like C#'s) aren't Turing-complete. But it comes very very close: https://blog.hediet.de/post/how-to-stress-the-csharp-compile...