• Ralph (unregistered)

    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!).

  • A nony mouse (unregistered)

    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', '')))

  • Ilya (unregistered)

    Well, the original code would consider 1.1 as well as 1E-1 to be invalid numbers. Who knows what impact that may have.

  • (cs) in reply to DOA
    DOA:
    TRWTF is that Andy went to his boss to talk about implementation details. Only newbies do this. Experienced developers get the gist of what has to be done and keep the implementation to themselves. They do not discuss low-level code issues with management, because there is a very real risk that some clueless manager might start coming up with brillant ideas of the type "we should use XML because I keep hearing about it" and "we need to write this application in AJAX"
    That, and the only reason people go to their boss on things like this is to go "hey boss, look at me, I'm so much smarter than your last programmer. Are you proud of me? My dad never was :( I'm so sad and lonely."
  • Rootbeer (unregistered) in reply to Wizou
    Wizou:
    something like (ch >= '0') And (ch <= '9')

    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!

  • Kevin (unregistered)

    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.

  • anonymous (unregistered) in reply to Rootbeer
    Rootbeer:
    Wizou:
    something like (ch >= '0') And (ch <= '9')

    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!

    if if's and but's were candy and nuts, we'd all have a merry christmas.

  • (cs) in reply to HuHu

    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.

  • Sylver (unregistered) in reply to PleegWat
    PleegWat:
    Clueless manager is clueless. Where's the WTF?
    "Clueless" manager turns out to be the smart one.

    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".

  • THG (unregistered) in reply to JB
    JB:
    While that code snippet probably doesn't have any funny side effects, it's possible that another one might, and "improving" the code as you translate could introduce/get rid of side effects that could change the behavior of the system. There's a time and place for improvement, but that just seems like it's premature--I agree with Andy's boss on this one.

    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.

  • plsql-oron (unregistered)

    Sounds like a job for RegEx!

  • jdw (unregistered) in reply to ammoQ
    ammoQ:
    tiller:
    Why the hell is data converted to/from barcodes by the database?

    This is a task that the normal language (Php/Java/.net I guess) can do much faster, and without an insane implementation.

    Why should PHP be faster than, say, T-SQL or PL/SQL? Just because an interpreter is running in the database doesn't necessarily mean that it's slower.

    Let's assume they're both just as fast.

    It's still superfluous. Why add interaction with a db into this routine if it can be accomplished without that interaction?

  • (cs) in reply to jdw
    jdw:
    ammoQ:
    tiller:
    Why the hell is data converted to/from barcodes by the database?

    This is a task that the normal language (Php/Java/.net I guess) can do much faster, and without an insane implementation.

    Why should PHP be faster than, say, T-SQL or PL/SQL? Just because an interpreter is running in the database doesn't necessarily mean that it's slower.

    Let's assume they're both just as fast.

    It's still superfluous. Why add interaction with a db into this routine if it can be accomplished without that interaction?

    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.

  • Anonymous (unregistered) in reply to DOA
    DOA:
    TRWTF is that Andy went to his boss to talk about implementation details. Only newbies do this. Experienced developers get the gist of what has to be done and keep the implementation to themselves. They do not discuss low-level code issues with management, because there is a very real risk that some clueless manager might start coming up with brillant ideas of the type "we should use XML because I keep hearing about it" and "we need to write this application in AJAX"
    I have to say I agree with this wholeheartedly. If you've been tasked to rewrite a piece of code and you have rewritten that piece of code to be functionally equivalent to the old piece, then there is absolutly no reason to verify that change with a manager. It's not your manager's job to worry about implementation details, that's your job as the coder. So who cares if you've refactored a procedure, if it performs the right function then you don't need manager oversight. Of course, whether or not Andy's code actually did perform the right function we'll never know, because we never actually saw his revised routine (maybe he accounted for numeric symbols and it worked 100%, but then maybe he didn't).
  • ablaze (unregistered)

    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.

  • Eve (unregistered) in reply to Adam
    Adam:
    IsNumeric() would allow currency symbols, negative signs, decimal points, etc - all of which can NOT be rendered as a bar code. The manager is right that the implementation would be different. The "Andy" in the story needs to STFU and not assume he is the smartest person in IT.
    Does it make you feel like a big man to hurl imaginary insults at people you've never met, for reasons you aren't even sure about? Please try to remember that this is a site for IT professionals, not angsty kids.
  • (cs) in reply to lofwyr
    lofwyr:
    Jaime:
    ammoQ:
    tiller:
    Why the hell is data converted to/from barcodes by the database?

    This is a task that the normal language (Php/Java/.net I guess) can do much faster, and without an insane implementation.

    Why should PHP be faster than, say, T-SQL or PL/SQL? Just because an interpreter is running in the database doesn't necessarily mean that it's slower.

    I believe "faster" refers to the developer accomplishing the task faster rather than the code executing faster. T-SQL is a horrible language and PL/SQL is only marginally better. Any modern language can do this as a one or two liner.

    So can PL/SQL, although it would be wise to format the code, such as given in this example:

    DECLARE 
      v_test VARCHAR2(99) := '01234567890';
    BEGIN
      -- Oracle PL/SQL Version before 10g
      IF TRANSLATE(v_test, 'a01234567890', 'a') <> v_test 
      THEN
        DBMS_OUTPUT.put_line('Invalid characters in given string!');
      END IF;
    END;
    /
    
    or 
    
    DECLARE 
      v_test VARCHAR2(99) := '01234567890';
    BEGIN
      -- Oracle PL/SQL Version 10g and above using regular expressions
      IF REGEXP_REPLACE(v_test, '[^0-9]', '') <> v_test 
      THEN
        DBMS_OUTPUT.put_line('Invalid characters in given string!');
      END IF;
    END;
    /
    

    l.

    See, PL/SQL is better than T-SQL, like I said. However, you are still writing UI code in the database. Just because you can doesn't mean you should.

  • iToad (unregistered)

    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.

  • Roy T. (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.

    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?

  • (cs)
    Begin Try
    	set @CheckDigit =  Convert(int,@barcodeValueSequence)
    End Try
    Begin Catch
    	Select 'Non-Numeric Sequence Provided'
    End Catch
    
  • Anonymous Coward (unregistered)

    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.

  • (cs) in reply to SR
    SR:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.

    AFAIK passing a string is correct. Or is a barcode starting with 0 not valid?

    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).

  • (cs) in reply to Roy T.
    Roy T.:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.

    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?

    If it's an integer, you don't have to pass it to the function in the first place. Numbnuts.

  • HonoredMule (unregistered)

    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."

  • Franz Kafka (unregistered) in reply to frits
    frits:
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.

    That's cute. I'll bet you store zip codes as integers, too.

        //If it compiles, it must be OK.
        int myZipCode = 98052-1123;
    
    

    Why am I not surprised that this is in redmond.

  • (cs) in reply to Eve
    Eve:
    Adam:
    IsNumeric() would allow currency symbols, negative signs, decimal points, etc - all of which can NOT be rendered as a bar code. The manager is right that the implementation would be different. The "Andy" in the story needs to STFU and not assume he is the smartest person in IT.
    Does it make you feel like a big man to hurl imaginary insults at people you've never met, for reasons you aren't even sure about? Please try to remember that this is a site for IT professionals, not angsty kids.

    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.

  • wtf (unregistered) in reply to frits

    [quote user="frits]

    Insults = pointless and unenlightening rudeness [/quote]

    FTFY

  • Neville Flynn (unregistered)

    I love it when a submitter thinks he found a WTF but it turns out the submitter is the WTF after all.

  • (cs) in reply to wtf
    wtf:
    frits:

    Insults = pointless and unenlightening rudeness

    FTFY

    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?

  • (cs)

    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."

  • Riker (unregistered) in reply to Jon
    Jon:
    The real WTF is the manager used the phrase, "think outside the box."
    All managers are required to use this and certain other phrases, which are taught in the secret ceremony held on the first day of becoming a manager. It's all part of the conspiracy to convince workers that managers are mindless kool-aid spewing sociopaths, making it easier to sneak up on you when it comes time for bonuses (for them) and layoffs (for you).
  • Joe (unregistered) in reply to jdw
    jdw:
    Why add interaction with a db into this routine if it can be accomplished without that interaction?
    Because, as a side effect, the old routine constantly verified that the database and network are up.

    You wouldn't want to print a bar code if the Internet is down, now would you. Would you???

  • re:me (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    Roy T.:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.

    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?

    If it's an integer, you don't have to pass it to the function in the first place. Numbnuts.

    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]?

  • System.Net.Chris (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.

    TRWTF is that you spelled out the word The instead of just using TRWTF like everyone else. Bad sheep!

  • wtf (unregistered) in reply to frits
    frits:
    wtf:
    frits:

    Insults = pointless and unenlightening rudeness

    FTFY

    I'm insulted!

    That's your business, not mine.

    frits:
    Addendum (2010-06-28 13:01): Who would you rather sit and listen to for an hour, Don Rickles or Al Gore?

    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.

  • (cs) in reply to wtf
    wtf:
    frits:
    wtf:
    frits:

    Insults = pointless and unenlightening rudeness

    FTFY

    I'm insulted!

    That's your business, not mine.

    Whoooooosh!

    wtf:
    frits:
    Addendum (2010-06-28 13:01): Who would you rather sit and listen to for an hour, Don Rickles or Al Gore?

    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.

    Thou doth qualify too much. Just remember, Rickles rhymes with tickles and Gore rhymes with bore.

  • wtf (unregistered) in reply to frits
    frits:
    Just remember, Rickles rhymes with tickles and Gore rhymes with bore.
    Lifestyles of the easily amused.
  • Some Wonk (unregistered) in reply to anonymous
    anonymous:
    Rootbeer:
    Wizou:
    something like (ch >= '0') And (ch <= '9')

    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!

    if if's and but's were candy and nuts, we'd all have a merry christmas.

    Santa is sick, and Christmas has been cancelled. What do you do, now?

  • Vs (unregistered)

    I think it should replace whole loop:

    @barcodeValueSequence like '%[^0-9]%'

    (TRUE if anything but digit is in the string)

  • Mario (unregistered)

    This post is just stupid :P but some of the comments are priceless!

  • (cs) in reply to HuHu

    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.

  • MP (Real) (unregistered) in reply to bl@h
    bl@h:
    if isnumeric(@ORACLEWTF) RAISERROR ('cannot deal with oracle frist thing in morning', 16, 1)

    captcha:enim - I need an enima after this article to cleanse my brain

    Someone has his head up his arse.

  • boog (unregistered) in reply to wtf
    wtf:
    frits:
    Just remember, Rickles rhymes with tickles and Gore rhymes with bore.
    Lifestyles of the easily amused.

    Easily amused.

    What do you expect? You're at an IT website dedicated to laughing at the shortcomings of others.

  • Richard (unregistered)

    If @barcodeValueSequence Like '%[^0-9]%' Begin Select 'Non-Numeric Sequence Provided' Return End

  • katastrofa (unregistered) in reply to PleegWat
    PleegWat:
    Clueless manager is clueless. Where's the WTF?

    He isn't clueless, just cautious. Sometimes it is better not to fix things which work.

  • RandomUser423689 (unregistered) in reply to db2
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.
    That's cute. I'll bet you store zip codes as integers, too.
    I do feel like I'm forgetting something, but right now I can't remember why this wouldn't work. Sure, you have to have input and presentation logic to convert 00401-0203 to 4010203 and 79301-0000 to 793010000, and vice-versa; but as long as you consistently store +4 (even when zero), prepending zeros shouldn't be a problem. Or maybe that was the issue, that +0000 is "valid" and therefore not good to mean "no +4". If that's it, how about negative for 5-digit. Right back to input and presentation logic.

    Someone please remind me what I'm forgetting.

  • jrh (unregistered) in reply to Some Wonk
    Some Wonk:
    anonymous:
    Rootbeer:
    Wizou:
    something like (ch >= '0') And (ch <= '9')

    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!

    if if's and but's were candy and nuts, we'd all have a merry christmas.

    Santa is sick, and Christmas has been cancelled. What do you do, now?

    Start putting, commas where they, don't belong?

  • Luis Espinal (unregistered) in reply to PleegWat
    PleegWat:
    Clueless manager is clueless. Where's the WTF?

    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 :)

  • Geocoder (unregistered) in reply to Airhead

    which brings up the MSWTF of RAISERROR only having one "E"

    captcha abbas: because the one band wasn't awesome enough

  • (cs) in reply to java.lang.Chris;

    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.

Leave a comment on “Warts and All”

Log In or post as a guest

Replying to comment #:

« Return to Article