- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Most likely the fresh programmer would have thought that he'd be in retirement by then and that somebody else can maintain this code.
Admin
should have been
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.
Admin
So basically you're saying: were it not for the bugs it would have worked?
Admin
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...
Admin
Can be simplified to
Edit: I forgot to say this makes perfect sense in context
Admin
Article is up, but Discourse isn't listing it. Paula Bean has broken things. Again.
@PJH or @boomzilla — Fix please?
Admin
No. You're mixing up between
textBox1
andtextBox2
.Admin
Not necessarily. Remember how unimaginably far away year 2000 was in 1975?
Oops.Admin
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...
Admin
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.
Admin
This topic is now listed. It will be displayed in topic lists.
Admin
When all you have are hammers everything looks like nails.
Admin
Which is why not changing the default name on any of his input fields to something meaningful is such a maintenance a nightmare.
Admin
Paula's MIA again?
Admin
PJH is just short for Paula's Job Helper. She's delegating.
Admin
Most of the functional WTF of this can be fixed with a handful of minor changes:
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.
Admin
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.
Admin
Except if there's a single digit, then
isdigitornot
will be1
. So this code will let 1a bcde pass. Looks like crud to me.Admin
Oh, ha ha, my bad... I missed a lot of WTF when I skimmed over that code.
Admin
Phillips nails? ( http://xobba.com/wp-content/uploads/2011/03/Phillips-Screw.jpg )
Admin
Luftballons should be with a capital letter, like all German nouns. /application for pedantic knight etc.
Admin
Application denied. Not dickweedish enough.
Admin
Um... it looks like C#, in which case this is all you need:
I would then recommend doing some kind of masking on the textbox itself, to force users to enter something sane:
__/__/____
Admin
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!
Admin
"What do you mean, LOOKS LIKE? They ARE f----- nails!!" said the hammer.
Admin
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".
Admin
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.
Admin
BZZT!
So something like, say, EXTENDED ARABIC-INDIC DIGIT NINE still passes the test.
Admin
int digitornot = false; //I don't dig this code
Admin
TR :wtf:
I fail to see any circumstances where that behaviour would be useful.
Admin
That depends whether it is understood as a
9
for the purposes of parsing a number. If it is, it's probably useful in somelanguagewriting system but not necessarily one you use.Admin
Well, if it does, then this will remain true AFAIUI:
Admin
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.
Admin
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…
Admin
And! He's shouting! At the user!
Admin
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.
Admin
Admin
No need to screw the code up like that.
Admin
I'll take some of column A and some of column B, please. :confused:
Admin
Admin
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 )
Admin
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.
Admin
The Rapture is scheduled for 2038-01-19 03:14:08 UTC. It's a Tuesday. I thought everyone knew that?
Admin
https://www.youtube.com/embed/0w4AoUSb_0w?version=3&start=17&end=28
Admin
:wtf:
Oh hell https://en.m.wikipedia.org/wiki/Numerals_in_Unicode
Admin
In python3
valid = input in range(2000, 2050)
would be perfectly valid, optimal solution, becauserange.__contains__
is an O(1) function essentially equivalent toisinstance(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.I'd call it MS fuckup. Unicode digits have unambiguous values, so the functions can be made consistent.
Admin
https://www.youtube.com/watch?v=y4RdKzzTU8E
Admin
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.
Admin
It's a solved problem. (Except in the USA.) Or you can do the right thing and use YYYY/MM/DD. :D
Admin
ISO compliance is SOOOOO 1990. :stuck_out_tongue: