Can you say WTF?
The following post was inspired by the following site: The Daily WTF
During a quick review of some legacy code today, I stumbled upon this gem of a method. I can't believe how many different ways this design, or lack thereof, gets under my skin. All comments were sprinkled in for demonstration purposes only. All javadoc that existed(none) is not shown to protect the guilty.
1:// by the method name, would you expect the return value to be a boolean?
2:// Also, way to pass in a Date as a string and also the format. Passing
3:// in a simple date would have been a bit too convenient
4:private boolean dateDifference(String fillDate, String format) {
5:
6: boolean result = false;
7: try {
8: Date current = new Date();
9: SimpleDateFormat sd = new SimpleDateFormat(format);
10: Date filldate = sd.parse(fillDate);
11: if (current.compareTo(filldate) > 0) {
12: double msdiff = (current.getTime() - filldate.getTime());
13: // for those of you that don't know, this value is the meaning of Life,
14: // the Universe, and Everything. Or was that 42. I forget.
15: double msd = 3888000000.00;
16: if (msdiff <= msd) {
17: result = true;
18: }
19: }
20: } catch (ParseException e) {
21: //Excellent Handling of Exceptional cases :)
22: logger.error("ParseException while getting the dateDifference " + e.getMessage());
23: }
24:
25: return result;
26:}