Article 1GCYD CodeSOD: A Dated Inheritance

CodeSOD: A Dated Inheritance

by
Remy Porter
from The Daily WTF on (#1GCYD)

Teppo works for a Finnish company that, among other things, develops a few mobile applications. This company is growing, and as growing companies do, it recently purchased another company.

One of the applications that came with this company had a mongrel past. It started as an in-house project, was shipped off to a vague bunch of contractors in Serbia with no known address, then back to an intern, before being left to grow wild with anyone who had a few minutes trying to fix it.

The resulting code logs in a mixture of Serbian and Finnish. Paths and IP addresses are hard-coded in, and mostly point to third party services that have long since stopped working. It has an internal ad-framework that doesn't work. The Git repository has dozens of branches, with no indication which one actually builds the production versions of the application. The back-end server runs a cron script containing lines like this:

* * * * * curl www.google.com > ~/out.txt* * * * * echo 'lalala' > ~/out1.txt

It's a terrible application that doesn't even "barely" work. The real test, of course, for an unsupportable mess of an application is this: how does it handle dates?

public static String getSratdate_time_date(String date) { String dtStart = date; try { SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Date deals_date = format.parse(dtStart); String intMonth = (String) android.text.format.DateFormat.format( "M", deals_date); // Jan String year = (String) android.text.format.DateFormat.format( "yy", deals_date); // 2013 String day = (String) android.text.format.DateFormat.format( "dd", deals_date); // 20 return (intMonth + " / " + day); } catch (Exception e) { e.printStackTrace(); } return "";}

This takes a string containing a date and converts it into a string containing "M/dd". You may note, I used a date format string to describe what this code does, since the easiest way to write this might have been to do something like" DateFormat.format("M/dd", deals_date), which doesn't seem to be that much of a leap, since they used the DateFormat object.

Bonus points for using Hungarian notation, and triple that bonus for using it wrong.

otter-icon.png [Advertisement] Infrastructure as Code built from the start with first-class Windows functionality and an intuitive, visual user interface. Download Otter today! TheDailyWtf?d=yIl2AUoC8zAbvQ77_YTDSA
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