Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I find the validation topic very interesting in general. In my opinion option 2 (returning a special value) is not a good one, since you are forcing the client to do if/case to check for the returned value and that code must be repeated everywhere. Also, unlike exceptions that propagate through the calling stack, in this scenario the caller is almost always the one that has to handle that special value.</p> <p>In the context of OOP raising an exception or having an assertion is, IMO, a more elegant way to cope with it. However i find that inlining verification code in every method doesn't scale well for some reasons:</p> <ul> <li>Many times your validation logic ends up being greater than the method logic itself, so you end up cluttering your code with things that are not entirely relevant to it.</li> <li>There is no proper validation code reuse (e.g. range validation, e-mail validation, etc).</li> <li>This one depends on your tastes, but you will be doing <a href="http://en.wikipedia.org/wiki/Defensive_programming" rel="nofollow">defensive programming</a>.</li> </ul> <p>Some years ago I attended to a talk about validators (a similar talk slide's are <a href="http://csl.ensm-douai.fr/Esug2007Media/uploads/1/Extreme.pdf" rel="nofollow">here</a>. The document explaining it used to be in <a href="http://www.caesarsystems.com/resources/caesarsystems/files/Extreme_Validation.pdf" rel="nofollow">http://www.caesarsystems.com/resources/caesarsystems/files/Extreme_Validation.pdf</a> but now its a 404 :( ) and totally like the concept. IMHO having a validation framework that adopts the OO philosophy is the way to go. In case you want to read about it I've written a couple of posts about it <a href="http://research.quanbit.com/2012/10/09/about-oop-validation/" rel="nofollow">here</a> and <a href="http://research.quanbit.com/2012/11/05/discussing-validators-and-related-concepts/" rel="nofollow">here</a> (disclaimer: the posts are part of the blog of the company I work for).</p> <p>HTH</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload