by billytetrud · 5y ago · 0 comments
It's also misleading in that the code is still doing validation, just in a different place.
In that sense, using types is only one way to do this, but you could model that in other ways. For example:
var foo = "123"
foo = validFoo(foo)
print(foo)
> {"value" : "123",
"valid?" : true}
And now you could have: function bar(validFoo) {
if (!validFoo.get("valid?"))
throw new InvalidInputException("Foo must be validated prior to calling bar.")
...
}Now types are a convenient way to do this that also gives you static checking for it, but I believe the idea is more to model that things were validated and expects validated input or fail.
That allows you to push all validation at the boundary, and make sure that no one ever forgets to validate the input, because if they do, the inner functions will fail reminding the caller: Please remember to validate this!