- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The resulting single line of code has two bugs.
1. When date1 is greater than date2, it returns a positive value rather than zero.
2. When date2 is greater than date1, it returns a negative value instead of a positive one, although they should have the same magnitude.
So, uhm. Maybe try harder next time?
Admin
Touché!
Admin
They must have been getting paid by the line...imagine the code they must have used to establish the date in the first place...
Admin
I almost wrote something like this, trying to get a UNIX timestamp from a date in AppleScript. However you can just subtract "jan 1 1970 12:00 AM" from a date to get it. Nifty.
Admin
Am I the only one who really enjoys this code pattern?
<font face="Courier New">if(condA || condB) {
if(condA) {
}
if(condB) {
}
}</font>
Admin
Sadly? You think such people should reproduce?
Admin
If the language supports subtracting Date objects from each other, I do hope it also supports arrays.
You know, arrays. Useful variables for storing multiple fields of data without having to resort to int values and multiply the data fields by powers of ten to keep them separate.
I did something comparable to year10000+month100+day on my first day of learning Java. It's one of those ideas that look brillant while you're implementing them.
Admin
Emmm,
short isValidDate[99991232];
This uses 192Mb of memory when it is populated..... I think I prefer the original WTF
(unless you were joking, which I think you were :)
Admin
Or you could have the dubious pleasure of programming Eiffel where there is no return statement, you have to set a variable call Result to return a value. I wish I was kidding but I'm not.
Admin
Admin
At least you didn't copy the name I use, a.out.
Admin
Admin
--
I am NOT a robot
Admin
Admin
Despite all the wtf-ness, I must say this line is cryptic, but somewhat clever.
Admin
<FONT face=Tahoma>the more i look at it, it seems to form some sort of a figure...
</FONT>
Admin
The REAL WTF is this forum software.
Seriously though, I've seen worse date functions than this written in TSQL!
Admin
Hey, woah, it made it to front page - even though someone posted a link to the original thread, with original function (before anonymisation - it's even worse! =)
As to answer to this comment - it might not be appearent from this function alone, but the logic where it was used didnt require it to return 0 for date1 > date2. The anonymisation swapped dates in my one-liner aswell.. besides, the original function didnt even work (i dont remember what was it anymore, but it just got days wrong).
Admin
or a swap :D
<font face="Courier New">if (date1 > date2) {
temp = date1;
date1 = date2;
date2 = temp;
}</font>
Admin
I could have understood this if the code converted the dates to Julian Day Numbers, and then subtracted those. Who wants to calculate the number of days in a month?
Am I the only one who thinks this code looks like a mess -stylewise? It's so hard to read ...
The captcha says I'm "1337" Hehe.
Admin
Actually, I believe he was correcting spelling, but never mind. Right I'm off to pai for my lai.
Admin
Heh. I suppose that bad habit only became common in the 32-bit age. Anyone who began coding on 8-bit systems with 16-bit ints, would probably never do such a thing. He would of course do other silly things.
For example, I must admit to committing stupid date follies myself. Such as packing a whole date into a 16-bit word to save space. y<<9+m<<5+d or something like that. Not exactly Y2K-compatible. OTOH it was on an 8-bit system, and space was expensive, and Y2K seemed aeons away.
Admin
I bet it was originally PL/SQL. The local DBA team lead once told me a story how she cought a newbie college grad unfamiliar with the wonders of that language who implemented an algorithm that counts the difference between two days by subtracting a single day from the larger date, recursively. I completely sympthized when she told me he had his grants revoked and had to submit every schema change (on debug DB, of course) on paper to DBA team for a month. No, I can't post the code.
Admin
"...but is usually far too long to type."
This is a tru wtf! You probably only write programs with max. 26 variables and functions. Or do you use the capitals as seperate names?
Admin
emurphy wrote the following
> The February "logic" has dat/100 and dat%100 switched, plus (as noted) it fails to implement the 100-year rule (granted you have to go outside 1901-2099 for that rule to matter).
A agree with the 2099 date. The logic breaks down for dates before about1930 - you cannot use the contempory calculation for days-in-month and leap years prior to about 1930, you need to know the location to which the date applies, for the same reason that the Russian October revolution occurred in November (after which 31 January 1918 was followed by 14 February 1918). Go back a bit further and the year didn't even start on the 1st January!
If someone was born on 2 Jun 1906, they may or may not celebrate their 100th birthday today depending on where they were born (and how they decide to handle the Julian-Gregorian switch).
Of course you can use the Proleptic Gregorian Calendar, but this just introduces another set of problems.
Admin
And then you've got to watch out for the yanks! With their strange date formats, I mean MMDDYYYY - what's the deal with that?
Captcha = Whiskey.
Not as whiskey as a bank waid!!
Admin
Oh! They just wanted a date format that you couldn't sort lexicographically.
Admin
Someone who understands niether double negatives nor comma usage should discriminate(???) on double negatives.
//captcha:clueless
Admin
*Someone who understands niether double negatives nor comma usage should NOT discriminate(???) on double negatives.
I can't imagine why I might have trouble proofreading a sentence in a text box 6cm wide.
Admin
If the method name was EnterpriseGetWrongDateDiff I could understand it but this method just doesn't have that wrath of the almighty feel to it without some XML. I mean seriously, how can we be expected to make fun of enterprise methods without at least one connection to BizTalk with some XML tossed into the mix.
So lets rename it EnterpriseGetWrongDateDiffBizTalkToXMLBackToInt(date a, date b) and be done with it.
Admin
And yet again, history (and the calendar) is the real WTF...
Admin
This ^ kinda looks like an old Luger...
Admin
Argh!
I think that in this particular case a conditional statement is nonsense.
I hope the programming language supports abs() or Math.abs or something like that.
The original functionality (zero if first date is later than second) would be max ( 0, date2 - date1 ).
Admin
No joy. He also heard that only losers do bubble sorting.
--Rank
Admin
I like that. Makes it clear that the variable is "special" and holds the return value. the function definition and comments should make it clear what it does.
Admin
What the....
Yes, of course I was joking. The memory usage is about 1/3 of the joke; the O(N) algorithm (N is length of interval) where O(1) would do is the next 1/3 (although that is shared by teh original WTF if you generalize it); and the gratuitous use of an external XML resource is the final 1/3.
The code is nice and compact, though :)
The captcha is enterprisey...
Admin
Is that big O notation? I guess there are a few real programmers left in the world.
Admin
Yeah, you should be paiing more attention!
Admin
<FONT face=Verdana size=2>Not quite as original as the above, but this was sprinkled liberally throughout an application that we contracted this guy to help with.</FONT>
<!-- code formatted by http://manoli.net/csharpformat/ --><FONT face=Verdana size=2>if(!Page.IsPostBack)
{
DateTime today = System.DateTime.Today;
DateTime tomorrow = System.DateTime.Today;
string compTom = Convert.ToString(tomorrow.AddDays(+1));
string thisDay = Convert.ToString(today);
string onlyDate = thisDay.Substring(0,10);
string onlyDays= compTom.Substring(0,10);
this.dpFromDate.Text = onlyDate.ToString();
this.dpToDate.Text = onlyDays.ToString();
}
else
{
DateTime tomorrow = System.DateTime.Today;
string compTom = Convert.ToString(tomorrow.AddDays(+1));
string onlyDays= compTom.Substring(0,10);
this.dpToDate.Text = onlyDays.ToString();
}</FONT>
<FONT face=Verdana size=2>All to accomplilish adding 1 to the current date and placing it in the next textbox. And, since this was written in October, the algorithm only works on 2-digit months. We didn't find out about this bug until Janurary rolled around and the client began calling with complaints about the date formatting.</FONT>
<FONT face=Verdana size=2>Of course, he didn't even include it in a library. We counted at least 30 pages where this was implemented. We've left it commented out in a couple as a reminder to the great Fernando.</FONT>
Admin
I use "out" cause it only takes 3 keystrokes
Admin
That one's not Unix's fault, it's carved into the POSIX standard:
It is inappropriate to require that a time represented as seconds since
the Epoch precisely represent the number of seconds between the referenced
time and the Epoch. -IEEE Std 1003.1b-1993 (POSIX)
Now there is a WTF. Now you know why early GNU programs checked for an environment
variable 'POSIX_ME_HARDER' (now sanitized to POSIXLY_CORRECT).
Admin
Here's how I see the code, with suggested fixes:
Admin
out is a reserved work in some languages. My personal preference is either ret or retter... Don't know the story behind adding ter to ret...
Admin
That's easy to fix, just use a std::vector<bool>.
(one of C++'s WTFs: std::vector<bool> is completely different from any other std::vector)
CAPTCHA: genius
Admin
Although in standard Big-O notation, where n is the length of the input data, the algorithm is a much scarier-sounding O(2^n). I would describe that as, "Impressively Bad."
Admin
I suspect this particular one probably predates even POSIX (i.e. dates back to the original Unix) and changing it would just break far too much stuff...
Admin
How is this clever? If the eveness of the year matches the year divisible by 8 we will subtract 1 from the day?
Admin
Isn't the code meant to be easily mayntayned?
Admin
Perhaps the developer just wanted to make a function flexible enough to compensate for relativistic time dilation in case a nearby black hole alters the gravitational field in the spacetime continuum adjacent to contemporary Solar Sytem. This developer had a vision! A forward-thinking type, you know.
Admin
I think I understand the context. This is used to compute interest due on a mortgage/loan credit account. The financial institution uses the other algorithm for interest earned for the account.
1. Install java and ANT
2. ?????
3. Profit!