- 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
i really wanted to read the comments for this one, but someone mentioned the words "science" and "intelligent design" in one sentence, they were serious, and it made me cry.
intelligent design is something that religious folk came up with to reconcile the fact that their books said nothing of HOW the universe worked, just WHY it worked. and the WHY was the epitome of "ask your mother" answers.
I can't read this in good faith knowing that people are probably arguing this back and forth.
Admin
it doesn't matter when the program is written, but what context the program is used for.
Admin
modern IDEs have auto optimization built into them. I'm not saying that there is 0 need for optimization, but the term "overkill" should apply.
You end up wasting more resources, time and effort trying to tweak something that might make the most insignificant difference.
Something I've learned, (I'm still student - blast me all you like), for every code you write, there is always a better way to write your code. Most students fall under this trap, instead of using their time on more appropriately (no, not boozing).
Admin
IS NOT!
It is not a premature optimization if the optimized code is just as clean and readable and maintainable as the unoptimized code.
This is LOW hanging fruit. Lop it off!
Admin
Now look, I did science in high school and from what I can tell, these science guys just come up with ideas out of thin air. So tell me, why can't intelligent design be a valid scientific theory? After all, I'm not saying it's a law but a theory and from what I can gather, a theory just needs people to theorize about things and proof can be anything I like - like a book.
Remember, Darwin himself said that evolution was just a theory and I'm pretty sure he said it was flawed and he may have also refuted the whole lot on his death bed. All these other biologist who are evolutionists (basically all of them) are wrong, stupid and wasting their time; infact I'd like to know what they do all day - probably burning bibles.
PS. I'm not a monkey.
Admin
You may mean compilers, doesn't matter if you use visual studio to write up your code or notepad, it's the compiler which does the work.
Anyway, I really hope they are not teaching this sort of stuff in universities, a compiler will never be able to make up for a crappy algorithm.
Admin
By putting in the %4 test first, you cover nearly all cases so the speed would hardly be noticeable, even when you call it often (say in a loop).
I agree with you that sometimes it's not worth putting in the extra effort to fix a problem (eg. Our software covers 99.9% of cases - and we end having to pay out issues for the other 0.1% of the time. However, the cost in fixing that 0.1% is astronomical so it's far cheaper to pay out) but the cost here is almost 0 (for software which is more correct) but given the right context, the cost of not doing it could be significant.
Also, clearly this code is not going onto an embedded system :-)
Admin
Given the available development environments and the clarity and expressiveness of the language itself, Scheme as implemented in EdScheme is the only contender in high school CS curriculum. I'm dead serious.
Think about how you'd go about developing in Javascript: you need an editor,a web browser, reload button, and something like Venkman debugger. Interactive evaluation? Yeah, in the debugger or if you code it yourself using eval(). No, thank you.
There's a good article http://www.trollope.org/scheme.html about why Scheme makes sense for entry-level CS. I've self-educated myself in Basic and Borland Pascal back in elementary school, and admittedly my style and way of thinking got pretty much bastardized because of that. Only recently I've rediscovered Lisp and I'm so much happier for that. I vividly remember my classmates' struggles with Pascal in high school, and their relative ease of understanding both LOGO and Quattro Pro (a functional programming environment -- so no, that's not hard at all).
Admittedly, JavaScript is lighter on syntax -- nothing like the shackles of Pascal or C/C++. But then, its "free form" is an illusion when you start thinking of Lisp family of languages, which are about as free form as you can get. I.e. you get down to the business of programming, and not fighting the environment.
Cheers, Kuba
Admin
Ajax got thrown out of the UEFA cup by Werder last month ... Werder is better than Ajax
Admin
This has got the be the post of month.
Admin
Or a big-ass telescopic lens - then you can shoot them many, many times.
Admin
You, sir, are grossly negligent and very possibly a menace to public safety.
Admin
Actually, everyone's ignoring the highly lateral way of doing the mod arithmetic by checking if it has a decimal point. That's what I was most impressed by. It appeals to my appreciation of elegance and conciseness, but it also alerts my sense of unexpected failures.
Such a lateral thinker should be encouraged, but gently.
Admin
You forgot the many ships named Ajax. But well done.
Admin
In that "new and improved" version, if the number of seconds is exactly 59, then the code returns 0 minute(s) 59 second (s) and if the number of seconds is exactly 3599 it returns 0 hour(s) 59 minute(s) 59 second(s).
The conditionals should be:
if ( nSeconds < 60 ) ...
else if ( nSeconds < 3600 ) ...
Admin
Yeah, and what about the Aussie steel works which stopped because all their embedded controllers did not know about leap years (I can't find the reference right now - Aussies pls help).
I restate my previous statement: You, Sir, are grossly negligent and a menace to public safety.
Admin
We had one a few weeks ago: email address validator
Admin
But hey even FCK is better than Ajax, so the might snap but without good reason.
Admin
Y2K... heard of it?
What about an app that needs to see a few years into the future?
Admin
You check for validity with javascript to reduce server load. Then you check for validity serverside to make sure that it -is- valid (javascript can be circumvented).
That said, your dev is an idiot if his script only works if you actually press the button.
Admin
You might want to read some mathematics first, like number theory and the concept of countable infinity. When you say "75% of years aren't divisible by 4", I can show you a year that is a leap year for every year that you show me that isn't - proving that there are equal number of both.
Admin
Doh, Ordering! I had assumed that the code was doing 4, 100, 400 in that order without actually reading it. My WTF.
Admin
I rather thought that the excessive and child-like capitalisation, plus the absurd rubbish about the Earth's precession, would have given it away... (Not to mention the utter idiocy of shifting zero by 4004 in a calculation involving modulos.)
Admin
If you're gonna write a broken implementation anyway, then pretty pretty please at least name it isLeapYear1900-2100(year) or isLeapYearWarningDontReuse(year)!!
Admin
this code is a bigger WTF than the article (400, 100 and 4 are all divisable by 4), anyway if you really need to find out if it is a leap year, the easyest way to tell is (in essence, all were doing is testing the last 2 bits for 0).
isLeapYear(int year) { return ((year & 3) == 0); }
Admin
"The Real WTF here is..." that someone actually took the time to write down something as elementary as this.
I mean, hasn't everybody done this leap year detection several times for different languages?
Admin
And then as it was supposed to be like:
"The Real WTF here is..." that someone actually took the time to write down something as elementary as this.
I mean, hasn't everybody done this leap year detection several times for different languages?
Admin
Admin
This is obviously the best solution:
That's just delightful satire. It is satire, isn't it?Admin
[quote user=brendan] this code is a bigger WTF than the article (400, 100 and 4 are all divisable by 4), anyway if you really need to find out if it is a leap year, the easyest way to tell is (in essence, all were doing is testing the last 2 bits for 0).
isLeapYear(int year) { return ((year & 3) == 0); }[/quote]
I hope this is not serious! What do you think will happen when the year is 2100 or 2200, or 1900?
The WTF here is someone calling something a WTF and screwing it up even more.
Admin
Hah you, Sir, are too negligent read what I wrote (or too dumb to understand?). If I constantly do implementations like this and save $0.10 on the unit price by using a smaller chip, then I'm the hero of the day, I've just made my company $10.000 on the first hundred thousand units. I am a menace to nobody except for you trying to reuse the code for something it was not intended for and the person who by a miracle manage to keep the product running for a hundred years, and will be forced to change the date on march 1st of the year 2100.
The point is that there is sometimes a difference between the correct way and the best way to do things. Of course I bow to your absolute superiority but one not as humble as I might point out that you're not always right.
Admin
Read and mostly agreed. Still, there is a quite real chance that somebody else will see your code. That someone might copy the code, or get tricked into thinking that it's that simple and repeating the mistake in an inapproppriate place.
So I think it's not much to ask to clearly label your optimized-to-break code accordingly. If you can save the time someone else would spend by checking or wondering about your solution, then you're even bigger a hero.
In the meanwhile, I keep reinventing wheels all the time because people are writing code like that. They assume something isn't important, don't document it, and I find out I simply can't use their work. Even when they wanted me to. Maybe it wasn't important to them. Yay, go them.
Admin
If you were familiar and in regular contact with what religious nutjobs say and do, you wouldn't be so sure it was satire. Sometimes the satire is too similar to real events to be distinguishable, dense or not. It depends on which events you've seen and experienced, the general context and whether you know the person making the satire. There was no need to (try to) be insulting.
Admin
While I agree that HumptyMoo's code was broken, so is yours. It wrongly accepts 1900 as a leap year.
Admin
How old is this JavaScript code? You pretty well had to write horrible code like that back in the Netscape/IE3 days, because virtually everything in JavaScript was broken all to hell.
Admin
Or, in code,
function IsLeapYear(year){return (new Date(year, 3, 0)).getDate() == 29);}
Admin
I was bored so I took a shot at producing a non-crazy version of the uploadTime function.
Notes: 1) This is the first function I've ever written in javascript. 2) It doesn't change the basic assumption that it takes exactly 1 seconds to transfer 3500 bytes 3) It explicitly rounds up seconds, which seemed resonable, but is inconsistent with observed behavior of the previous script 4) Based on a quick test, javascript does support floating point modulus which is why there is an explicit Math.ceil around the secs % 60)
Admin
Doesn't vb6 have andalso and orelse keywords for stuff short circuiting?
Admin
Well, lucky for them their code works for all years between 1901 and 2099.
This code probably won't be used in 90 years... famous last words of hundreds of developers of Y2K affected software...
Admin
Admin
Hi,
Can anyone shed some light on the magic number 3500?
var secs = bytes / 3500; and var nSeconds:Number = nSize / 3500;
Thanks.
Admin
Whilst there is an element of duplication of effort in that approach, it has the advantage of trapping naff input before the form is even submitted, meaning that network bandwith and server resources are not wasted on invalid data.
I have frequently argued about this with one of my colleagues who liked to do all the validation on the client in JavaScript and then reasoned that the server side validation was not necessary.
I could see his point about not sending rubbish to the server, but he never seemed to get the point that it should not be the first, last and only line of defense.
Admin
Let's try again, remembering to click on 'quote' this time (followed by 'preview' :) )
Whilst there is an element of duplication of effort in that approach, it has the advantage of trapping naff input before the form is even submitted, meaning that network bandwith and server resources are not wasted on invalid data.
I have frequently argued about this with one of my colleagues who liked to do all the validation on the client in JavaScript and then reasoned that the server side validation was not necessary.
I could see his point about not sending rubbish to the server, but he never seemed to get the point that it should not be the first, last and only line of defense.
Admin
Somebody ealier mentioned Excel, so I fired it up and tryed a couple of leap year checks. I type 28/02/1800 in a cell and it failed to recognise it as a date.
So I tryed the formula =DATE(1800,2,28) and it resulted in the date 28/02/3700! Thats a real WTF.
Shouldn't it throw one of those #VALUE! errors. To a spreadsheet a =DATE() function is as a library function would be to a programming language.
I then tried ?dateserial(1800,2,28) in Visual Basic in Excel and that worked correctly.
This is Excel 2002 SP-2 for goodness sake.
Admin
Satire does not apply to events, btw. It's a purely literary conceit.
And now I'm insulted ... I honestly do think that you have to be a bit dense not to recognise my post as satire, for reasons I've pointed out earlier on. Apart from anything else, it is far too well-written, IMHO, to be the product of a creationist loonie. Now, take the following, for example:
Now, that's what I call splendid idiocy, coupled with the writing style and ability of the average third-grader. Trouble is, it might still be satire -- the name BillyBob leads me to believe that it is, and the PS is almost too funny to be accidental -- but, if so, it's far more subtle than mine. I only wish I could write that badly.Admin
what the heck are you people talkin' about ???
ajax is a way to make html interactive with an xml service capable server and a javascript capable web client, flash is a vector graphics plugin for the browser that can pull of some amazing tricks, but yet remains just a plugin on the browser ...
so how exactly does a tool that can hide/show table rows, create html on the fly etc. in html be even an opponent to an vector graphics display ...
get a grip && educate yourselves - ajax can't ever "kill flash" nor vice versa, people will always want nice graphics and flash is there to provide it.
Admin
You do not speak for me, and I wouldn't consider myself to be elitist. Handling input data correctly, or raising an error if you don't, is one of the defining aspects of your job as a programmer.
If your design spec clearly states that you will only be handling dates in a certain range, make a one-line comment about this, referencing that part of the spec, so it can be fixed if they change the spec.
Of course, you'd better be damn certain noone can pass in input you don't handle properly, too.
That said, this is exactly the thinking that brought us Y2K, and will bring us Y2038 (affectionately called "armageddon" by several C programmers).
When will people learn that the "zero, one or infinite" rule applies doubly to input data?
Admin
Is it really?
I mean, sure, if you have seperate servers for static content, or a Varnish accelerator in front of the server, I can agree, as long as these tests are part of the static content.
But remember that if you're pushing a lot of validation code, you're taking a small hit on that, too. And maintaining the javascript code that does this kind of validation takes developer time. It also runs the risk of false positives (valid input becoming unsubmittable because the JS code doesn't like it) if the testing is inadequate.
Since you'll be needing to deal with this stuff on the server side anyway, it makes sense (IMO) to keep it there.
Admin
You are all wrong.
Ajax is a soccer team: http://english.ajax.nl/web/show/id=49108
Admin
Better yet, if you have a context-coloring IDE:
bool isLeapYear(date) { return false; // TODO: Fix to true on Jan 1 }
CAPTCHA: gygax - inventor of the gaming geek?