Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

12
  • 1
    Can't argue with 22.8K rep... My issue was that first we are told to decouple, decouple, decouple, and separate validation logic from data model and then you see this kind of code from people with years of experience doing the opposite and you just get so confused Commented Aug 29, 2013 at 13:22
  • 16
    @iAteABug_And_iLiked_it - No, by all means you should argue with me if you think I'm wrong. And in general, you should go nuts with decoupling - but there's always some line where you need to stop or else you end up with classes that have only one variable making your code completely unusable. That line is a trade off, and one you'll be able to guess more accurately with experience. If you're light on experience, err towards more decoupling. Commented Aug 29, 2013 at 13:30
  • 2
    While I agree that this is pretty standard and possibly good enough (in the "we've got bigger problems elsewhere" kind of way), it's still not particularly pretty. It's not DRY (e.g. one or two classes down the line I'd get irritated that child object's validations have to be manually merged in, with the same code each time), encourages monolithic methods (with high cyclomatic complexity), has a low signal to noise ratio, etc. To be fair, the book might later on refactor some of it into a more generic form. Commented Aug 29, 2013 at 13:52
  • 2
    @iAteABug_And_iLiked_it you can always argue with rep. Simply accepting an argument because of rep is the "Argument from authority" logical fallacy (en.wikipedia.org/wiki/Argument_from_authority). Aristotle had (and still has) huge rep but that doesn't mean that vultures are impregnated by the wind. Not saying Aristotle was a rep-whore, of course ;) Commented Aug 29, 2013 at 14:34
  • 1
    I'm not that bright; I missed that this was a model with validation, I read the code snippet as an operational method that validated it's arguments. +1 this is the right approach. Commented Aug 29, 2013 at 14:40