The Daily Parker

Politics, Weather, Photography, and the Dog

Hunting wabbits

(By way of explanation why I'm being wery wery qwiet today.)

Actually, I'm hunting financial accounting (Duke) and bugs (client). Like this one, which shows one of the perils of refactoring. See if you can spot my stupidity:

Original code

private void OldMethod
{
   bool canChangeThing =
   (
      _isCompany |
      _isClient &
      (
         someConditionA == true |
         someConditionB == true
      )
   );

   if (canChangeThing) 
   { 
      // do stuff 
   }
}

Refactored code

private bool CanChangeThing
{
   get
   {
      return (
         _isCompany |
         _isClient &
         !(null == _thing) &&
      	(
            someConditionA == true |
            someConditionB == true
         )
      );
   }
}

private void OldMethod
{
   if (CanChangeThing) 
   { 
      // do stuff 
   }
}

Fixed bug

private bool CanChangeThing
{
   get
   {
      return (
         _isCompany |
         (_isClient &
            !(null == _thing) &&
            (
               someConditionA == true |
               someConditionB == true
            )
         )
      );
   }
}

private void OldMethod
{
   if (CanChangeThing) 
   { 
      // do stuff 
   }
}

The sound you hear is me hitting my head on my desk until it stops hurting.

Comments are closed