3 ms·
I don't want to start a war. I'm neither an expert programmer nor a smart person. But isn't it better to put data and validation all together? What if someone f
by majidazimi 9y ago
I don't want to start a war. I'm neither an expert programmer nor a smart person. But isn't it better to put data and validation all together? What if someone forgets to call the validation function? I mean in some complex projects, there may be tens of those validation functions that need to called, probably in a special sequence.
- crimsonalucard 9y agoPut 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.