Ask HN: Do you follow the positive or negative pattern when programming?
Me and my coworker follow a totally different pattern while programming. Probably there are a better technical term for that, but I call it now positive pattern and negative pattern.
I prefer the following way (in controllers, etc.):
function ($param)
{
if ($param is not valid) {
return false
}
// do the stuff
return true;
}
While my coworker does the opposite: function ($param)
{
if ($param is valid) {
// do the stuff
return true;
}
return false
}
We agreed that none of them is good or wrong, just different approach. I am curious, how do you do, what are your thoughts, pros and cons?