Comment On Warts and All

"We need to make sure that the new PL/SQL version that runs on Oracle will work exactly as it does on SQL Server," stated the directive given to Andy by his supervisor. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Ugh

2010-06-28 09:06 • by ∃ 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''

Re: Warts and All

2010-06-28 09:07 • by Aussie Contractor (unregistered)
ISNUMERIC("First") = TRUE; // what ??

Re: Warts and All

2010-06-28 09:07 • by Fred (unregistered)
The boss has a point, after all ISNUMERIC() accepts values that the PL/SQL While... piece o' crap would have rejected. Examples '+' , '-', ...

Re: Warts and All

2010-06-28 09:07 • by 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.

Re: Warts and All

2010-06-28 09:07 • by 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?

Re: Warts and All

2010-06-28 09:08 • by Aussie Contractor (unregistered)
313026 in reply to 313022
Aussie Contractor:
ISNUMERIC("First") = TRUE; // what ??


Garr !!

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

Re: Warts and All

2010-06-28 09:09 • by Airhead
I think TRWTF is "Select 'Non-Numeric Sequence Provided'" instead of RAISERROR().

Re: Warts and All

2010-06-28 09:09 • by 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.

Re: Warts and All

2010-06-28 09:09 • by 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

Re: Warts and All

2010-06-28 09:10 • by 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 ?

Re: Warts and All

2010-06-28 09:12 • by PleegWat (unregistered)
Clueless manager is clueless. Where's the WTF?

Re: Warts and All

2010-06-28 09:12 • by highphilosopher (unregistered)
313032 in reply to 313029
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...

Re: Warts and All

2010-06-28 09:15 • by frits
Stored procedures are so Enterprise 1.0. Isn't there a cloud computing platform that'll do this for you?

Re: Warts and All

2010-06-28 09:21 • by db2
So what Andy means to tell us is that "123456.789E17" is a valid barcode string in their system? And also "$123456.789"?

Re: Warts and All

2010-06-28 09:21 • by DocBrown
Ah, TheDailyNotAWTF. Shouldn't there be a series tag for that already?

Re: Warts and All

2010-06-28 09:22 • by HuHu
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.

Re: Warts and All

2010-06-28 09:23 • by 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.

Re: Warts and All

2010-06-28 09:28 • by Wizou (unregistered)
313038 in reply to 313036
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')

Re: Warts and All

2010-06-28 09:28 • by 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.

Re: Warts and All

2010-06-28 09:28 • by 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"

Re: Warts and All

2010-06-28 09:29 • by 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."

Re: Warts and All

2010-06-28 09:34 • by SR (unregistered)
313042 in reply to 313039
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?

Re: Warts and All

2010-06-28 09:39 • by 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.

Re: Ugh

2010-06-28 09:39 • by millimeep
313044 in reply to 313021
∃ 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!

Why convert in the database??

2010-06-28 09:39 • by 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.


Re: Warts and All

2010-06-28 09:40 • by Mike D. (unregistered)
313046 in reply to 313040
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.

Re: Warts and All

2010-06-28 09:40 • by Helix
Clueless programmer is clueless. Where's the WTF?

Re: Warts and All

2010-06-28 09:40 • by Franz Kafka (unregistered)
313048 in reply to 313025
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.

Re: Warts and All

2010-06-28 09:42 • by ammoQ
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.

Re: Warts and All

2010-06-28 09:44 • by Steve (unregistered)
I don't get it...this guy was trying to add a T-SQL function into Oracle?

Re: Why convert in the database??

2010-06-28 09:47 • by ammoQ
313051 in reply to 313045
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.

Re: Warts and All

2010-06-28 09:47 • by 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.

Re: Warts and All

2010-06-28 09:48 • by Jon (unregistered)
The real WTF is the manager used the phrase, "think outside the box."

Re: Warts and All

2010-06-28 09:49 • by 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...

Re: Warts and All

2010-06-28 09:52 • by ammoQ
313055 in reply to 313052
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.

Re: Warts and All

2010-06-28 09:54 • by savar
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.

Re: Warts and All

2010-06-28 09:57 • by db2
313057 in reply to 313039
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.

Re: Why convert in the database??

2010-06-28 09:57 • by Jaime
313058 in reply to 313051
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.

Re: Warts and All

2010-06-28 10:02 • by Anonymous (unregistered)
313059 in reply to 313055
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.

Re: Warts and All

2010-06-28 10:07 • by Bert (unregistered)
TRWTF is the choice of language.

Re: Warts and All

2010-06-28 10:10 • by frits
313061 in reply to 313057
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;


Re: Warts and All

2010-06-28 10:14 • by 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.



Re: Warts and All

2010-06-28 10:15 • by toth
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?

Re: Warts and All

2010-06-28 10:17 • by akatherder
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.

Re: Warts and All

2010-06-28 10:20 • by joe.edwards
313066 in reply to 313027
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.

Re: Warts and All

2010-06-28 10:21 • by Adam (unregistered)
313067 in reply to 313028
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.

Re: Warts and All

2010-06-28 10:21 • by WMD (unregistered)
TRWTF is that the code was well documented to begin with.

Re: Why convert in the database??

2010-06-28 10:22 • by lofwyr
313069 in reply to 313058
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.

Re: Warts and All

2010-06-28 10:24 • by Steve (unregistered)
313070 in reply to 313065
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.

Re: Warts and All

2010-06-28 10:26 • by Kef Schecter (unregistered)
313071 in reply to 313031
PleegWat:
Clueless manager is clueless. Where's the WTF?

You're it.
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment