• (cs)

    IMHO the biggest WTF is replacing invalid user input with some default value. I just hate it. Typos are a lot easier to fix when you don't have retype everything.

  • (cs) in reply to Amerrickangirl
    Amerrickangirl:
    Will:
    The more important question is how much you're get pay'd for. If you want such a Job - go ahead, for $10 a month you can write it for me, I'll post hear :-)

    Is "pay'd" even a word?

    Of course it is, it's contraction of "pay would" as in What do you expect from this job? Well, pay'd be nice.

  • Craig Greenhouse (unregistered)

    I've seen a project with some similarly horrible date wrangling code in PHP. To generate a drop down list of twelve months we have this abomination

    for($tempMonth = 1; $tempMonth <= 12; $tempMonth++) { $tempMonthText = date('F', ($tempMonth - 1)60602431); $template->set_var(array( 'vMonth' => $tempMonth, 'vMonthText' => $tempMonthText, )); $template->parse('bMonth_Block', 'bMonth', true); }

    Unsurprisingly when testing it on a particular day in August the whole month of February just "disappeared" from the drop down list !

    It got rewritten using an array listing the 12 month names...

  • Zerbs (unregistered) in reply to Nick J
    Nick J:
    Isn't is about time we decimalised time?
    I think it would cause too much confusion if there were only 10 hours in a day, 10 minutes in a second, 10 seconds in a minute, ect...
  • anonymous (unregistered) in reply to CodeRage
    CodeRage:
    Date pickers (mouse only) are horrible inefficient compared to using the keyboard.

    For random, far-distant dates this is true. For "later this month" dates (like online bill pay) this is false. I'd much rather click the date in a mini-calendar than get out my own calendar and decide which date to type in.

    CodeRage:
    Even worse are US State pickers... having to go through a whole drop-down list when I could just type TWO LETTERS.

    I don't really have a problem with these if they are implemented correctly. By which I mean that the option values begin with the state name or abbreviation (no prefixed "-" or " " etc.). Any reasonable browser will allow you to click on the field and type the first few letters of the state you're looking for. This works less-well when random garbage is inserted by the designer because it "looks better".

  • Anonymous (unregistered) in reply to Mr B
    Mr B:
    Anonymous:
    I code in pure ASM. I use a lot of comments. Do I have got to do it again sir?

    Yup, sorry, even in ASM if you need comments in the code, then the code needs re-writing. The pseudo-logic for ASM belongs outside codebase comments. If someone handed me ASM with comments but no pseudo-code I'd throw it back at them.

    Note that my gripe was with "comments" not "documentation", and the sort of comments I usually see with ASM coders are along the lines of:

    Label1: mov ax, bx ;we move bx into ax add ax, bx ;add the contents of bx into ax ...

    Yup, that's really adding value there! Adding about the same amount of value as:

    //--- get first character of date make sure its less than 4 ---// posit0 = userdate.value.charAt(0) if (posit0 < "0" || posit0 > "3")

    When it's checking if it's less than 0 or greater than 4, rather than it being less than 4. So the comments don't actually match the code anyway, marvellous!

    So without even seeing my code you're telling me that because it contains comments the whole thing needs to be re-written? Quick question: are you high or something? I've usefully noted the contents of various registers at various key points in the code and you think I need to rewrite it - without comments??? Sorry my friend, I thought we were having a serious conversation but obviously you're a complete nutter!!

  • me (unregistered) in reply to Richard W.

    Nerds are bad at handling dates, isn't it clear :-)

    "The rest of us" really wonders why validating a date with any sort of hammer wouldn't be a federal crime

    Thanks, I'll be here all night!

  • (cs) in reply to Will
    Will:
    The more important question is how much you're get pay'd for. If you want such a Job - go ahead, for $10 a month you can write it for me, I'll post hear :-)
    For $10, I'll teach you about apostrophe usage, capitalization, and homophones.
  • hims (unregistered) in reply to CodeRage
    CodeRage:
    Even worse are US State pickers... having to go through a whole drop-down list when I could just type TWO LETTERS.

    UGH WTF.

    I've seen bank logon pages which force you to enter passwords by selecting from a different dropdown each number or letter, and request forms which force you to enter 12 digit codes by choosing 1-9 from 12 different dropdown menus.

    If I had goggles for my brain and I tried to understand why, they'd still do nothing.

  • dividius (unregistered) in reply to Voodoo Coder
    Voodoo Coder:
    posit9 > "9"

    Does anyone else see anything just a bit hilarious with that line?

    How many single characters are greater than 9?

    At least 70, inluding..

    Decimal Octal Hex Binary Value


    057 071 039 00111001 9 058 072 03A 00111010 : 059 073 03B 00111011 ; 060 074 03C 00111100 < 061 075 03D 00111101 = 062 076 03E 00111110 > 063 077 03F 00111111 ? 064 100 040 01000000 @ 065 101 041 01000001 A 066 102 042 01000010 B 067 103 043 01000011 C ... 122 172 07A 01111010 z 123 173 07B 01111011 { 124 174 07C 01111100 | 125 175 07D 01111101 } 126 176 07E 01111110 ~ 127 177 07F 01111111 DEL

  • (cs) in reply to hims

    [quote user="hims"][quote user="CodeRage"] I've seen bank logon pages which force you to enter passwords by selecting from a different dropdown each number or letter, and request forms which force you to enter 12 digit codes by choosing 1-9 from 12 different dropdown menus.

    If I had goggles for my brain and I tried to understand why, they'd still do nothing.[/quote]

    You don't need goggles to understand the logic....

    One word: Keyloggers

    Now, is a drop down menu the best solution? Of course not. If fact, it's one of the worst. I've seen banks create an on-screen keyboard, and that was a pretty smart solution to a real security problem. But a drop down...well, that's not really solving much of any problem since people like me tab through fields and use the keyboard to select items in a drop down.

  • wiki-freak (unregistered) in reply to Nick J

    Go french!

    http://en.wikipedia.org/wiki/Decimal_time#France

    They actually proposed having decimal time way back then in 1793. Days would have had 10 'hours', of 100 'minutes' each, of 100 'seconds each'.

    Working upwards, they also proposed the

    http://en.wikipedia.org/wiki/French_Republican_Calendar

    where years had 12 months of 30 days each, with 3 10-day weeks per month, and the 5 or 6 extra days clumped together at the end of the year.

    Of course, it failed miserably.

  • Dennis (unregistered) in reply to Nick J
    Nick J:
    Isn't is about time we decimalised time?

    1 s = 1 second 1 ks = 1000 seconds (16 mins 40 secs) 1 Ms = 1e6 seconds (11 days 13 hours 46 minutes 40 seconds)

    etc...

    There's nothing stopping you. In fact it's used all the time for measuring time intervals. It's referred to as metric time. But since it doesn't correspond to any natural periods, it'd be inconvenient for clocks, for example.

    Decimal time, on the other hand, is based on division of the day by powers of 10 and would be just as viable as the current system, but, as in the past, its adoption would be unlikely.

    See also decimal calendar.

  • (cs) in reply to Voodoo Coder
    Voodoo Coder:
    posit9 > "9"

    Does anyone else see anything just a bit hilarious with that line?

    How many single characters are greater than 9?

    Did the user enter the shorthand for infinity into a date field? Or perhaps he was just checking for Roman Numerals...?

    JavaScript converts strings into numbers when they are used with any operator other than concatenation/addition.

    http://www.jibbering.com/faq/faq_notes/type_convert.html#tcNumber

  • me (unregistered) in reply to Mr B
    Mr B:
    Yup, that's really adding value there! Adding about the same amount of value as:

    //--- get first character of date make sure its less than 4 ---// posit0 = userdate.value.charAt(0) if (posit0 < "0" || posit0 > "3")

    When it's checking if it's less than 0 or greater than 4, rather than it being less than 4. So the comments don't actually match the code anyway, marvellous!

    Well, yours certainly doesn't.

  • Dirk Diggler (unregistered) in reply to operagost
    operagost:
    Will:
    The more important question is how much you're get pay'd for. If you want such a Job - go ahead, for $10 a month you can write it for me, I'll post hear :-)
    For $10, I'll teach you about apostrophe usage, capitalization, and homophones.
    Please leave the gayz out of this.
  • (cs) in reply to anonymous
    anonymous:
    Any reasonable browser will allow you to click on the field and type the first few letters of the state you're looking for.
    I agree that this works, but it's suboptimal. It bugs me to type "TE" to get Texas when I should be typing "TX". Also there are multiple states whose names start with "Mi", "New ", "North ", "South ", etc. All of this defeats the purpose of standardized abbreviations. Maybe the pull-down list boxes should contain entries of the form "AL: Alabama", "AK: Alaska", "AZ: Arizona", "AR: Arkansas", etc. They wouldn't have to be sorted by abbreviation, so they would still read "naturally" to someone using the mouse to make a selection.
  • Atlantys (unregistered) in reply to Dennis
    Dennis:
    Nick J:
    Isn't is about time we decimalised time?

    1 s = 1 second 1 ks = 1000 seconds (16 mins 40 secs) 1 Ms = 1e6 seconds (11 days 13 hours 46 minutes 40 seconds)

    etc...

    There's nothing stopping you. In fact it's used all the time for measuring time intervals. It's referred to as metric time. But since it doesn't correspond to any natural periods, it'd be inconvenient for clocks, for example.

    Decimal time, on the other hand, is based on division of the day by powers of 10 and would be just as viable as the current system, but, as in the past, its adoption would be unlikely.

    See also decimal calendar.

    Given that Americans still don't use metric, updating our time system will never occur.

    I mean, really, how difficult is it to use metric? I hate having to handle both imperial and metric.

  • iMalc (unregistered)

    I've also previously maintained a program that was originally written by someone who left a similar marking at the top of the file, called Tony B. It was aparently Tony B's first Visual Basic program. If it's the same person, he's gone neither forwards nor backwards.

  • Oxyd (unregistered) in reply to me
    me:
    Mr B:
    Yup, that's really adding value there! Adding about the same amount of value as:

    //--- get first character of date make sure its less than 4 ---// posit0 = userdate.value.charAt(0) if (posit0 < "0" || posit0 > "3")

    When it's checking if it's less than 0 or greater than 4, rather than it being less than 4. So the comments don't actually match the code anyway, marvellous!

    Well, yours certainly doesn't.

    Even better is that the line actually does what it advertises if you put it in the context it's in:

    if (posit0 < "0" || posit0 > "3") { alert("date contains invalid DAY default value set") ...

    It does make sure it's less than 4 (and greater or equal to 0) -- only it's in negative logic and if the condition is not met, it enters the body -- which then alerts the user and dies.

  • (cs) in reply to Zecc
    Zecc:
    Phill:
    Off topic but if Alex is reading can you please use this formatting for all future code posts? It is the first time I have had code formatting maintain line breaks in my RSS reader.
    I second this comment.
    And, if Alex is reading, can you please STOP POSTING HUGE ARTICLES AS SUMMARIES? Try to keep the front page shorter... I almost broke my finger rolling the mouse wheel to get to the lower comments. THANK YOU!
  • asdf (unregistered)

    That's why I only use Unix timestamps for date/time entry fields. Pfft... noobs.

  • Sanity (unregistered) in reply to rohypnol
    rohypnol:
    Jok:
    Anyway, Javascript validation is completely useless.
    No, it's not. Client-side validation is as mandatory as server-side validation.
    I'm going to say, no, it's not.

    Useful? Sure! And I agree, it is annoying to have to manually check back with the server, as opposed to some AJAXy method.

    But mandatory? Consider:

    If there is no client-side validation, some of your customers get pissed.

    If there is no server-side validation, you've got a GIGANTIC FUCKING GAPING SECURITY HOLE.

    One will annoy some users, and maybe waste a little bandwidth. The other will compromise your system, and very possibly expose your users to risk.

    Since they're not mutually-exclusive, you do want both. But I would say the security is mandatory, and the convenience is just convenient.

  • moshbox (unregistered) in reply to Mr B
    Mr B:
    fred34:
    Indeed, for some incredibly naive coding and general bad design, the documentation is better than most WELL written production code!

    Well written production code doesn't need any comments.

    If your code NEEDS lots of comments, then it NEEDS re-writing. If you NEED comments to understand code, then you NEED to learn how to code.

    Who says comments are to help the author understand his or her own code? I lace my stuff with comments simply to avoid being calling in on my vacation.

  • (cs) in reply to Sanity
    Sanity:
    Since they're not mutually-exclusive, you do want both. But I would say the security is mandatory, and the convenience is just convenient.
    Well, I would say the same thing, but your typical customer will make the opposite call. This is why you shouldn't give the customer exactly what they ask for; sometimes, you should also give them what they should have asked for as well…
  • Anonymoos (unregistered) in reply to Anonymous coward
    Anonymous coward:
    Graham Stewart :
    TRWTF is that Date.getMonth() is apparently zero-indexed... why??

    Because arrays, at least in .Net, are zero-indexed ofcourse, eg. ArrayofMonthNames[d.GetMonth()]

    But why is it then, that daynumbers and yearnumbers are 1-based?

  • (cs) in reply to virgil
    virgil:
    Not that I want to defend this code, but a read-only field+ datetimepicker can be less user-friendly... sometimes it's much more productive to do data entry by manually keying in the data, rather than moving the mouse around to select the proper value. What I'm saying is that Catherine's solution is not "obviously better", it's just simpler and less bug-prone :)
    Just because you use a manual entry (which I allow for both manual and clicky-click) doesn't mean you have to be a retard about processing the date. It is easy to use something like SimpleDateFormat to attempt to validate the date using the parse method. Not all that hard and can be done is oh about 3-5 lines of code and will validate both manual and clicked.
  • I have some SAE adjustable wrenches too (unregistered) in reply to Atlantys

    The Metric system is an invention of the french with the adoption thereof enforcable by death. So it caught on fast...in france. Realizing it would go about nowhere without international support they made a deal with England for the Prime Meriden. The original metric prime meridian would have run through paris. The English would have none of that poppycock, there maps weren't drawn that way and "Britannia rules the seas" you know. Somehow the french compromised our meter for your meridian.

    The metric system has made strides in education because the lazy students frustrate the lazy teachers into giving up on them. Not because the bright scientific students can't +-*/ by 12! Therefore I have no sympathy for "computer guys" who can't add, subtract, multiply or divide by 12 and especially 16! Are you that [email protected]#$%^& Lazy? Are you an art major?

    Don't get me started, wait..., starting now... on how it is all based on the imperial system to begin with! If it wasn't the meter would be 1,000,000 wavelengths of some thing not some seemingly pseudo-random 1,650,763.73 wavelengths of orange-red light <snip> just so the conversion would still line up. Why not 1E6 or 2E6 wavelengths? This was a stopgap to have a more "scientific" definition of the crap. Garbage in, garbage out. The original definition was based on time so we see the whole system was dependant on the "English second."

    The conversion was clever actually. 2.54 cm/ inch and 39.37 in/m both being exact is cool. Except anyone who can multiply and divide and know that there are 100 cm/m will see that these two EXACT conversions don't line up. Exact as defined by everyone to the point it is common knowledge. <insert conspiricacy theory here>

    Measurement is arbitrary. Light-years are pretty good. At least they didn't base it on the distance from one corner of the earth to another. (The falling water would have eroded the edge over time of course. ;-)

    In the end meter or E-meter, whatever, it's a crock of contrivance.

    On another note:
    I'd love to code ASM all day. I endorse meaningful comments. Coders should be more professional about their work, quit your whining, get to work. Would you rather be unemployed right now?

    captcha="quibus" doesn't that have something to do with a quibble or fight? :-)

  • dork (unregistered) in reply to Dazed

    This was also the first thing that came to my mind. If there is a server side validation, then it is OK, though redundant. Some devs tend to forget that there are people who are not so into the Web 2.0 thingy / besides the security implications. But doing stuff twice seems to be a good occupation for bored developers, especially the maintenance of this stuff.

  • (cs)

    So... when encountering some piss-poor javascript, programmer replaces is with something inaccessible?

    Please tell me that this new "read only" field is set to "read only" only AFTER it's clear that the javascript date picker is going to work...

    followed by server-side validation...

  • matt (unregistered) in reply to I have some SAE adjustable wrenches too

    So the metric/english argument went stale what one or two hundred years ago?

    But lazy people do irk me. Heaven forbid you look up a funcion in the standard library of anything. unless you're paid by the line.

  • Bob (unregistered) in reply to CodeRage
    CodeRage:
    Almost every form that requires a date also requires keyboard entry also (first name, etc), so why do these genius UI people think that it is somehow more friendly to force the user to click on the mouse 30-50 times to pick a birthdate, rather than just type it in?
    Ok, here's the real WTF.

    You're being very very clever and demonstrating an amazing mastery of the fine art of sarcasm, but if these "genius UI people" actually are as awful as you think they are, then what on earth makes you think they'll be any better at handling dates typed in by a user?

    Yes, you're right, a badly designed calendar control isn't better than a badly designed text validator. So? One would assume, if one was smart, that a well designed control would be used.

    Of course, "well designed" and "web 2.0" seem to go together like bicycles and refrigerators, so maybe the real WTF is expecting high quality in the first place.

    (Also, this "30-50 times" nonsense, is, well, a slight exaggeration. Maybe once to say you want to enter a date, a couple of times to pick a year, once for a month, and once for a day. That's 5 clicks. As compared to a mimimum of 6 - 8 keypresses (4 for year, 1 or 2 for month, and 1 or 2 for day) for typing the date in, plus you have to remember what format the website expects, or have some magic code that can tell if 01/02/03 is january the second 2008, or february the third, 2001 by reading the user's mind.

    Because we all know that the real WTF is a website that doesn't demand the user use the exact same date format as god in heaven and the website's designer have agreed on.

  • tony b (unregistered)

    thanks for the moral support guys

  • santa.Deliver() (unregistered) in reply to Anonymoos
    Anonymoos:
    Anonymous coward:
    Graham Stewart :
    TRWTF is that Date.getMonth() is apparently zero-indexed... why??

    Because arrays, at least in .Net, are zero-indexed ofcourse, eg. ArrayofMonthNames[d.GetMonth()]

    But why is it then, that daynumbers and yearnumbers are 1-based?

    Because "The 11 Days of Christmas" sounds weird.

  • Phil (unregistered) in reply to Mr B
    Mr B:
    fred34:
    Indeed, for some incredibly naive coding and general bad design, the documentation is better than most WELL written production code!

    Well written production code doesn't need any comments.

    If your code NEEDS lots of comments, then it NEEDS re-writing. If you NEED comments to understand code, then you NEED to learn how to code.

    Self explanatory code is nice and all, but there are a lot of times when something [ican[/i] be done in multiple ways. In that case, unless it truly doesn't matter which way it's done in a given program, comments are a godsend so I can see why you did it the way you did it, and sometimes more specifically why you didn't do it a different way (e.g., a non-obvious idiosyncracy that popped up that would be nice to know about as I do further work on the program).

    Something like "x = 5; // set x to 5" is useless but "comments" and "useless comments" aren't the same thing. Comments---documentation in the source files---are definitely a good thing.

    TDD Chauvinist:
    The only real WTF is the apparent lack of comprehensive unit tests. The problem with leap years, for example, is only possible because the coder didn't write his tests first.

    In a very real sense, I don't care how gnarly the code is, as long as it's well tested. Why should I have to look inside the date validation code at all? It should be an opaque box to me... One in which I have confidence because it's well tested.

    I'd also like to echo a previous poster's observation that replacing this code with drop downs is not necessarily an improvement. Sure it makes life easier on the coder, but it possibly does so at the expense of the user. It's hard to imagine the universe in which that's a good trade off.

    It's starting to bother me that we WTF posters are more concerned with nitpicking lousy code than with the bad practices (or absence of good practices) that make it possible. Lousy code is no longer entertaining to me, and I don't think I'm learning much from it.

    This would not be fixed if the coder wrote his tests first. Leap years aren't handled because he never even thought of them. What magic is going to make him think of leap years when writing the test if he didn't think of them when writing the code? Ok, you specified the lack of "comprehensive" tests as the problem, but what makes you think the guy who couldn't write comprehensive code would write comprehensive tests?

  • Phil (unregistered) in reply to I have some SAE adjustable wrenches too
    I have some SAE adjustable wrenches too:
    The metric system has made strides in education because the lazy students frustrate the lazy teachers into giving up on them. Not because the bright scientific students can't +-*/ by 12! Therefore I have no sympathy for "computer guys" who can't add, subtract, multiply or divide by 12 and especially 16! Are you that [email protected]#$%^& Lazy? Are you an art major?

    LOL. I can't understand why a "computer guy" would be saying crap like this.

    Sure, I can keep track of my 1/8, 3/8, 5/16, 5/32, etc, drill bits and wrenches, but I don't want to. Doing so doesn't help the job get done any better or any faster. I'd much rather be using my metric wrenches where you go 4mm, 5mm, 6mm, and so on instead of dealing with a bunch of fractions with inconsistent denominators (which is probably the real WTF when it comes to wrenches. Just doing everything with regard to 64ths seems like it would be much nicer.)

    Sorta like how I could write everything in assembly, but it would just be a bunch of wasted effort not helping get the job done any better. Though even this is more sensible than our measurement system, since going that low-level might result in a program that runs significantly faster, while I don't see any such benefit to having to deal with feet, inches, and weird-ass fractions when working with my tools.

    Yes, I'm that lazy. But you say that like it's a bad thing. Why not use the tools that let the job be done the quickest, with the least complexity? These days, laziness is the mother of invention.

  • BillyBob (unregistered)

    I love it when people put their name on source code. Even better, dated as well. All it needed was a signed bug fix somewhere.

    Maybe one day we won't have a need for such things and software will track all changes and who made them for us

  • (cs) in reply to Bob

    Could be worse. I misread the truncated title in my RSS feed as "Validating a date with Sleep()".

    Bob:
    or have some magic code that can tell if 01/02/03 is january the second 2008, or february the third, 2001 by reading the user's mind.
    TRWTF is date formats in which "01/02/03" is a day in 2008.

  • mikeo (unregistered)

    imagine how much fun this would be in lisp

  • Dan (unregistered) in reply to CodeRage
    CodeRage:
    Even worse are US State pickers... having to go through a whole drop-down list when I could just type TWO LETTERS.

    UGH WTF.

    Well I just go and type the two letters. On Windows, in a Combobox (HTML <select> element), opened or not, typing letters will select the first entry your typing matches. Always works for me.

  • Code Monkey (unregistered) in reply to Mr B
    Mr B:
    fred34:
    Indeed, for some incredibly naive coding and general bad design, the documentation is better than most WELL written production code!

    Well written production code doesn't need any comments.

    If your code NEEDS lots of comments, then it NEEDS re-writing. If you NEED comments to understand code, then you NEED to learn how to code.

    Wow you must be quite the superstar.... People who say code doesn't need comments are idiots. People who say programmers shouldn't need to read comments are the same.

    Code ALWAYS needs comments - I add comments because the next monkey to look at tis code might be too stupid to understand what's going on. I hope the person before me adds comments, so that when they use clever short cuts I can actually understand what they are trying to acheive (perhaps more to the point, I hope the person before me comments code, because I don't trust them enough to have actually done things properly - I like them to document their intent - what the code does, and what the code was meant to do can be two seperate things. Saying "Any programmer should understand this code" ia all beaut and fine - but just because I can understand what a piece of code does, doesn't mean I can understand what a piece code is meant to do....)

    I assume you were just being a tad facetious (that's shitful - from the latin: faeces) If, on the other hand you are serious, then to me it shows a severe lack of understnading of how the world works.

    (I'll even say Comprehensive) Comments are imperative because: a) You don't know what monkey will need to maintain your code (and them not understanding it will be blamed on you) b) You can't trust the monkey who writes code you have to maintain actually knew what they were doing c) It makes it more readable for the non-techo (not always important - but a lot of managers like to think they can read well commented code, and understand that you ARE doing the job they hired you for) d) (Probably a paraphrase of b mixed with a) Just because it is bleedingly obvious (to you) what your code does, doesn't mean that it's obvious to someone else - -nor does it mean that it does what you intended....

    Anywho, I'm off to eat some bananas

  • Johnno (unregistered) in reply to Graham Stewart
    Graham Stewart:
    Anonymous coward:
    Graham Stewart :
    TRWTF is that Date.getMonth() is apparently zero-indexed... why??

    Because arrays, at least in .Net, are zero-indexed ofcourse, eg. ArrayofMonthNames[d.GetMonth()]

    Well yeah, but that's not really a very good reason though is it? If I set the date as February then I'd expect the month to be two, not one.

    I mean isn't it less of a leap to just do:

    ArrayofMonthNames[d.GetMonth() - 1]

    Than to have:

    mydate = new Date("25/01/1975")
    year = mydate.getFullYear()  // 1975
    day = mydate.getDate()       // 25
    month = mydate.getMonth()    // 0 ?!

    As you say, .NET arrays are zero-indexed, but in .NET the month of January is still 1 (System.DateTime.Month).

    Hmmm...Now might be a great time to reopen the "Magic Numbers" debate..... Sure some languages have odd quirks in how they represent dates (Java has several date/calendar type classes that are a real mess - and are inconsistent with each other).... If the language chooses to represent February as 1, create a constant to represent February - then you don't need to worry about the number being out of sync....

    This is why we avoid Magic Number, people....

    Here endeth the lesson

  • More Monkeys.... (unregistered) in reply to Mr B
    Mr B:
    Anonymous:
    Mr B:
    fred34:
    Indeed, for some incredibly naive coding and general bad design, the documentation is better than most WELL written production code!

    Well written production code doesn't need any comments.

    If your code NEEDS lots of comments, then it NEEDS re-writing. If you NEED comments to understand code, then you NEED to learn how to code.

    I code in pure ASM. I use a lot of comments. Do I have got to do it again sir?

    Yup, sorry, even in ASM if you need comments in the code, then the code needs re-writing. The pseudo-logic for ASM belongs outside codebase comments. If someone handed me ASM with comments but no pseudo-code I'd throw it back at them.

    Note that my gripe was with "comments" not "documentation", and the sort of comments I usually see with ASM coders are along the lines of:

    Label1: mov ax, bx ;we move bx into ax add ax, bx ;add the contents of bx into ax ...

    Yup, that's really adding value there! Adding about the same amount of value as:

    //--- get first character of date make sure its less than 4 ---// posit0 = userdate.value.charAt(0) if (posit0 < "0" || posit0 > "3")

    When it's checking if it's less than 0 or greater than 4, rather than it being less than 4. So the comments don't actually match the code anyway, marvellous!

    I must disagree most vehemently..... Granted the code is checking that a value is less than 0 or greater than 3, but commenting it like that is EXACTLY what you are bagging ASM comments about above.... The comment explains (or attempts to explain) the purpose of the test - that is, to make sure we have a positive (oops, he missed that bit) value less than 4....

    Comments should explain what is acheived (or attempt thereof) by that line, not exactly how the line does it.... You seem to realise this in your comments about comments in ASM ( ;move ax to bx....). Surely commenting this code as "Check whether value is less than 0 or greater than 3" is exactly the same mistake you highlight with the ASM. The comment there explains WHAT is being acheived not HOW it is being done (admittedly, it may be more useful to explain WHY we need to check this)...Sure, it's an obvious comment abut an obvious piece of code, bu comments are harmless....If you are "De Man" and can interpret the code (and the coders intentions) simply by staring at the code, feel free to ignore all comments.... You could always write a program to strip them all out for you, anyways (or find an IDE that allows you to fold them over nicely so they disappear)....

  • Wretch (unregistered)

    Tony B then moved on to his next project; creating a circular device that is capable of rotating on its axis to facilitate movement or transportation whilst supporting a load.

  • Achoo (unregistered) in reply to amischiefr
    amischiefr:
    virgil:
    Not that I want to defend this code, but a read-only field+ datetimepicker can be less user-friendly... sometimes it's much more productive to do data entry by manually keying in the data, rather than moving the mouse around to select the proper value. What I'm saying is that Catherine's solution is not "obviously better", it's just simpler and less bug-prone :)
    Just because you use a manual entry (which I allow for both manual and clicky-click) doesn't mean you have to be a retard about processing the date. It is easy to use something like SimpleDateFormat to attempt to validate the date using the parse method. Not all that hard and can be done is oh about 3-5 lines of code and will validate both manual and clicked.

    More to the point (and I'll crawl back under my rock If I'm wrong), can't you add a validator to a text box - so that it only allows valid things to be entered (ie validates the text AS it's entered.......)

  • (cs) in reply to More Monkeys....
    More Monkeys....:
    that is, to make sure we have a positive (oops, he missed that bit) value less than 4....

    It doesn't make sure we have a positive value, it makes sure that we have a character that is one of "0", "1", "2", or "3". We are comparing character values here, not numeric values.

    More Monkeys....:
    bu comments are harmless....
    Actually comments can be VERY harmful, especially if you read and TRUST only the comment. The problem with comments is they tend to get out of sync. If you get a piece of code, what is correct, the comment or the code? I'm not saying comments are bad, and that we shouldn't use them. But comments should be used sparingly. Well written code trumps a bad comment any day.
  • Been tried (unregistered) in reply to Nick J
    Isn't is about time we decimalised time?

    I think they tried that in the French Revolution, but it didn't stick.

    Actually, a 60-based time system has some advantages. You can easily divide 60 by 2, 3, 4, 5, 10, 20, and 30 without much thought. 100-minute horus would require more math.

  • Nostradamus (unregistered)
    if (dday > "28" && mmnth == "02" )
    It's a good thing those "leap years" never made it into practice.
  • (cs) in reply to TDD Chauvinist
    TDD Chauvinist:
    The only real WTF is the apparent lack of comprehensive unit tests. The problem with leap years, for example, is only possible because the coder didn't write his tests first.

    What makes you think there are no unit tests? With one exception the code works, and works as designed. It is a bad design, and it is bad code. But it works.

    The coder forgot about leap year. Why do you think he would have magically remembered if he had written the test first?

    I'm going to say that the problem with leap years, for example, is only possible, because the coder FORGOT about leap years.

    A good majority of the code we see here is broken. Sometimes a unit test would have found the problem, shoot sometimes just USING the product would have found the problem. But sometimes the code we get works. It is still WTFy code, and is still amusing to see.

    WTFs happen because people are stupid. They happen in any language, and happen with any tools, or process. TDD is a WTF in itself, and will generate just as many, or more WTFs as non TDD.

  • (cs) in reply to virgil
    virgil:
    Not that I want to defend this code, but a read-only field+ datetimepicker can be less user-friendly... sometimes it's much more productive to do data entry by manually keying in the data, rather than moving the mouse around to select the proper value. What I'm saying is that Catherine's solution is not "obviously better", it's just simpler and less bug-prone :)

    Making the entry Read Only and relying on the datepicker is definitely a WTF.

    I was at a hotel one time, and needed to check on my flight. I went to the website and was only able to use the datepicker. Unfortunately the time on the computer was off by about 5 years. Since I couldn't type in the date, nor change the time, my only option was to click through 60+ plus months!

Leave a comment on “Validating a Date with a Sledgehammer”

Log In or post as a guest

Replying to comment #:

« Return to Article