• (cs) in reply to chrismcb

    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.

  • Dan (unregistered) in reply to JohnB
    JohnB:
    Paul:
    What's even more of a WTF is that the leap year calculation is WRONG. Leap years are years that are divisible by 4, unless they're divisible by 100, unless they're divisible by 400. The year 1900 was not a leap year, 2000 was.
    None of the software I've written was around in 1900, it was around in 2000, it won't be around in 2100. When I was doing all the Y2K remediation, we never worried about whether 2100 was or wasn't a leap year (except for the people who were remediating COBOL code).

    it doesn't matter when the program is written, but what context the program is used for.

  • Dan (unregistered) in reply to Thorin
    Thorin:
    Dan:
    optimization doesn't really matter does it? assuming you're working in a company that actually uses a IDE instead of notepad.
    I'd really like to hear an explanation of your logic here....

    Captcha: bathe (too funny)

    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).

  • (cs) in reply to guy
    guy:
    Ultimape:
    I don't think its premature optimization... typically code like this is reused many times in multiple projects. While in your particular project, it might only be ran .01% of the time, another project might use it every time a database transaction is ran, which might be the entire point of the program (thus running a good deal more of the time).

    If you think about it in that sense, you realize that the weight of the code's optimization is potentially spread out in parallel over all the projects that include it. Thusly, the effectiveness of one optimization could be more than originally thought.

    This is espcially true with javascript, and how it is copied and pasted from website to website on a regular basis.

    Besides, I did that optimization instinctually when I went through and tried to write that code... shortcircuiting is a tool that should be used when availble, regardless. Its such a simple bit of tweaking that when applied uniformially, can reduce a large amount of comparitors.

    captcha: gotcha, like I just gotcha with a burn.

    It is totally a premature optimization. A couple of mod operations are nothing compared to a database transaction. This would basically have to run as one of the most expensive operation in a loop millions of times before you would see any gain at all from optimization.

    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!

  • BillyBob (unregistered) in reply to GeneWitch
    GeneWitch:
    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.

    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.

  • BillyBob (unregistered) in reply to Dan
    Dan:
    Thorin:
    Dan:
    optimization doesn't really matter does it? assuming you're working in a company that actually uses a IDE instead of notepad.
    I'd really like to hear an explanation of your logic here....

    Captcha: bathe (too funny)

    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 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.

  • BillyBob (unregistered) in reply to jesse
    jesse:
    assuming one's piece of code will be out of service in 93 years from now, mod 4 is an adequate check. it's not correct but why bother..

    hah since this was declared "a big wtf" by several others, let me explain what I meant with the word "assuming" in the beginning. If I know I can do that assumption it's adequate, what if there is no big picture.

    I can do the correct implementation but if this function was ever required from me I probably would avoid it (unless, of course, it would calculate on other dates than the current). I work embedded, usually on too small targets (i.e. always think optimise for size, for all you windows wankers size is the bytes and the kilobytes and the megabytes, yes applications also occupy those) and that code will be useless long before the next century. Is that a reason good enough for you? This is not a defense for that javascript code (that won't be in embedded) but rather a beration of the know-it-alls crowding this site, trying to excel in their own brillance.

    And yeah some would call me lazy too, but let's call it optimised for speed.

    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 :-)

  • Kuba (unregistered) in reply to Volmarias
    Volmarias:
    It's great that it's so easy to learn to use javascript, and I'd consider it an ideal language to teach programming concepts to high school students (delightfully instant feedback when you pair it with the DOM, no need to precompile)

    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

  • (cs) in reply to Unomi
    Unomi:
    if I hear one more person talk about AJAX without being able to tell me what it means, I'll snap.

    Some people snap when you tell them Feyenoord is better than AJAX....

    • Unomi -

    Ajax got thrown out of the UEFA cup by Werder last month ... Werder is better than Ajax

  • (cs) in reply to Duston
    Duston:
    Nero:
    so, Paul, what's the method for figuring out if a year is a leap year?

    You go to the calendar hanging on the wall, flip to the page that says "February" and look for the number "29." If you see it, then it's a leap year. If not, then it's not. Unless of course your calendar was printed wrong. Hmm...so maybe that's not so fool-proof either. That's odd...Come to think of it, my calendar doesn't have any 7's. Better check my phone to see if it has a 5.

    This has got the be the post of month.

  • (cs) in reply to pshotts
    pshotts:
    Am I the only one who wants to do something about those "var mints" in the uploadTime function? Possibly using a hunting rifle?

    Or a big-ass telescopic lens - then you can shoot them many, many times.

  • (cs) in reply to jesse
    jesse:
    assuming one's piece of code will be out of service in 93 years from now, mod 4 is an adequate check. it's not correct but why bother..

    You, sir, are grossly negligent and very possibly a menace to public safety.

  • Static (unregistered)

    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.

  • (cs) in reply to Andrew
    Andrew:
    Actually, the term ajax is rather overloaded. There are two characters in the Iliad named Ajax, a play about one of them was written by Sophocles. Other uses include at least four makes of automobiles, several ships, and two locomotives, at least nine sports teams, a band or two, a city in Canada, a missile, an asteroid, the cleanser and the dish soap, and even a kind of dinosaur.

    That's what happens when you name something after a mythical character.

    You forgot the many ships named Ajax. But well done.

  • Ed Minchau (unregistered)

    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 ) ...

  • (cs) in reply to jesse
    jesse:
    assuming one's piece of code will be out of service in 93 years from now, mod 4 is an adequate check. it's not correct but why bother..

    hah since this was declared "a big wtf" by several others, let me explain what I meant with the word "assuming" in the beginning. If I know I can do that assumption it's adequate, what if there is no big picture.

    I can do the correct implementation but if this function was ever required from me I probably would avoid it (unless, of course, it would calculate on other dates than the current). I work embedded, usually on too small targets (i.e. always think optimise for size, for all you windows wankers size is the bytes and the kilobytes and the megabytes, yes applications also occupy those) and that code will be useless long before the next century. Is that a reason good enough for you? This is not a defense for that javascript code (that won't be in embedded) but rather a beration of the know-it-alls crowding this site, trying to excel in their own brillance.

    And yeah some would call me lazy too, but let's call it optimised for speed.

    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.

  • (cs) in reply to dak
    dak:
    Do a Google search for "javscript email validation"

    ...

    Yuck. Where's a regex when you need one?

    We had one a few weeks ago: email address validator

  • lst (unregistered) in reply to Unomi

    But hey even FCK is better than Ajax, so the might snap but without good reason.

  • operagost (unregistered) in reply to jesse

    Y2K... heard of it?

    What about an app that needs to see a few years into the future?

  • Pilum (unregistered) in reply to vt_mruhlin

    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.

  • B (unregistered) in reply to savar

    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.

  • Jamie (unregistered) in reply to Kou Eihou
    Kou Eihou:
    Jamie:
    HumptyMoo:
    bool
    isLeapYear(int year)
    {
        if (year % 400 == 0)
            return true;
        if (year % 100 == 0)
            return false;
        if (year % 4 == 0)
            return true;
        return false;
    }

    OK, it's verbose, but it's legible.

    WTF. You've already returned true on the mod 400, and never get to the mod 100 or mod 4 checks.

    Well, there wouldn't be any point in checking whether if it is divisible by 100 and 4 if the year is already divisible by 400.

    Doh, Ordering! I had assumed that the code was doing 4, 100, 400 in that order without actually reading it. My WTF.

  • (cs) in reply to Zylon
    Zylon:
    Secure Programmer:
    The mythical intelligent design is a "scientific point of view"? WTF? I initially thought this post was sarcasm and a joke, but it seems to have been written seriously. Wow. Far out.
    The best satire is written with a straight face. This has the added advantage of outing people too dense to detect satire on their own.
    Thank you, Sir or Madam.

    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.)

  • Jonni (unregistered) in reply to jesse

    If you're gonna write a broken implementation anyway, then pretty pretty please at least name it isLeapYear1900-2100(year) or isLeapYearWarningDontReuse(year)!!

  • (cs) in reply to HumptyMoo
    HumptyMoo:
    bool
    isLeapYear(int year)
    {
        if (year % 400 == 0)
            return true;
        if (year % 100 == 0)
            return false;
        if (year % 4 == 0)
            return true;
        return false;
    }

    OK, it's verbose, but it's legible.

    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); }

  • Ascen (unregistered) in reply to Mixu

    "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?

  • Ascen (unregistered) in reply to Paul

    And then as it was supposed to be like:

    Paul:
    What's even more of a WTF is that the leap year calculation is WRONG. Leap years are years that are divisible by 4, unless they're divisible by 100, unless they're divisible by 400. The year 1900 was not a leap year, 2000 was.

    "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?

  • (cs) in reply to B
    B:
    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.
    No Quack. Seeing as the current calendrical system has not been in use for perpetuity there is not an infinite number of leap years in the past. You also assume that the current calendrical system will be in use until the end of time. You also assume that time is an infinite concept (i.e. it continues after the universe heat-death / Big Crunch / whatever). Although you could probably prove that mathematically INFINITY-1 == INFINITY, leap years don't fall into that category
  • Faxmachinen (unregistered)

    This is obviously the best solution:

    var LeapYearLookup = new Array()
    
    function isLeapYear( year )
    {
    	if (LeapYearLookup[year] == null)
    	{
    		if (year % 4)
    			LeapYearLookup[year] = false
    		else if (year % 100)
    			LeapYearLookup[year] = true
    		else if (year % 400)
    			LeapYearLookup[year] = false
    		else LeapYearLookup[year] = true
    	}
    
    	return LeapYearLookup[year]
    }
    Mr Wolf:
    Web 2.1 is the way forwards.
    That's just delightful satire. It is satire, isn't it?
  • SomeoneElse (unregistered) in reply to brendan

    [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.

  • jesse (unregistered) in reply to cklam
    cklam:
    jesse:
    assuming one's piece of code will be out of service in 93 years from now, mod 4 is an adequate check. it's not correct but why bother..

    hah since this was declared "a big wtf" by several others, let me explain what I meant with the word "assuming" in the beginning. If I know I can do that assumption it's adequate, what if there is no big picture.

    I can do the correct implementation but if this function was ever required from me I probably would avoid it (unless, of course, it would calculate on other dates than the current). I work embedded, usually on too small targets (i.e. always think optimise for size, for all you windows wankers size is the bytes and the kilobytes and the megabytes, yes applications also occupy those) and that code will be useless long before the next century. Is that a reason good enough for you? This is not a defense for that javascript code (that won't be in embedded) but rather a beration of the know-it-alls crowding this site, trying to excel in their own brillance.

    And yeah some would call me lazy too, but let's call it optimised for speed.

    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.

    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.

  • Jonni (unregistered) in reply to jesse
    jesse:
    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.

    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.

  • Secure Programmer (unregistered) in reply to Zylon
    Zylon:
    Secure Programmer:
    The mythical intelligent design is a "scientific point of view"? WTF? I initially thought this post was sarcasm and a joke, but it seems to have been written seriously. Wow. Far out.
    The best satire is written with a straight face. This has the added advantage of outing people too dense to detect satire on their own.

    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.

  • (cs) in reply to brendan
    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); }

    While I agree that HumptyMoo's code was broken, so is yours. It wrongly accepts 1900 as a leap year.

  • awefasdfsaf (unregistered)

    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.

  • Charles Bretana (unregistered) in reply to cklam
    cklam:
    Duston:
    Nero:
    so, Paul, what's the method for figuring out if a year is a leap year?

    You go to the calendar hanging on the wall, flip to the page that says "February" and look for the number "29." If you see it, then it's a leap year. If not, then it's not. Unless of course your calendar was printed wrong. Hmm...so maybe that's not so fool-proof either. That's odd...Come to think of it, my calendar doesn't have any 7's. Better check my phone to see if it has a 5.

    This has got the be the post of month.

    Or, in code,

    function IsLeapYear(year){return (new Date(year, 3, 0)).getDate() == 29);}

  • Jonathan (unregistered)

    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)

    function uploadTime(bytes)
      {
          var secs = bytes / 3500;
          var mins = 0;
          var hours = 0;
          var outputstring = "";
    
          mins = Math.floor(secs/60);
          hours = Math.floor(mins/60);
          secs = Math.ceil(secs % 60);
          mins = mins % 60;
          
          if ( hours > 0 )
          {
              outputstring = outputstring + hours;
    	  if ( hours == 1 )
    	  {
    	      outputstring = outputstring + " hour ";
    	  }
    	  else
    	  {
    	      outputstring = outputstring + " hours ";
    	  }
          }
          if ( mins > 0 )
          {
              outputstring = outputstring + mins;
    	  if ( mins == 1 )
    	  {
    	      outputstring = outputstring + " minute ";
    	  }
    	  else
    	  {
    	      outputstring = outputstring + " minutes ";
    	  }
          }
          outputstring = outputstring + secs;
          if ( secs == 1 )
          {
              outputstring = outputstring + " second";
          }
          else
          {
              outputstring = outputstring + " seconds";
          }
          return outputstring;
      }
    
  • jdawg (unregistered) in reply to Beavis

    Doesn't vb6 have andalso and orelse keywords for stuff short circuiting?

  • Tom (unregistered) in reply to Paul
    Paul:
    What's even more of a WTF is that the leap year calculation is WRONG. Leap years are years that are divisible by 4, unless they're divisible by 100, unless they're divisible by 400. The year 1900 was not a leap year, 2000 was.

    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...

  • (cs) in reply to aikii
    aikii:
    That's just amazing to see how many coders actually focus on number representation ( as a string ) instead of properties ( modulo, comparison to 0, integer truncation ... ).

    Excusable for teenagers, but not for professionals. Not even non-programmers.

    I remember similar cases in older WTFes, like checking if a number starts with "-".

    I am guilty of something much worse, back in my "still learning" days. I wanted to store two numeric values in a text file, so I stored a single value and converted it such that "value one" was anything before the decimal point, and "value two" was anything after... 10 and 25 = 10.25 23.678 = 23 and 678 Needless to say, it sucked to write, didn't really work very well, and could have just been stored as two digits....

  • Ahmed (unregistered)

    Hi,

    Can anyone shed some light on the magic number 3500?

    var secs = bytes / 3500; and var nSeconds:Number = nSize / 3500;

    Thanks.

  • Derek Nippl-e (unregistered) in reply to vt_mruhlin

    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.

  • Derek Nippl-e (unregistered) in reply to vt_mruhlin

    Let's try again, remembering to click on 'quote' this time (followed by 'preview' :) )

    vt_mruhlin:
    JavaScript in general pisses me off. My company has a web-based provisioning app that insists on using JavaScript to validate all the form data before you submit it.

    The developers on it set up the forms so that pressing enter in a textbox doesn't actually submit the form. They want me to have to press the submit button with my mouse, because that will "ensure" that I don't try to hack my way around the validation by turning JavaScript off....

    I tell the developer, "umm, I can just look at the source and find the URL it's posting to, send whatever data I want that way." His response? "That's why we do the same validation on the server side".....Why? Why bother?

    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.

  • Tony B (unregistered)

    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.

  • (cs) in reply to Secure Programmer
    Secure Programmer:
    Zylon:
    Secure Programmer:
    The mythical intelligent design is a "scientific point of view"? WTF? I initially thought this post was sarcasm and a joke, but it seems to have been written seriously. Wow. Far out.
    The best satire is written with a straight face. This has the added advantage of outing people too dense to detect satire on their own.

    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.

    If there was "no need to (try to) be insulting," this implies that you weren't insulted. So what's the problem?

    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:

    BillyBob:
    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.

    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.
  • martin (unregistered) in reply to mrprogguy

    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.

  • zuiraM (unregistered) in reply to Kalirion
    Kalirion:
    I think I speak for most "non-elitists" when I say, WHO CARES? For by far the most purposes, finding out if a number is divisible by 4 is quite enough, thank you very much. How many of todays applications, especially web apps really need to know whether any year before 1901 or after 2099 is a leap year?

    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?

  • zuiraM (unregistered) in reply to ML
    ML:
    Preliminary validation on the browser, without making calls to the server, is a very nice-to-have. With this, the user can get instant feedback on obvious errors without a round-trip to the server AND it takes a lot of unnecessary load off the server to boot. It's a win-win.

    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.

  • André Cardoso (unregistered) in reply to Strider

    You are all wrong.

    Ajax is a soccer team: http://english.ajax.nl/web/show/id=49108

  • Michael (unregistered) in reply to newfweiler
    newfweiler:
    bool isLeapYear(date) { return false; // Note to self: remember to change to true on Jan 1 }

    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?

Leave a comment on “JavaScript Hacks ”

Log In or post as a guest

Replying to comment #:

« Return to Article