|
|
|
|
|
by cercatrova
1273 days ago
|
|
That's why I like the other TDD, type driven development. Lay out all your types and make unwanted states literally unrepresentable. For example, if you're making an email sending service, you can have an EmailAddress type that is represented underneath by a string and the only way you can instantiate a new EmailAddress is via the constructor function which will take a string, parse it and validate it as an email, and if it works, it returns the EmailAddress type, otherwise it returns None (if you're using a Result typed language). And the sender function only accepts an EmailAddress, not a string, so if your EmailAddress constructor returns None, you literally can't send the email, by design. A good video on this concept: https://www.youtube.com/watch?v=1pSH8kElmM4 |
|