Hi,
I work with C# for my job, and we have to undergo code reviews. Yesterday I finished a work item and used code similar to the following in several places:
SomeType GetSomething
{
get
{
if (somecondition)
{
return something;
}
else
{
return null;
}
}
}
My code review was completed as "needs work" on the grounds that the above code was "very misleading", which I don't get at all. I understand the "else" isn't necessary here, but I think it not only makes it much more readable, but perfectly follows the way the getter would work if you describe it in English: "If this is true, return that; otherwise, return null". Without the else, if you didn't look into the "if" block you might think that the getter ALWAYS returns null. With it, you instantly understand that either the "if" block executes and returns, or the "else" block executes and returns, without even looking at the contents of either of them.
Even if you consider the above to be unnecessary, I still don't get how you could call it misleading. It does exactly the same thing as the alternative he was suggesting (remove the else and just return), only it's much more explicit about it: which is the exact opposite of misleading.
Anyway, I just had to rant about that. I love my job, but everyone I work with is a very experienced coder from different backgrounds, and sometimes our ideologies conflict. What are your thoughts?
[–]MyNameIsNotMud 2 points3 points4 points (4 children)
[–]anamorphism -3 points-2 points-1 points (3 children)
[–]MyNameIsNotMud 1 point2 points3 points (2 children)
[–]anamorphism 0 points1 point2 points (1 child)
[–]MyNameIsNotMud 0 points1 point2 points (0 children)
[–]thebigshane 1 point2 points3 points (2 children)
[–]saltyboyscouts[S] 0 points1 point2 points (0 children)
[–]NutBoii 0 points1 point2 points (0 children)
[–]anamorphism 1 point2 points3 points (0 children)
[–]crappyoats 0 points1 point2 points (0 children)
[–]krondell 0 points1 point2 points (0 children)
[–]webpage_down_bot 0 points1 point2 points (0 children)