Article 6SZ3B CodeSOD: A Little Extra Padding

CodeSOD: A Little Extra Padding

by
Remy Porter
from The Daily WTF on (#6SZ3B)

Today's anonymous submitter supplies us with a classic antipattern: padding via switch:

string TransactionOrder = (string)dr["TransactionOrder"].ToString().Trim();switch (TransactionOrder.Length){ case 1: TransactionOrder = "000" + TransactionOrder; break; case 2: TransactionOrder = "00" + TransactionOrder; break; case 3: TransactionOrder = "0" + TransactionOrder; break; default: TransactionOrder = TransactionOrder; break;}

There's not much to say here, as we've seen this before, and we'll see it again. It's wrong, it's not how anything should be done, yet here it is, yet again. In this case, it's C#, which also has a lovely set of built-in options for doing this, making this code totally unnecessary.

proget-icon.png [Advertisement] ProGet's got you covered with security and access controls on your NuGet feeds. Learn more.
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