Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Tests are good but moving left by lifting invariants into the type system is better.

Compare

   fn send_email(addr: &str, subject: &str, body: &str) -> Result<()>
to

    fn send_email(add: &EmailAddr, subject: &str, body: &str) -> Result<()>
In the second case, the edge cases of an empty or invalid email address don't need to be tested, they are statically impossible.


Thanks for the small concrete example. I try to explain this a lot. It also makes coverage really easy to get with fewer tests.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: