| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
It's always funny when a program goes through all the trouble of detecting an "error" when it could just deduce the answer with same or simpler logic.
I mean, if it was a human being talking like this, we would probably smack him in the head. |
|
return("You must express the magnitude of the dollar amount using modern, Arabic-derived numerals formatted according to base-10 (decimal) convention, most significant digit first.")
|
ROFLAMO! |
|
Time to go enter $-%
|
Re: A Very Valid validInt
2007-10-03 09:34
•
by
Kelly
(unregistered)
|
Hee |
|
I wonder if this is really a WTF and not the request from some crazy client. I had a project recently where the client was not satisfied with generic error messages and we needed to get much more in depth with what errors were being generated.
|
|
^\$-?[:digit:]*\.[:digit:]{2}$ anyone?
What language doesn't has a regex library available these days? |
Re: A Very Valid validInt
2007-10-03 09:49
•
by
dkf
(unregistered)
|
Brainf*ck. |
Rolling On Floor, Lusting After Marie Osmond? |
|
The real WTF is the name of the function - validInt(). The function does not valid integers, it validates currency. Currency is mostly never integer based, but decimal based, even if you want to ignore formatting (which this function does not).
This is first grade programming at it's best. You should allow your users to enter data in flexible formats and your code should adjust. |
Agreed. This looks more like a case of runaway requirements more than an overzealous coder. |
Re: A Very Valid validInt
2007-10-03 10:01
•
by
tryWhitespace
(unregistered)
|
|
that snippet is more or less what we were told to do in first year of computer sciences...
|
Re: A Very Valid validInt
2007-10-03 10:09
•
by
Calli Arcale
(unregistered)
|
|
Whether the WTF originated with the coder or the client, it's still a WTF. It's just not necessarily becuase the coder was an anal-retentive idiot. Perhaps he even avoided a regex because it made him feel better to express his frustration through a function like this one.
But it's still a WTF. |
|
There comes a time when you have to force your user to grow up and accept some responsibility. Regex validation is needed here, with a single error message: "Please re-enter the amount using this format: $9999.99".
|
|
I guess I will be the first one to say that I don't think this is a WTF. Just because there may be an easier way to accomplish the validation doesn't make this a WTF. Is it overly verbose? Maybe...but even that is open to opinion.
If I saw this in code I was maintaining I wouldn't say "WTF!?!", I would probably just change it to use a regex or something. Or since it appears to accomplish what it set out to accomplish I might just leave it alone. |
|
While this might not be the best way to actually implement the input validation, wrt the messages, I think you underestimate how obtuse end users can be.
captcha: tastey (spellcheck, anyone?) |
|
The thing is, it doesn't accomplish it's objective very well. Unless $-. is a valid currency.
|
Re: A Very Valid validInt
2007-10-03 10:28
•
by
Bob
(unregistered)
|
The readable, maintainable ones. |
Re: A Very Valid validInt
2007-10-03 10:29
•
by
Chris Barts
(unregistered)
|
Right. Tell that to IBM, and everyone who programs in COBOL and RPG. CAPTCHA: 'tastey' they are not. |
Re: A Very Valid validInt
2007-10-03 10:30
•
by
Mean Mr. Mustard
(unregistered)
|
|
No, you ninny! It means "Rolling On the Floor, Laughing Ass My Off"!
|
|
I feel funny admitted this but I have a similar piece of code that I use to validate emails.
It has messages like... "the tld must be more then 1 character." I don't get crappy email values though.... just fake ones;) captcha: sanitarium |
Re: A Very Valid validInt
2007-10-03 10:33
•
by
nickf
(unregistered)
|
True, I immediately thought that too, but it wouldn't be able to tell you exactly what is wrong with the input. The code is pretty much WTF-free... The Real WTF(tm) is the requirement that such a level of error reporting is needed. The only things I'd change would be to do a really simple regex right at the top, and only THEN go through all that garbage to say what's wrong if it failed the first test - with all that code, you're gonna let some cases slip through (like what people above me pointed out). |
Tongue-in-cheek humor isn't your strong suit, is it. |
Re: A Very Valid validInt
2007-10-03 10:41
•
by
nickf
(unregistered)
|
not to be anal about it, buuuut: /^\$?-?(\d+\.?\d*|\d*\.\d+)%?$/ it's not just for currency - it does all sorts of numbers (percentages, for example), hence why you can have any number of digits after the decimal. |
Re: A Very Valid validInt
2007-10-03 10:44
•
by
dpm
(unregistered)
|
|
You should write one.
|
Re: A Very Valid validInt
2007-10-03 10:44
•
by
John Doe
(unregistered)
|
Well, the thing is that the code does use a regex at the very beginning to filter out some errand " " text. Which doesn't belong in there anyways. Apart from the high verbosity and the wrong naming, this code is broken (does not check the input correctly in all cases) and not culture-independent. |
|
So, wait... -10.00 is valid, $10.00 is valid, $-10.00 is valid, 10.00% is valid.. what sort of field is this? It takes unitless floats, dollars, and percentages?
|
Re: A Very Valid validInt
2007-10-03 10:48
•
by
Val
(unregistered)
|
|
So Brainf*ck is a readable, maintainable language, isn't it?
|
They actually used a regex. To strip off blanks. Sigh. |
Re: A Very Valid validInt
2007-10-03 10:57
•
by
Foosball Girl In My Dreams
|
|
A project or so back I had a requirement from the end user to recalc an entire series of fields on a keystroke by keystroke basis. For example, as they entered a price of 123.45, it would recalc the entire form for: 1, 12, 123, 123.4, 123.45, with appropriate range-check errors spewing into an error-status scrolling window. Sort of rediculous, and a cpu-pig, but the user wanted it, he agreed that it might be wasteful, but was willing to pay for it, so we did it.
|
Re: A Very Valid validInt
2007-10-03 11:01
•
by
aaron
(unregistered)
|
i once wrote an overly complicated email validator aswell. mine even did a reverse lookup on the domain to see if it existed, then tryed to open a connection on port 25. |
|
Well, I guess tou can't enter French formatted currency (might be Quebec only, not sure) where the dollar sign is after the numbers which actually makes sense: you say ten dollars not dollar ten for 10$.
Bonus for redunant ifs and the fact that it fails to notice having a dollar percentage. Definately not "^.^,^-^". |
Re: A Very Valid validInt
2007-10-03 11:19
•
by
Dividius
(unregistered)
|
$-23.26% ?? Yeah, we're deploying a version of the software for the U.K., and I'm gonna need you to come in on saturday and localize this, mmmkay? captcha: Run outta funny letters, lamo? |
Re: A Very Valid validInt
2007-10-03 11:20
•
by
Nobody (all that) important
(unregistered)
|
Actually, $-10.00 is invalid as well: if (fdollar > -1 && fminus > -1) and yet ... they follow up with this??
.. ok . I'm confused ... :\ so .. are you allowed: $- or not?? seems like it's both .. |
Re: A Very Valid validInt
2007-10-03 11:21
•
by
Nobody (all that) important
(unregistered)
|
|
hehe ... ok .. never mind ... did my own WTF ... missed the comment: "//" of that return .. *sigh*
(note to self: clean glasses ... ) ;) |
And are any of those ints? My brain is now sore. IHTFP. It makes me angry some times. But, some times it makes me laugh. |
Re: A Very Valid validInt
2007-10-03 11:27
•
by
Mike
(unregistered)
|
|
Not only is currency rarely integer-based, but this "validInt" function actually ALLOWS a floating-point number (look at the "fdot" variable). I actually read the comments to see if anyone had noticed this. Glad I wasn't the only one.
|
Re: A Very Valid validInt
2007-10-03 11:32
•
by
TraumaPony
(unregistered)
|
|
YES, THIS CODE SNIPPET IS WORSE THAN FAILURE.
IT'S -WORSE- THAN -FAILURE-. I hold a grudge indefinitely. Anonymous does not forgive. |
Re: A Very Valid validInt
2007-10-03 11:33
•
by
TraumaPony
(unregistered)
|
|
And I'm aware that I have my name in the user field, by the way.
|
Re: A Very Valid validInt
2007-10-03 11:33
•
by
Flim McBoobie
(unregistered)
|
You must use the percent sign. You must use the minus sign. Please use them. Now. (I'm still waiting.) |
Re: A Very Valid validInt
2007-10-03 11:56
•
by
Frost
(unregistered)
|
Which is more important than people probably think, in general. How many flat-pack resistors do you get for a penny? The MRP package I'm working with right now supports 4 decimal places for monetary values. |
Agreed. My approach to validating fields like this is to strip out non-numeric characters (possibly excepting ".") and then use built-in functionality for validating that the numeric characters left form a valid number. If it doesn't, output a single error message saying something like, "This field is required, and the format should be $xxx.xx." Anything wrong with that? Sure, a clever user can enter something like hi100my234name567max980powers and it validates okay...but is that behavior that the developer has to prevent? |
|
Goes to far? You apparently haven't dealt with some of the incredibly stupid users I have over the years... It would have been perfectly appropriate to have an error message that said:
"You haven't typed anything in this field, and something is required in this field. Please use the keyboard, which is likely in front of you (it'll be the thing with a bunch of squares with letters, number and symbols on it). Please ball your hand up, then extend your index (pointer) finger out, and use it, in conjunction (read: together with) an up and down movement of your arm (the one that is attached to the hand you've balled up) and try and target the squares with letters on the keyboard in a pattern that forms a word that makes sense in this field. For example, this field is labeled First Name, so an appropriate entry might be 'bill' or 'jeff', but '12345' is most likely not an appropriate response. In addition to this activity, please remember to expand and contract your diaphram, thereby getting air into your lungs and oxygen into your blood stream for distribution throughout your body. If you are still having difficulty achieving the goal of proper data entry into this field, please contact the technical support emergency hotline at 123-456-7899 (please click HERE for details on how to use the device next to you which sends and recieves sounds between yourself and another human being, commonly referred to as a telephone)." Yes, that would be an absolutely appropriate error message, considering some of the users I've dealt with over the years. It would be even MORE appropriate accompanied by animated graphics demonstrating what to do, hand-drawn with bright Crayola-esque colors. |
Re: A Very Valid validInt
2007-10-03 12:04
•
by
Gabriel
(unregistered)
|
I recall in the chapters in Patterns of Enterprise Application Architecture that dealt with currency, they explicitly advised using an integer-based storage mechanism. Treat currency as an integral number of the smallest unit (e.g., cents for US currency). This helps prevent floating point math funniness, and ensures that you don't lose a penny here or a penny there due to rounding. It gets hairier when you have to do currency conversions, but I think I recall that you want to still store in the denominations of one of the languages. |
|
Well, the coder's heart was in the right place. This definitely could have been implemented much better, and I'm confused as to why this field seems to be able to accept so many formats, but if anything there isn't enough input validation IMO (there are still incorrect values that can get through).
My daddy always taught me: "Son, the user should be able to mash the keys with their fist and not break anything." |
Re: A Very Valid validInt
2007-10-03 12:19
•
by
awt
(unregistered)
|
User: But I need to enter $1234.56! What should I do? |
|
Why is it OK for a ValidInt to have a decimal point? I guess if he checked that all digits to the right of it were 0, but he's not doing that...
|
You did notice that that return statement is commented out, right? :) |
|
This is QA driven code. The first validation was very simple and then snowballed as the QA department tried every goofy combination under the sun and insisted on a specific, new error message for each case.
|
| « Prev | Page 1 | Page 2 | Page 3 | Next » |