Article 5KANQ CodeSOD: Classic WTF: The Great Code Spawn

CodeSOD: Classic WTF: The Great Code Spawn

by
Alex Papadimoulis
from The Daily WTF on (#5KANQ)
We're taking a little summer break this week for our regular articles. Since we're re-using articles, let's start with one about developer efficiency. Why write code when you can automate writing code? Original -- Remy

Several years ago, Dan D's predecessor, Steve, came to the realization that many of us arrived at one point or another: writing data-access code can get boring and repetitive. To ease the tedium, Steve did what many developers in his position do. He wrote some code to generate a lot of code.

Unfortunately, Steve's coding skills weren't all too hot. Worse were his code-writing-code writing skills. In the years since The Great Code Spawn (as it has come to be known), the data-access layer has become an unmaintainable disaster - so much so that, rather than add a new database column, developers have split" single fields into multiple through bit-shifting and string manipulation.

Following is a single line of code (re-formatted by yours truly) that represents one of the smaller" insert statements.

new OdbcCommand(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append(new StringBuffer() .append("Insert into wc_scanbol values(") .append(num) .ToString()) .append(",'") .ToString()) .append(bol.BolNum) .ToString()) .append("',") .ToString()) .append(Integer.parseInt(bol.get_ShipDate().ToString("yyyyMMdd"))) .ToString()) .append(",") .ToString()) .append(bol.Period).ToString()) .append(",'") .ToString()) .append(bol.Consignee.Replace("'", "''")) .ToString()) .append("',") .ToString()) .append(bol.Cases) .ToString()) .append(",") .ToString()) .append(bol.Bottles) .ToString()) .append(",") .ToString()) .append(num).ToString()) .append(",") .ToString()) .append(bol.CustID) .ToString()) .append(",'") .ToString()) .append(bol.State) .ToString()) .append("','')") .ToString(), this.con) .ExecuteNonQuery();
proget-icon.png [Advertisement] ProGet's got you covered with security and access controls on your NuGet feeds. Learn more. TheDailyWtf?d=yIl2AUoC8zANJx92KQ8TBg
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