Article 5E22Y CodeSOD: Self Improvement in Stages

CodeSOD: Self Improvement in Stages

by
Remy Porter
from The Daily WTF on (#5E22Y)

Jake has a co-worker named "Eddie". Eddie is the kind of person who is always hoping to change and get better. They're gonna start eating healthier... after the holidays. They're gonna start doing test driven development... on the next project. They'll stop just copying and pasting code... someday.

At least, that's what we can get from this blob of code.

//TODO make this recursive, copy paste works for now thoughif (website_description != null) { if (website_description.length() > 25) { int i = website_description.indexOf(" ", 20); if (i != -1) { String firstsplit = website_description.substring(0, i); String secondsplit = website_description.substring(i); websiteWrapped = firstsplit + "<br/>" + secondsplit; if (secondsplit.length() > 25){ int split_two = secondsplit.indexOf(" ", 20); String part1 = secondsplit.substring(0, split_two); String part2 = secondsplit.substring(split_two); websiteWrapped = firstsplit + "<br/>" + part1 + "<br/>" + part2; if (part2.length() > 25){ int split_three = part2.indexOf(" ", 20); String part3 = part2.substring(0, split_three); String part4 = part2.substring(split_three); websiteWrapped = firstsplit + "<br/>" + part1 + "<br/>" + part3 + "<br/>" + part4; if (part4.length() > 25){ int split_four = part4.indexOf(" ", 20); String part5 = part4.substring(0, split_four); String part6 = part4.substring(split_four); websiteWrapped = firstsplit + "<br/>" + part1 + "<br/>" + part3 + "<br/>" + part5+ "<br/>" + part6; if (part6.length() > 25){ int split_five = part6.indexOf(" ", 20); String part7 = part6.substring(0, split_five); String part8 = part6.substring(split_five); websiteWrapped = firstsplit + "<br/>" + part1 + "<br/>" + part3 + "<br/>" + part5+ "<br/>" + part7+ "<br/>" + part8; if (part8.length() > 25){ int split_six = part8.indexOf(" ", 20); String part9 = part8.substring(0, split_six); String part10 = part8.substring(split_six); websiteWrapped = firstsplit + "<br/>" + part1 + "<br/>" + part3 + "<br/>" + part5+ "<br/>" + part7+ "<br/>" + part9+ "<br/>" + part10; if (part10.length() > 25){ int split_seven = part10.indexOf(" ", 20); String part11 = part10.substring(0, split_seven); String part12 = part10.substring(split_seven); websiteWrapped = firstsplit + "<br/>" + part1 + "<br/>" + part3 + "<br/>" + part5+ "<br/>" + part7+ "<br/>" + part9+ "<br/>" + part11+ "<br/>"+ part12; } } } } } } } else { websiteWrapped = website_description; } } else { websiteWrapped = website_description; }}

It is, of course, the comment which makes this sample: //TODO make this recursive, copy paste works for now though. But I would argue that recursion wouldn't actually help that much, not if we're gonna keep building every string via string concatenation.

I'm sure the comment is accurate: it works for now. I'm afraid, though, that it's probably going to keep working like this for a much, much longer period of time.

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today! TheDailyWtf?d=yIl2AUoC8zAEWW8Vy2FFPM
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