Mutually Exclusive Events Style Question

What is your all preferences regarding the following:

1
2
3
if (condition1)
   return true;
else return false;


or:

1
2
3
if (condition1)
   return true;
return false;


which do you prefer and why?
I prefer the second one. I never did think of why, but I guess it just looks cleaner to me.
I prefer return condition1;
In other, similar cases I often omit the else unless I think it improves the reading flow in the case at hand.
Actually, I'm with Athar. I was assuming there would be some code between if(condition1) and return true.
Yeah, I'd prefer the second one.
In that case, there's no actual reason to have an else statement. Sure it makes more logical sense to have an else included, but if you don't need it, why generate the extra code?
Last edited on
The second one. Its quicker to deduce. And I think it makes sense that there should always be a non-conditional return.
I don't know if you guys had thought about it but mutually exclusive events may be obvious to some, but the more complex the logic the harder it may be to see if a certain set of statesments are or are not mutually exclusive. So i was wondering if there is a guiding principle when it comes to writing readable code()?
I like to think about how other people will modify the code at some future time and try to make their life as easy as possible.
Agreed with Galik.
Make your variable names clear and detailed as possible. Don't call a vector of strings holding student names 'x', refrain from unmanaged infinite loops, yada-yada. And comment the crap out of everything. That's what i do.
Topic archived. No new replies allowed.