• ∃ Style. (unregistered)

    Why does it have to be oracle and ms sql to start the day? :(

    ``unholy evil prophets rise fire is raining from the endless skies can you hear the final thunder roaring oracle in the morning''

  • Aussie Contractor (unregistered)

    ISNUMERIC("First") = TRUE; // what ??

  • Fred (unregistered)

    The boss has a point, after all ISNUMERIC() accepts values that the PL/SQL While... piece o' crap would have rejected. Examples '+' , '-', ...

  • Ken B. (unregistered)

    Does ISNUMERIC() return "true" for values with decimal points? What about negative numbers? Or leading/trailing spaces?

    The original version would fail in those cases.

  • (cs)

    Hmmm. In this case, I agree with the manager. IsNumeric will say that "5.3" is ok, which is not what the original code would accept.

    However, a try/catch block may not be the best way to do this.

    How about writing a test harness, using XML to pass the data around ... with some more Enterprise-y WTF-ness? Then you can test the original and rewritten one to make sure they get the same results?

  • Aussie Contractor (unregistered) in reply to Aussie Contractor
    Aussie Contractor:
    ISNUMERIC("First") = TRUE; // what ??

    Garr !!

    capture "cansequat" : what happens when you are quat. !!

  • (cs)

    I think TRWTF is "Select 'Non-Numeric Sequence Provided'" instead of RAISERROR().

  • Graham (unregistered)

    The T-SQL ISNUMERIC function returns True for characters that can appear in numbers, such as currency symbols, exponation and plus/minus signs, so its behaviour would be different from the character-by-character approach used.

  • bl@h (unregistered)

    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

  • Andrei (unregistered)

    I don't get it - where is the wtf ? Is it so much unbelievable that the manager would simply choose the safe path ?

  • PleegWat (unregistered)

    Clueless manager is clueless. Where's the WTF?

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

    Good to know the proximity of where you keep your brain...

  • (cs)

    Stored procedures are so Enterprise 1.0. Isn't there a cloud computing platform that'll do this for you?

  • (cs)

    So what Andy means to tell us is that "123456.789E17" is a valid barcode string in their system? And also "$123456.789"?

  • (cs)

    Ah, TheDailyNotAWTF. Shouldn't there be a series tag for that already?

  • (cs)

    You can not use ISNUMERIC for checking barcodes, as a barcode does not have to fit into an INT. For example, the EAN-13 barcodes contain 13 digits.

    The original developer is correct. Manager is right. Andy should stick to his task.

  • Mister Zimbu (unregistered)

    Old solution seems fine to me, though there's probably a dozen cleaner and simpler ways to do it.

    It's more that the new proposed solution wouldn't work.

    cast('123.45' as int) will happily be converted in SQL (as it should), and I'd assume IsNumeric('123.45') would work too, as 123.45, well, is numeric.

  • Wizou (unregistered) in reply to HuHu

    I completely agree... However the original developer could have used more efficient methods to validate each digit rather than a try-catch..

    something like (ch >= '0') And (ch <= '9')

  • (cs)

    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.

  • (cs)

    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"

  • Mike D. (unregistered)

    Ignoring the whole "ISNUMERIC is the wrong tool" issue (let's be nice and assume there's an ISINTEGER (or a regexp) and it would be used instead), the conversation should have ended like this:

    "We just can't run the risk of the new Oracle code behaving any differently than the SQL Server version does. However, you should put your version in there as well, just as comments, so the next guy knows what's going on and doesn't resubmit this to TDWTF."

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

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

  • JB (unregistered)

    I dunno...it seems perfectly reasonable to ask that a piece of production code, which probably interacts with a great many equally warty codes, do the exact same thing, at least at first. I could see implementing Andy's fix down the road (or rolling into the SQL Server code, if it weren't being transitioned to Oracle), but starting out by changing things just seems like a bad idea.

    Now, before I get pilloried, let me explain. There're inevitably going to be bugs in the transition from SQL Server to Oracle, and being able to say "we implemented it the exact same way as before" provides a basis on which to debug. You can compare the two codes line by line, and figure out what didn't get translated correctly (or what function has different side effects, &c). 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.

  • (cs) in reply to ∃ Style.
    ∃ Style.:
    Why does it have to be oracle and ms sql to start the day? :(

    ``unholy evil prophets rise fire is raining from the endless skies can you hear the final thunder roaring oracle in the morning''

    Wow...

    Not expecting a quote from Sodom's lyrics on the Daily WTF!

  • (cs)

    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.

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

    Oh, so true. As someone once said, "The surest way to cause your supervisor to fail is to follow his every order without question." And people wonder why computers are frustrating.

  • (cs)

    Clueless programmer is clueless. Where's the WTF?

  • Franz Kafka (unregistered) in reply to Prosthetic Lips
    Prosthetic Lips:
    Hmmm. In this case, I agree with the manager. IsNumeric will say that "5.3" is ok, which is not what the original code would accept.

    However, a try/catch block may not be the best way to do this.

    How about writing a test harness, using XML to pass the data around ... with some more Enterprise-y WTF-ness? Then you can test the original and rewritten one to make sure they get the same results?

    So write some unit tests and make sure they pass with the new code. You should do this anyway.

  • (cs)

    Assuming the string has to be something that can be printed as an EAN (UPC, GTIN...) barcode, then the original version is more correct than a simple ISNUMERIC, because only digits are allowed (but not e.g. "."); and most likely, the resulting number is too big to be converted to a 32bit integer, so "cast (... ) as int" might fail where it shouldn't. For that reason, it's not much of a WTF IMO.

  • Steve (unregistered)

    I don't get it...this guy was trying to add a T-SQL function into Oracle?

  • (cs) in reply to tiller
    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.

  • Anonymous (unregistered)

    Everyone is a little bit wrong here:

    Andy shouldn't be using IsNumeric without any further processing because, as others have commented, it will return true for numeric symbols such as a decimal point. However, I'm going to give Andy the benefit of the doubt and assume that his revised function handled these cases. After all, the article specifically says that he researched the IsNumeric function and it's behaviour in this regard is perfectly well documented.

    The manager is wrong for thinking that a piece of code has to be written in the same way to function the same way. In any programming language there are a myriad of ways to code exactly the same function. Only a clueless manager would assume that two pieces of code have to perform exactly the same steps in order to perform the same function.

    Personally speaking, the manager scores highest on my WTF meter.

  • Jon (unregistered)

    The real WTF is the manager used the phrase, "think outside the box."

  • Greg (unregistered)

    The manager is totally right. The only way to test these kinds of mass code changes is through automated scripts that compare outputs. If there is ANY change in behaviour, even if it's to fix a bug, it can make automated testing infeasible. Noting the defect and fixing it after the conversion would be a better approach. Sometimes you need to step back and look at the bigger picture...

  • (cs) in reply to Anonymous
    Anonymous:

    The manager is wrong for thinking that a piece of code has to be written in the same way to function the same way. In any programming language there are a myriad of ways to code exactly the same function. Only a clueless manager would assume that two pieces of code have to perform exactly the same steps in order to perform the same function.

    On the other hand, it's trivially easy to formaly prove that program B is an 1:1 translation of program A (exactly the same steps in order to perform the same function), while it is generally speaking difficult to impossible to prove that a differently written program B gives the same result like program A. To be on the safe side, requiring an 1:1 translation doesn't seem unreasonable to me.

  • (cs)

    What is the WTF?

    Unless the system is under test, their best bet is to transliterate the semantics of one system to the other. Other parts of the system may rely on that idiosyncratic behavior.

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

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

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

    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. The more important issue raised by the poster you responded to is that checking to see if something can be printed on a barcode seems to be UI validation code, not data layer validation code. For example, if the UI changes the barcode format to PDF417, the validation rules change. UI code in the database is not a good idea.

  • Anonymous (unregistered) in reply to ammoQ
    ammoQ:
    Anonymous:

    The manager is wrong for thinking that a piece of code has to be written in the same way to function the same way. In any programming language there are a myriad of ways to code exactly the same function. Only a clueless manager would assume that two pieces of code have to perform exactly the same steps in order to perform the same function.

    On the other hand, it's trivially easy to formaly prove that program B is an 1:1 translation of program A (exactly the same steps in order to perform the same function), while it is generally speaking difficult to impossible to prove that a differently written program B gives the same result like program A. To be on the safe side, requiring an 1:1 translation doesn't seem unreasonable to me.

    I see exactly where you're coming from and I agree with your sentiment. But testing a function/program/system should be a complete task in and of itself and it should be possible to do this without ever seeing the code (ie. as a black box). If you're porting a legacy system, for example, you should not be forced to write logically identical code to the old system just because it makes it easier to prove that the new functions the same as the old. You should write the code in the most effective manner provided by your language and then identify any differences through a thorough test schedule.

  • Bert (unregistered)

    TRWTF is the choice of language.

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

        //If it compiles, it must be OK.
        int myZipCode = 98052-1123;
    
    
  • st0815 (unregistered)

    Regardless whether the manager in this case was right or not: your manager is typically not interested in technical details.

    If it's a technical decision, then it needs to be made by you, because you are the assigned engineer. If you are not prepared to take responsibility for the change yourself you should skip it. Asking for permission just tells your boss that you are not confident that your approach is right. In all likelihood he'll reject your proposal and will think of you as incompetent.

  • (cs)

    I agree not a WTF, the programmer is TRWTF, etc, but...surely that while loop can't be significantly faster than

    REGEXP $\d+^
    

    ? Can it?

  • (cs)

    It's a good thing they're checking to make sure "@CheckDigit is null" in the Catch block. They probably wanted to implement something like "IF TRUE", but TSQL doesn't support booleans so they were stuck with the equivalent.

  • (cs) in reply to Airhead
    Airhead:
    I think TRWTF is "Select 'Non-Numeric Sequence Provided'" instead of RAISERROR().
    I never could figure out if it was rais error or raise rror.
  • Adam (unregistered) in reply to Graham

    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.

  • WMD (unregistered)

    TRWTF is that the code was well documented to begin with.

  • (cs) in reply to Jaime
    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.

  • Steve (unregistered) in reply to akatherder

    Right - it was coded correctly in T-SQL by the previous developer(s). It's the new Oracle developer causing problems by unnecessarily extending his "expertise". If he stuck to his directive and ported the function to oracle, he wouldn't be sidetracked with trying to throw somebody else under the bus. The real WTF is the n00b dev wanting to make a name for themselves.

  • Kef Schecter (unregistered) in reply to PleegWat
    PleegWat:
    Clueless manager is clueless. Where's the WTF?
    You're it.

Leave a comment on “Warts and All”

Log In or post as a guest

Replying to comment #:

« Return to Article