During code review I discovered many places of our C# code that looks like this:
if(IsValid()) {
return true;
}
else {
return false;
}
<
If you're absent-minded, it's easy to refactor some code from this:
private bool ConsiderTheOstrich()
{
/* do ostrich things */
if(someCondition && unpredictableThing == 5)
return true;
else
{
// log something
return false;
}
}
To this:
private void IsValid() { return (someCondition && unpredictableThing == 5); }
/* ... */
private void ConsiderTheOstrich()
{
/* do ostrich things */
if(IsValid())
return true;
else
return false; // ostrichlogger logs it for us now
}
Without noticing the extra opportunity for brevity.