stevedoria.net

Scratching your head doesn't make it work any better. It only loosens unsightly dandruff.

Explicitly Redundant

Today, I caught myself doing this:

bool f()
{
  bool r;
  if( x == y )
  {
    r = true;
  }
  else
  {
    r = false;
  }

  return r;
}

When I really should have written:

bool f()
{
  return x == y;
}

In the actual code I that I was writing, x and y were functions or fields that used multiple member access operators. I do not remember why I wrapped this boolean expression into a function, but when I caught myself doing the former, it was like smelling a strong stench.

Leave a Reply