Article 34Q99 Representative Line: Refactoring the Conditional

Representative Line: Refactoring the Conditional

by
Remy Porter
from The Daily WTF on (#34Q99)

Virginia N was trying to refactor some code, and that meant understanding where the value m_PSOC_SIG was used, and why. So, she did some searching, and found this line, which doesn't contain our value:

ChangePosition("P",true,(bool)ar[6],(DateTime)ar[1],(DateTime)ar[5]);

Now, you might be asking yourself, "what's the problem?"

Well, let's put this into a little context. You're probably familiar with the "do the same thing on both branches" if statement, like this:

 if (m_ProgEnt.SAFF_SIG==m_PSOC_SIG) { ChangePosition("P",true,(bool)ar[6],(DateTime)ar[1],(DateTime)ar[5]); } else { ChangePosition("P",true,(bool)ar[6], (DateTime)ar[1], (DateTime)ar[5]); }

Now, that's annoying, but it's not a full-on WTF. It's the sort of thing that probably just accrues in old code-bases, the gradual decay of good- well, not godawful- code into bad by changing requirements and rushed timelines. Once upon a time, the branches probably were different. But neither of those are the line I posted above. Here's the full code in context:

if (m_ProgEnt!=null){ if (m_ProgEnt.SAFF_SIG==m_PSOC_SIG) { ChangePosition("P",true,(bool)ar[6],(DateTime)ar[1],(DateTime)ar[5]); } else { ChangePosition("P",true,(bool)ar[6], (DateTime)ar[1], (DateTime)ar[5]); }}else{}ChangePosition("P",true,(bool)ar[6],(DateTime)ar[1],(DateTime)ar[5]);

Virginia removed the conditionals.

release50.png[Advertisement] Release!is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped! TheDailyWtf?d=yIl2AUoC8zANTcDg7dskmM
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments