- 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 goggles, they do nothing!
....seriously, ouch.
Admin
Not sure, but doesn't the
Admin
Was there an anonymization typo? Based on two dates I used to figure out the logic, I find that dat/100 cannot be 2 (it's always greater), but I guessed that daymo finds the number of days in a given month, in some convoluted way.
Admin
<FONT face=Georgia>Well, that's a pretty, huh, creative way to do it... Maybe 5 minutes of research would've saved the poor sap days of creating this monstrosity.</FONT>
>BiggBru
Admin
<FONT size=6>RTFM.</FONT>
Admin
The first function has a bug... if the two dates passed straddle any of the following dates, the result will be off by one.
...
February 28, 1800
February 28, 1900
February 28, 2100
February 28, 2200
February 28, 2300
February 28, 2500
...
Note February 29, 2000 and February 29, 2400 are OK.
Admin
Thats the way you save your Job, nobody will understand your code,
once you're fired ;)
//captcha: clueless
Admin
Actually this function assumes every month is 31 days so it becomes grossly inaccurate the greater the span between the two dates.
Admin
No. It handles the days per month mostly correct.
Admin
And they'll hire you back as a highly payed contractor.
Admin
If you put in 2 dates 1/1/2005 and 1/1/2006 you'll get 372 as a return value. Which btw is the result of 12 * 31.
Admin
I'd like to see the reaction when the author is shown the replacement line of code. Would he/she say "oops, I was stupid", or what?
Admin
No one who can't spell "paid" deserves to be highly "payed".
Admin
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).
I have no earthly idea how the April/June/September/November "logic" is expected to work.
a < 12 apparently imposes a maximum of 12 months (with wiggle room within the months, e.g. 1 May 2005 to 31 May 2006 gives 395 days), plus (as noted) there's a minimum of 0 days. Was the original function named EffectiveDaysOverdue?
Admin
I think the new one liner has a bug - should be date2 - date1.
Admin
...and in a very roundabout way. :)
(OK, I understand the author didn't know how to subtract two dates but there's no real excuse for not using arrays to find out the number of days in a month.)
Admin
Well, no, the two lines that follow the initial appearance of daymo try to handle varying length of months in a year. I couldn't for the life of me understand how he reached such a complex setting though.
Admin
Yup. Mostly. All the pieces are there.
Admin
I kind of think that the author would say something like:
"But MY code is more enterprisey!"
/captcha=billgates
Admin
It doesn't handle the days per month correctly at all. As I said earlier it returns 372 as the difference between 1/1/05 and 1/1/06.
Admin
And no one who corrects grammar on a WTF forum gets "layed" [sic]
Admin
That's a known bug. The original coder wanted that line to be:
<FONT face="Courier New" size=2>if (date1 > date2) return -(functionName(date2, date1));</FONT>
But then he heard that recursion can blow your stack and couldn't figure out how else to do it.
--Rank
Admin
I've written something similar to that, except:
a) mine worked, and
b) the language didn't support it natively (no "Date" type).
Still, why didn't he use an array and then simply adjust for leap years? It's just weird not to do so.
Admin
Oooooooops, you are right. I didn't test it, just looked over it and saw "well, there is some code that seems to handle the days per month". But there are some bugs (e.g. / instead of %) that break it.
Admin
I've have yet to see a modern language that can't convert date structures to UNIX-style timestamps. Comparing that way is simply (timestamp1 - timestamp2) / (606024). Use integer division, rounding, or casting to int as appropriate.
Admin
<FONT face=Verdana size=6>obfuscation, <FONT size=3>eh?</FONT></FONT>
Admin
Now That is funny! (sadly true, too)
Admin
http://thedailywtf.com/forums/post/43762.aspx
Admin
Ugh, I hate it when people use "retval" for a return value. You might as well call it "variable".
Admin
You fail to realize that the Kepezinskas calendar has 172 days.
Maybe this is another case of being payed (as well as layed) by the line. And who can really trust the built in date calculations? If you want to be REALLY sure...
If the calendar ever changed (once the terrorists take over the world) his code will be easily (well not quite) maintained and my date2 - date1 will need extra code to compensate for the changes.
date3 = Math.AdjustForTerrorists(date2,date1)
Admin
The first rule of writing your own date manipulation functions is: don't write you own date manipulation functions!
How people don't get it? This should taught in schools instead of starting the teaching of OOP with implementing simple class Date (quite common example indeed).
I'm wating for the day, when people eventually understand, that our calendar system really sucks. Why are we still using this ancient stupid "you have to remember how many days there are in each month"-calendar?
Admin
I always call my return values ret.
The name of the function is a good clue to what the value means, but is usually far too long to type.
Admin
Sure, let's start using Star Dates instead :)
The fun thing is that every so often, due to the imperfections of the alignment of the sun, moon and the earth, we need to have leap years, seconds, etc. so there's still quirks, but at least it wouldn't be such a hard thing to remember in comparison, and math on dates would be simpler, until you start getting picky and dealing with the occasional leap second, etc.
Admin
Oops. (Although English is not my native language, it's understandable that things like this do happen if I'm not paying attention to what I write. :))
Admin
what an amazing construct. truely the most deserving wtf I've seen in a long while. we all do this from time to time on a smaller scale, but the perserverence it must have taken to see this one through is bewildering. while I accept that I am stupid and have limited capacity for these things, this guy is a wtf-y genius and I must bow to his clever idiocy.
the only thing I could think when I read the code was indeed "w.t.f????". more like this please.
Admin
Using unix time_t and taking the difference / (606024) will be slightly wrong because of leap-seconds. The library functions that gave you the time_t will have taken leap-seconds into account.
Admin
Why? If you already know what the function returns (e.g. from the comments), it would be redundant to state it in the variable name.
Admin
Score 1 for Visual Basic?
Admin
Hey, have you been looking at my code again? You can tell it's mine because it's called 'PROGRAM.EXE'.
Admin
Someone who doesn't understand double negatives, shouldn't discriminate on "paid" versus "payed".
Admin
IIRC, the definition of Unix time values requires that leap seconds are ignored - each day is treated as though it lasts exactly 86400 seconds (even if it isn't really). Simplifies things a lot...
Admin
Ah.. you're forgiven then, and I'm sorry!
Admin
Your comment on double negatives is the least benightedly unintelligent one it has ever been my extreme displeasure not to be able to avoid reading.
Admin
Mostly is the keyword here :-)
Admin
The comments probably say the code is "Mostly harmless". This is a great improvement over the first version of the comments, which simply read "Harmless".
Admin
I use it. In a language which does not have the return value in a variable of the same name as the function, it serves the same purpose. All I want to state is that the variable is the return value under construction. That makes "retval" a good name (for me).
Sincerely,
Gene Wirchenko
Admin
You'd think so.
But.
Compare it to a short story, with a most fitting title and comfortably descriptive introduction, but the actual story comprising mostly of sentences such as "When that thing happened at that time with the thing."
The syntax is for the compiler. It doesn't complain.
The code itself is for us. Programmers do.
Admin
It could be telling.
I am just working on some code where I have to say that the way that it was was a good idea at the time. At least, I hope it was. Sometimes, that previous idiot who was working on the code is you, well, me.
Sincerely,
Gene Wirchenko
Admin
Compilers are professional complainers.
Yes, we are even better/worse at it.
while programmer's sanity exists
"What is that variable for? The one that you called '<some long name>'." "Oh, that is the return value." "Why did you not just call it 'retval'?" "Well, dhromed said . . . OK, I will change it."
"Why did you just call that variable 'retval'." "Oh, that is the return value." "Why did you not call it '<some long name>'?" "Well, Gene Wirchenko said . . . OK, I will change it."
end of while
Sincerely,
Gene Wirchenko
Admin
After skimming the thread, I would like to make a couple observations:
1) I'm assuming that the "punctuation" got messed up during anonymization, and that the orignal code actually worked... But hey, who knows...
2) The difference between "paid" and "payed" is spelling, not grammar.
3) Clearly the right way to perform this operation is data-driven :)
short isValidDate[99991232]; // fix the y10k bug later
/* load in data that populates our array... probably from some sort of XML file... the first 10101 elements are 0, then the next 31 are 1, then 69 more 0's, then 28 1's... you get teh idea, right? */
d = 0;
for(i = d1; i < d2; i++) {d += isValidDate[i];}
BAM!