- 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
I guess I wasn't the only one thinking that the manager made the right call. It happens from time to time, especially with competent managers (yes, they do exist!).
Admin
If you Google for 'oracle isnumeric' the first result comes back with this function:
LENGTH(TRIM(TRANSLATE(string1, '+-.0123456789', '')))
which you could change to disallow +-,
LENGTH(TRIM(TRANSLATE(string1, '0123456789', '')))
Admin
Well, the original code would consider 1.1 as well as 1E-1 to be invalid numbers. Who knows what impact that may have.
Admin
Admin
What if the database uses a character encoding where the set of Arabic numerals is non-contiguous, like ITA2 Baudot code?
Your version could break!
Admin
Developer ports SQL code on nicely documented project. Runs into an odd way of doing something, and changes it. Reports findings to manager. Manager praises his findings, but reminds him that for the time being to just port the mission critical SQL verbatim just in-case
Guys... this is a pretty serious WTF.
Admin
Admin
This is not a WTF. There is a huge difference between a string containing something that can be evaluated as a number, and a string containing only digits. Which, from the article, is meant to be used for a barcode.
Admin
This is a barcode number and isNumeric() could accept values that are not valid for the barcode.
So replacing these 15 "ugly" lines of code with isNumeric() would introduce a bug.
"Ugly and working" is a lot better than "clean and buggy".
Admin
Quoted for truth.
Manager may not know coding, but obviously knows what damage "an improver" can do.
If you are working on well-formatted well-commented code, and see what you think is a WTF ... consider the possibility that it is not.
Admin
Sounds like a job for RegEx!
Admin
It's still superfluous. Why add interaction with a db into this routine if it can be accomplished without that interaction?
Admin
It depends, I'd say. If this is supposed to be a check on a table column, its place should be inside the db (which is the last line of defense for consistent data in that case). If it's just a format validation for an input form, it could well reside inside a PHP/Java/whatever-Application.
l.
Admin
Admin
I must be using sql too much, as my first reaction was to use "not like '%[^0-9]%'" as the check for the entire string.
Admin
Admin
Admin
When it matters, I try to specify strings using a regular expression. This cuts off a lot of arguments about what is or is not a valid string.
Admin
Lol, I think you sir are the WTF. Why would you pass an int to a function that checks if a STRING is an int?
Admin
Admin
I had an internship in the nuclear power industry for a short time. They are 100% concerned with stuff like this. Every time a new service pack, processor, etc. comes out, it has to be thoroughly tested to ensure that it produces the EXACT same results as previous software/hardware did. Any deviations have to be signed off on by the appropriate person as "acceptable" or "within limits." I'm sure the use of a different method of computation would be subjected to no less.
Admin
You pad it with leading zeros when you print it. At least that's what I did with numeric barcodes (this must be using a two of five interleaved format or else the whole check is pointless in the first place).
Admin
If it's an integer, you don't have to pass it to the function in the first place. Numbnuts.
Admin
Rule of thumb: never ever involve your manager in nitty-gritty details of logic implementation. Also, consider any opportunities for logical reduction a "nitty-gritty detail."
Admin
Why am I not surprised that this is in redmond.
Admin
If the youth of today understand why IsNumeric() does not provide a good validation for barcode sequences, my faith in the future is restored. Please try to remember this is a comments section for a comedy website specializing in IT. Insults = entertainment, lectures = tedium.
Admin
[quote user="frits]
Insults = pointless and unenlightening rudeness [/quote]
FTFY
Admin
I love it when a submitter thinks he found a WTF but it turns out the submitter is the WTF after all.
Admin
I'm insulted!
Addendum (2010-06-28 13:01): Who would you rather sit and listen to for an hour, Don Rickles or Al Gore?
Admin
The real WTF is still that this was posted as a WTF. This wouldn't be the first time that someone was tasked to do a port of a random system and decided to do "some fixes" at the same time. The best time to introduce new bugs is by premature optimization and/or fixing bugs. I'd say this Andy has a good manager who gave exactly the right answer: "good catch, but play it safe."
Admin
Admin
You wouldn't want to print a bar code if the Internet is down, now would you. Would you???
Admin
and, when someone types a barcode into a text input field, it's magically converted to an int? even if someone accidentally types something other than [0-9]?
Admin
TRWTF is that you spelled out the word The instead of just using TRWTF like everyone else. Bad sheep!
Admin
That's your business, not mine.
Hmm, an hour of content-free "I'm clever"-ing versus an organised presentation of a set of (purported) facts about the world. I'd give Rickles five minutes, ten on a good day, because he is sort of funny. If I were unfamiliar with and interested in Gore's topic, he'd get an hour of my attention.
Admin
Whoooooosh!
Thou doth qualify too much. Just remember, Rickles rhymes with tickles and Gore rhymes with bore.
Admin
Admin
Santa is sick, and Christmas has been cancelled. What do you do, now?
Admin
I think it should replace whole loop:
@barcodeValueSequence like '%[^0-9]%'
(TRUE if anything but digit is in the string)
Admin
This post is just stupid :P but some of the comments are priceless!
Admin
How do we vote a comment up or down on here? I've seen the featured comments (TRWTF would be if that was being done manually). I vote this one up.
Admin
Someone has his head up his arse.
Admin
Easily amused.
What do you expect? You're at an IT website dedicated to laughing at the shortcomings of others.
Admin
If @barcodeValueSequence Like '%[^0-9]%' Begin Select 'Non-Numeric Sequence Provided' Return End
Admin
He isn't clueless, just cautious. Sometimes it is better not to fix things which work.
Admin
Someone please remind me what I'm forgetting.
Admin
Start putting, commas where they, don't belong?
Admin
Was he really? The requirement is to validate strings composed of digits only. which the concocted T-SQL function did (pretty much positive number... and for barcoding, probably of a certain magnitude).
This is not the same as testing numeric input (.ie. -0.123), which ISNUMERIC() does.
It would have been extremely fun for the OP team had Andy changed that function with a PL/SQL ISNUMERIC equivalen :)
Admin
which brings up the MSWTF of RAISERROR only having one "E"
captcha abbas: because the one band wasn't awesome enough
Admin
Unless you're doing math on a value you shouldn't store or process it as a number. Numbers are for math, and counting, and statistics and such... Not zip codes. Just the fact that you have to add the extra zeros in at display time is wrong, and also, fully qualified zip codes contain non-numeric characters such as the hyphen.