• JBert (disco)
    (Program.Year < 2050)
    

    Most likely the fresh programmer would have thought that he'd be in retirement by then and that somebody else can maintain this code.

  • Ext3h (disco)
    if ((textBox1.Text.Length == 1) || (textBox1.Text.Length == 2) || (textBox2.Text.Length == 4))
    

    should have been

    if (((textBox1.Text.Length == 1) || (textBox1.Text.Length == 2)) && (textBox2.Text.Length == 4))
    

    In addition to the messed up, wrongly inverted "digitornot" logic.

    If it wasn't for these two mistakes, the script would actually have worked as expected. Well, if the "digitornot" logic had been used correctly, that check would even be unnecessary.

  • gvanvoor (disco) in reply to Ext3h

    So basically you're saying: were it not for the bugs it would have worked?

  • isthisunique (disco)

    Could be worse.

    I once saw something such as, valid = input in range 2000 2050.

    This approach wasn't so bad and is the kind of thing I occasionally do myself, but when it came to validating full dates, usernames, etc...

  • PWolff (disco) in reply to Ext3h
    Ext3h:
    should have been ` if (((textBox1.Text.Length == 1) || (textBox1.Text.Length == 2)) && (textBox2.Text.Length == 4)`

    Can be simplified to

    if (false)
    

    Edit: I forgot to say this makes perfect sense in context

  • dkf (disco)
    Comment held for moderation.
  • dkf (disco) in reply to PWolff
    PWolff:
    Can be simplified to
        if (false)
    

    No. You're mixing up between textBox1 and textBox2.

  • PWolff (disco) in reply to JBert
    JBert:
    (Program.Year < 2050)

    Most likely the fresh programmer would have thought that he'd be in retirement by then

    Not necessarily. Remember how unimaginably far away year 2000 was in 1975?

    dkf:
    No. You're mixing up between textBox1 and textBox2.
    Oops.
  • WernerCD (disco) in reply to PWolff
    Comment held for moderation.
  • operagost (disco)

    One of the popular workarounds for two-digit years during the Y2K remediation was to assume that dates beyond a certain cutoff belonged to the previous century, e.g. "49" was 2049, but "50" was 1950. Their software may have been using 50 as a cutoff. Of course, it makes no sense to do this, then not accept any dates before 2000, but when you have a programmer this bad I'd expect him to be incapable of understanding requirements.

  • PJH (disco)

    This topic is now listed. It will be displayed in topic lists.

  • Eldelshell (disco)
    foreach (char x in textBox1.Text + textBox2.Text)
    {
        if (Char.IsDigit(x))
        {
            digitornot = 1;
        }
    }
    

    When all you have are hammers everything looks like nails.

  • CodeSlave (disco) in reply to dkf
    dkf:
    No. You're mixing up between `textBox1` and `textBox2`.

    Which is why not changing the default name on any of his input fields to something meaningful is such a maintenance a nightmare.

  • accalia (disco) in reply to PJH
    PJH:
    This topic is now listed. It will be displayed in topic lists.

    Paula's MIA again?

  • FullPointerException (disco) in reply to accalia

    PJH is just short for Paula's Job Helper. She's delegating.

  • CoyneTheDup (disco)
    Comment held for moderation.
  • levesque (disco)

    The check for digits will allow all kinds of crud through

    I don't think this is true... Char.IsNumber would let all kinds of crud through but I believe IsDigit will function as the original developer intended. FWIW.

  • shenghi (disco) in reply to levesque

    Except if there's a single digit, then isdigitornot will be 1. So this code will let 1a bcde pass. Looks like crud to me.

  • levesque (disco) in reply to shenghi

    Oh, ha ha, my bad... I missed a lot of WTF when I skimmed over that code.

  • RFoxmich (disco) in reply to Eldelshell
    Comment held for moderation.
  • YellowOnline (disco)

    Luftballons should be with a capital letter, like all German nouns. /application for pedantic knight etc.

  • antiquarian (disco) in reply to YellowOnline
    YellowOnline:
    /application for pedantic knight etc.

    Application denied. Not dickweedish enough.

  • tenshino (disco)

    Um... it looks like C#, in which case this is all you need:

    private void button1_Click(object sender, EventArgs e)
    {
        DateTime dt;
        if(!DateTime.TryParse(textBox1.Text, out dt))
            MessageBox.Show("Wrong input!\r\nCheck format!");
        else
            this.Close();
    }
    

    I would then recommend doing some kind of masking on the textbox itself, to force users to enter something sane: __/__/____

  • Rich_Way (disco)

    I'd point out too that having gone to the trouble of checking for four specific errors, the author doesn't bother to differentiate the errors in the message given back to the end-user!

  • redwizard (disco) in reply to Eldelshell
    Eldelshell:
    When all you have are hammers everything looks like nails.

    "What do you mean, LOOKS LIKE? They ARE f----- nails!!" said the hammer.

  • Nprz (disco)
    Comment held for moderation.
  • SimpleSimon (disco)

    As somebody pointed out, this is C# web/win forms, and since DateTime.TryParseExact() has been around since .NET 2.0 this entire code is pretty much redundant.

  • Maciejasjmj (disco) in reply to levesque
    levesque:
    IsDigit will function

    BZZT!

    Valid digits are members of the UnicodeCategory.DecimalDigitNumber category

    So something like, say, EXTENDED ARABIC-INDIC DIGIT NINE still passes the test.

  • obeselymorbid (disco)

    int digitornot = false; //I don't dig this code

  • obeselymorbid (disco) in reply to Maciejasjmj
    Maciejasjmj:
    >Valid digits are members of the UnicodeCategory.DecimalDigitNumber category

    So something like, say, EXTENDED ARABIC-INDIC DIGIT NINE still passes the test.

    TR :wtf:

    I fail to see any circumstances where that behaviour would be useful.

  • dkf (disco) in reply to obeselymorbid
    obeselymorbid:
    I fail to see any circumstances where that behaviour would be useful.

    That depends whether it is understood as a 9 for the purposes of parsing a number. If it is, it's probably useful in some languagewriting system but not necessarily one you use.

  • obeselymorbid (disco) in reply to dkf
    dkf:
    whether it is understood as a 9 for the purposes of parsing a number.

    Well, if it does, then this will remain true AFAIUI:

    levesque:
    IsDigit will function as the original developer intended.
  • gnasher729 (disco)

    Totally annoyed with the variable name "isDigitOrNot". Should always be set to true, because every character is a digit or not. Correct name according to the code would have been "atLeastOneDigit". This would match the code setting the variable, and would make it clear that testing for this variable is nonsense.

  • dkf (disco) in reply to obeselymorbid

    The stupid thing is that the best approach for dealing with all this is to just parse the numbers and handle the exceptions (or TryParse if using C#; same general idea). Stop trying to second-guess the parsers when you can just use the real ones and have everything work right.

    But that would be too much to ask and so we get this sort of stupidity happening over and over. It's even worse with file handling, as it introduces race conditions as well, but it's the same brokenated concept of “errors are always catastrophic so try to avoid at all costs”. Grrrr…

  • Jonathan_Harston (disco)

    And! He's shouting! At the user!

  • Maciejasjmj (disco) in reply to obeselymorbid
    Comment held for moderation.
  • PWolff (disco) in reply to redwizard
    redwizard:
    f----- nails
    Since when is "finger" a filtered word?
  • PWolff (disco) in reply to RFoxmich
    Comment held for moderation.
  • dkf (disco) in reply to Maciejasjmj
    Maciejasjmj:
    I'm not sure if it's just a plain MS fuckup or if there's logic behind it

    I'll take some of column A and some of column B, please. :confused:

  • PWolff (disco) in reply to JBert
    JBert:
    Most likely the fresh programmer would have thought that he'd be in retirement by then and that somebody else canis doomed to maintain this code.
    FTFY
  • accalia (disco) in reply to YellowOnline
    Comment held for moderation.
  • blakeyrat (disco) in reply to accalia

    Dude.

    The English version contain the lyrics, "everyone's a superhero, everyone's a Captain Kirk", which is so far superior than anything ever created in German ever.

  • narbat (disco)

    The submitter has no idea why the year is being compared to 2050. Presumably, the Rapture will happen before then, so no future dates need be considered beyond that point.

    The Rapture is scheduled for 2038-01-19 03:14:08 UTC. It's a Tuesday. I thought everyone knew that?

  • ben_lubar (disco) in reply to tenshino
    Comment held for moderation.
  • swayde (disco) in reply to Maciejasjmj
    Comment held for moderation.
  • Bulb (disco) in reply to isthisunique
    Comment held for moderation.
  • aliceif (disco) in reply to narbat
    Comment held for moderation.
  • PWolff (disco) in reply to tenshino
    tenshino:
    to force users to enter something sane: \_\_/\_\_/\_\_\_\_
    Have fun with MM/DD/YYYY vs. DD/MM/YYYY. (Unless the application is intendedsure to be used in only one culture.)

    At least it will not be very likely that some user will try to enter something like 11:48:13AM.

  • dkf (disco) in reply to PWolff
    PWolff:
    Have fun with MM/DD/YYYY vs. DD/MM/YYYY.

    It's a solved problem. (Except in the USA.) Or you can do the right thing and use YYYY/MM/DD. :D

  • PWolff (disco) in reply to dkf
    dkf:
    Or you can do the right thing and use YYYY/MM/DD

    ISO compliance is SOOOOO 1990. :stuck_out_tongue:

Leave a comment on “You've Got My Number”

Log In or post as a guest

Replying to comment #:

« Return to Article