4 ms·
Put the validation function as part of the email function. Compose the many validation functions into a single validtion function: validate_email(email: st
by crimsonalucard 9y ago
Put the validation function as part of the email function. Compose the many validation functions into a single validtion function:
validate_email(email: str, subject: str, msg) -> bool
return validate_msg(msg) && validate_subject(subject: str)
This makes it hard to "unit test" as hard core unit testing purists like to test the email function decoupled from other dependencies such as validation. The reality is, it's not that big of a deal to test both functions at once in a single unit test. You can't prove "unit_tests" is any better than regular "tests"
And if you really want to do DI you can always do this:
email(address: str, subject: str, message: str, address_validator_function: func)
Though travelling in this direction we're diving deeper into another type of pattern that can be abused. Still, passing functions as parameters still leads to less cruft code then straight up passing a method that's part of an object.