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

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

  • (disco) in reply to Ext3h

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

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

  • (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

  • (disco)

    Article is up, but Discourse isn't listing it. Paula Bean has broken things. Again.

    @PJH or @boomzilla — Fix please?

  • (disco) in reply to PWolff
    PWolff:
    Can be simplified to
        if (false)
    

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

  • (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.
  • (disco) in reply to PWolff

    75 to 00... vs 00 to 50... His code will last TWICE AS LONG!

    So we should praise this programmer for being more forward thinking than past programmers.

    That being said... talk about a cluster @$#% in a code fragment...

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

  • (disco)

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

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

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

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

    Paula's MIA again?

  • (disco) in reply to accalia

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

  • (disco)

    Most of the functional WTF of this can be fixed with a handful of minor changes:

        int digitornot = 0;            //  ===> Assume not all digits
        if (((textBox1.Text.Length == 1) || (textBox1.Text.Length == 2)) && (textBox2.Text.Length == 4))  // ===> per @Ext3h 
        { 
            digitornot = 1;            //  ===> Assume all digits to start loop
            foreach (char x in textBox1.Text + textBox2.Text)
            {
                if (!Char.IsDigit(x))  // ===> Not digit
                {
                    digitornot = 0;    // ===> Indicate something was not a digit
                }
            }
    

    Not saying the whole thing isn't a general WTF. But functionally, it's only a bit off (holds nose) and could be fixed fairly easily. Now, all the naming and other assorted WTFery, well, left as an exercise.

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

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

  • (disco) in reply to shenghi

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

  • (disco) in reply to Eldelshell

    When all you have are hammers everything looks like nails.

    Phillips nails? ( http://xobba.com/wp-content/uploads/2011/03/Phillips-Screw.jpg )

  • (disco)

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

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

    Application denied. Not dickweedish enough.

  • (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: __/__/____

  • (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!

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

  • (disco)

    Way too many problems. Just give the user and calendar and not let them alter anything between, so you get back the date in the format you want.

    @shenghi pointed out what I saw immediately. isdigitornot should start at 1 and any nondigit invalidate it. @Rich_Way pointed out another maintenance issue that the error message don't identify what is wrong and will result in the user saying "it doesn't work" rather than knowing why.

    Year checking... meh, the code won't be around in 35 years from now. If it is, I'll be retired anyway, so don't care. Y2038 will likely cause more issue than this will.

    Feels like there is still a high proportion of date/time related WTF articles here and not very interesting beyond "duh".

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

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

  • (disco)

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

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

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

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

  • (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…

  • (disco)

    And! He's shouting! At the user!

  • (disco) in reply to obeselymorbid

    Nope!

    https://msdn.microsoft.com/en-us/library/w1c0s6bb.aspx

    Unicode sure is fun, innit? I'm not sure if it's just a plain MS fuckup or if there's logic behind it, but that's how it works.

  • (disco) in reply to redwizard
    redwizard:
    f----- nails
    Since when is "finger" a filtered word?
  • (disco) in reply to RFoxmich
    RFoxmich:
    Phillips nails? ( http://xobba.com/wp-content/uploads/2011/03/Phillips-Screw.jpg )

    No need to screw the code up like that.

  • (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:

  • (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
  • (disco) in reply to YellowOnline
    YellowOnline:
    Luftballons

    there's only one reply to that...

    https://www.youtube.com/watch?v=W2D4joJF5xo

    (or if you want the wimpy english lyrics version: https://www.youtube.com/watch?v=VPOAeDBH1_U )

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

  • (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?

  • (disco) in reply to tenshino
    tenshino:
    to force users to enter something sane
    tenshino:
    `__/__/____`

    https://www.youtube.com/embed/0w4AoUSb_0w?version=3&start=17&end=28

  • (disco) in reply to Maciejasjmj
    Maciejasjmj:
    Nope!

    https://msdn.microsoft.com/en-us/library/w1c0s6bb.aspx

    :wtf:

    Oh hell https://en.m.wikipedia.org/wiki/Numerals_in_Unicode

  • (disco) in reply to isthisunique
    isthisunique:
    I once saw something such as, valid = input in range 2000 2050

    In python3 valid = input in range(2000, 2050) would be perfectly valid, optimal solution, because range.__contains__ is an O(1) function essentially equivalent to isinstance(value, int) and value >= 2000 and value < 2050 (additionally checking modulo if the range has non-1 step).

    Of course in languages where range is a factory that returns generic generator such solution is somewhat stupid.


    Maciejasjmj:
    So something like, say, EXTENDED ARABIC-INDIC DIGIT NINE still passes the test.
    Maciejasjmj:
    https://msdn.microsoft.com/en-us/library/w1c0s6bb.aspx

    Unicode sure is fun, innit? I'm not sure if it's just a plain MS fuckup or if there's logic behind it, but that's how it works.

    I'd call it MS fuckup. Unicode digits have unambiguous values, so the functions can be made consistent.

  • (disco) in reply to narbat

    https://www.youtube.com/watch?v=y4RdKzzTU8E

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

  • (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

  • (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