| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
The real WTF is that they hardcoded the 19 seconds...
In all seriousness... my eyes, the goggles do nothing!! |
|
I want to know what WTF is really at work here. The need to add 19 seconds to a time hints at a bigger wtf.
|
|
I did this, back in CS160 the day before they told us about the time functionality. sad
|
|
ignorance of a library is bad, but this is atrocious:
HARDCODING for leap-year detection?!? Oi. |
|
oh we've all done this before when we were new.
|
At least, he doesn't expect his code to be running in 2016... |
Re: All For 19 Seconds
2007-09-21 10:53
•
by
Tes
(unregistered)
|
leap-year?? He's only hardcoding if February has 28 or 29 days. He should have used another four ifs to check if the year is congruent modulo 4 and modulo 400. You never know for how much time your code will be used... even being a WTF! |
Re: All For 19 Seconds
2007-09-21 10:53
•
by
Tes
(unregistered)
|
leap-year?? He's only hardcoding if February has 28 or 29 days. He should have used another four ifs to check if the year is congruent modulo 4 and modulo 400. You never know for how much time your code will be used... even being a WTF! |
|
if ($month == 2){
if (($year == 2008)||($year == 2012)){ if ($day < 29){$day++;} else{$day = 1;$month = 3;} haha here is a WTF, this code will work until 2016. After that I suppose this is his way of saying he doesn't plan to be around by then. Also, using modulo would yield the correct leap year. Oh, or the gmtime library! |
|
Nobody has commented on
my $hour = $date[2]+4;yet. Apparently, he's computing localtime by hard-coding the GMT offset! That's gonna break, half of the year. Great. |
|
Superb :-))
"Before August, odd months have 31 days; from August onwards, even months do." It's the good old counting-on-the-knuckles trick. |
This doesn't seem very Y2K friendly. |
Re: All For 19 Seconds
2007-09-21 11:12
•
by
Andrew
(unregistered)
|
Only if he's in Armenia, Azerbaijan, or Russia. If he's in Georgia, Mauritius, Oman, Réunion, Seychelles or the United Arab Emirates he's fine. |
The whole thing doesn't seem friendly to anything except his LOC count. |
Not to mention the fact that he hardcoded 41 (60-19) at one place, but left it as -19 + 60 in another. Phew! - this has to be one of the best WTFs I have seen for a while. |
|
The Real WTF is that he doesn't check whether the output of gmtime() is valid. If the date is, say, 1998-14-31, 23:59:59, the result will be 1998-14-31, 00:00:18. I mean, how can't he trust on the time library when he obviously doesn't really know it exists?
|
Re: All For 19 Seconds
2007-09-21 11:31
•
by
dnm
(unregistered)
|
That's one of the only OK lines in the code. In perl, localtime() returns an array of different parts of the date/time. Element 5 is the number of years since 1900, so 2007 would have a value of 107 in $date[5]. my $new_date = time + 19; Programmers like this amaze me. Not knowing gmtime exists is excusable. What is NOT excusable is not stopping about 1/10th of the way through that and going, "wait, this is stupid. there has to be an easier way." |
Re: All For 19 Seconds
2007-09-21 11:32
•
by
Anonymous
(unregistered)
|
That results from a stupidity in Perl, as you can see if you look at the gmtime docs. The year element of the array returned by gmtime() is equal to the current year minus 1900. |
|
newTime = ConvertTimeToSeconds(time)
newTime += 19 time = ConvertSecondsToTime(newTime) simple enough, right? :) Captcha: onomatopoeia (I hope I spell it right) |
Re: All For 19 Seconds
2007-09-21 11:35
•
by
Aquatoad
(unregistered)
|
|
Actually, this is correct in the UNIX world.
From the StdC gmtime() documentation: int tm_year; /* years since 1900 */ Also, the fix proposed by the submitter isn't correct, since the original code accounts for the *offset* from GMT, whereas the solution should be using localtime() instead of gmtime(). |
Re: All For 19 Seconds
2007-09-21 11:37
•
by
Synonymous Awkward
(unregistered)
|
So you thought you'd type it a second time for practice? |
Re: All For 19 Seconds
2007-09-21 11:39
•
by
Aquatoad
(unregistered)
|
Fail! This is a "stupidity" that Perl inherited from Standard C/POSIX. As an aside, I've found that aside from basic math operations (off-by-one errors etc) the biggest atrocities in programming languages occurs in date manipulations. |
|
my $hour = $date[2]+4;
Apparently this code will only work properly between 04:00 and 24:00 local time, as any time from 00:01 to 03:59 will actually show up as 00:xx |
|
The real wtf is that he isn't accounting for leap seconds
|
Re: All For 19 Seconds
2007-09-21 11:57
•
by
Asd
(unregistered)
|
You are not wrong. God save us from java.util.Calendar |
|
reminds me of a recent post on a (french, sorry) SEO forum :
http://www.webrankinfo.com/forums/viewtopic_80454.htm for those who don't speak french, the initial poster wants a php function that formats 2500000 to 2,500,000 the first answer is an interesting home-made function. the second answer is, well, the right answer. |
Re: All For 19 Seconds
2007-09-21 12:19
•
by
CynicalTyler
(unregistered)
|
|
Ha, good old java.util.Calendar. I once wrote a class that added a certain amount of days (or weeks or months or years) to a date by incrementing the date once for every day. Yeah, I knew it was a WTF, but I was in a hurry and dammit it worked! All that to avoid Java's built in date handling... tsk tsk.
|
|
Um, gmtime library? That ought to say "gmtime library function" or something similar.
|
You spelled it right, but it still sounds wrong. |
And furthermore, not simply using the Internet to search for a solution! As an "old timer" I sometimes fault the younguns for being lazy and jumping directly to Google. But, it is a great resource. If someone else on the planet has faced this problem once before, you can probably find their answer in a few minutes! |
I don't need to know French to find that even funnier than today's CodeSOD. Any why on earth did he name his function "ToMoney"??? Am I missing something in the French back-and-forth that mentions money? |
The numbers he's formatting are prices. |
Re: All For 19 Seconds
2007-09-21 13:02
•
by
Theo
(unregistered)
|
No they don't mention money, I guess the original purpose of the method was to display the number with a currency, for an amount of money... That's another WTF, naming methods for the purpose and not according to what they actually do... like getTheResultIWant() Anyway, you're right, it's evwen better than the current WTF :) I'm off to get some captcha (tacos) |
Re: All For 19 Seconds
2007-09-21 13:33
•
by
Mr Fred
(unregistered)
|
|
The 1900+$date[5] is a Perl-WTF, it is perfectly Y2K friendly so long as you remember that Perl starts counting years from 1900.
That led to some amusing bugs on Jan 1 2000. For example there were those who did string concatenations instead of addition and got Today is Jan 1 19100. |
Re: All For 19 Seconds
2007-09-21 13:38
•
by
Mr Fred
(unregistered)
|
Be careful what you wish for, you might get it. Hint: see JSR 310. |
|
The real WTF is that they are using Perl.
|
Re: All For 19 Seconds
2007-09-21 13:42
•
by
ahgan
(unregistered)
|
And what happens in 2016, 2020, etc... Only thing better than overly complicated, and unnecessary code is overly complicated, unnecessary, insufficient, and broken code Guess that's what they call job security Capcha: waffles, Mmmmmmmmmmmmmmmmmmmmmm waffles! :9 |
Re: All For 19 Seconds
2007-09-21 13:49
•
by
Michael
(unregistered)
|
http://jcp.org/en/jsr/detail?id=310 https://jsr-310.dev.java.net/ |
Re: All For 19 Seconds
2007-09-21 13:53
•
by
Corey
(unregistered)
|
The fact that I see this type of comment no matter what the language is leads me to believe that the actual real WTF is that they're using a computer at all. |
|
Lots of WTFs...
Isn't ($month==2) checking March, not February? Month is 0-based in Perl IIRC |
Not in this case, because the original programmer added 1 to the retrieved value stored in $month, as well as adding 1900 to the $year. |
|
"expand your solution from exercise 1 to take leap seconds into account".
|
Yes, if you google for 19107, and ignore the zip code hits from Philadephia, you can still get quite a bit of amusement. Every one of them WTF-worthy. |
Technically, it would work until Feb 28th at 23:59:40.999, 2020..since that would be the last point that you could add 19 seconds to and the code would return the correct date. |
|
The real wtf is people actually suggesting improvements to this crap. Its kinda like saying: "HAHA, are you eating shit? In my opinion, you should use less salt!"
|
Re: All For 19 Seconds
2007-09-21 15:21
•
by
wiregoat
(unregistered)
|
And hold your nose captcha = tesla. Shocking |
Re: All For 19 Seconds
2007-09-21 15:26
•
by
James
(unregistered)
|
Nope, I was born lazy -- and remember, kids, Lazy Is A Virtue. |
LMAO |
Re: All For 19 Seconds
2007-09-21 15:35
•
by
Nobody
(unregistered)
|
|
That should be:
my @time = gmtime(time + 19); -not- my @ time = gmtime(time + 19); No spaces allowed in Perl identifiers! |
Re: And his next assignment was…
2007-09-21 15:51
•
by
iMalc
(unregistered)
|
Yeah, except you can't anyway because they don't occur at precise calculateable times, their coming is announced. |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |