News for hackers. Stuff that matters.
Re:Why I hate all articles about design patterns (2016) by tuukkah on Monday March 05, 2018 @04:26AM (#16519810)
The runtime error can still occur... just in a different location and obscured by useless abstractions and code surrounding it.

One point of a type such as EmailAddress is that the validation is invoked at one place (inside the constructor) as opposed to an invocation at every usage site like send_email, which is a lot of work and error prone.

Another point is that when validation fails you get the runtime exception with a useful stack trace: instead of "address X was not valid when trying to send email" you actually get "you tried to convert string X to email address but it's not valid". In the first case all you can do is fail to send the message, but in the second case you can ask the user again, fix your escaping code etc.

There are no comments on this comment yet.