Article 466CB CodeSOD: Is Num? I'm Numb

CodeSOD: Is Num? I'm Numb

by
Remy Porter
from The Daily WTF on (#466CB)

"The hurrider I go, the behinder I get," is one of the phrases I like to trot out any time a project schedule slips and a PHB or PM decides the solution is either crunch or throwing more bodies at the project.

Karl had one of those bosses, and ended up in the deep end of crunch. Of course, when that happens, mistakes happen, and everything gets further behind, or you're left with a mountain of technical debt because you forgot that Integer.TryParse was a function in C#.

Which is what happened to Karl. And that's why Karl wrote" this.

private static bool IsNum(string num){ for (int i = 0; i < num.Length; i++) { for (int j = 0; j <= 10; j++) { if (j == 10) return false; if (num.Substring(i, 1) == j.ToString()) break; } } return true;}

This is an impressive brain-fart. Nested loops, multiple escape clauses from the inner loop which return control to different places. All the calls to Substring and ToString.

Unfortunately for Karl, this code shipped, and unless there are any show stopping bugs, none of the existing code is ever to be touched again. Everyone should be focused on writing new features for the next release.

raygun50.png [Advertisement] Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps - Think Raygun! Installs in minutes. Learn more. TheDailyWtf?d=yIl2AUoC8zAuMrNnoQZ4SE
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