Re:The type system is a programmer's best friend
by Ygg2 on Saturday November 05, 2022 @09:27AM
(#33481257)
> It's a very related problem.
It's not. You have the same problem regardless of type you place there.
> A string is a wrong model for an email address. But it's a pretty useful one.
Depends on use case. Perhaps it's an overkill in this toy example.
I've real life use cases with untrusted user input where having raw string as untrusted and some kind of verified type as trusted would eliminate whole swath of errors.
I agree: All models are wrong; some are useful.
A string is a wrong model for an email address. But it's a pretty useful one.
A custom type sitting lonely in an isolated codebase IS ALSO A WRONG MODEL. Arguably, it might be more a useful one than a string. But that's debatable.
And on that debate, I'll argue a string is a better model because it is a better UNDERSTOOD model by more PEOPLE than whatever MyEmailClassForThisProject you just came up with.