- 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
Oracle is great for all things enterprise. Enterprise data storage, enterprise basic mathematics, it has it all!
Admin
It's FutureProof! They can add variable discounts in the future from the DB by just modifying the SQL statement and the DB.
Admin
OMG! Eli totally screwed up the descriptive method name by not using SQL!
Admin
OK, so we know where the Marshal is. But where's LeBeouf?
Admin
I suspect they wanted to use fixed-point numbers when handling currency. Alas, the parameter and return types are all floating-point, which is TRWTF.
Captcha: Your mother is an ULLAMCORPER.
Admin
But the original returns 0 if the DUAL table is empty... :S
Admin
Ugh. If you need to have the differences between Plain Old Code Subtraction (POCS) and Advanced DBMS Subtraction (ADS) explained to you, then you shouldn't be coding at all.
Oh, I know, "they both return exactly the same results".
/facepalm
Get a brain, morans!
:D
Admin
Admin
He should have used a stored procedure. That's TRWTF
Admin
I read Qvazar's comment as a joke, but it's possible that s/he hasn't used Oracle, in which case: what of it? If you haven't used Oracle it's not a dumb comment.
For anyone who doesn't know, DUAL is a stupidly-named built-in read-only table containing exactly one row and column, for use in situations like this.
(Well, not exactly in situations like this, but you get the point.)
Admin
Looks like code that once needed something from the database (e.g. tax information) which was subsequently removed so just the substraction was left. I guess there was no source control information about it, so the history is unknown.
Admin
But if the DB is down or any other exception is thrown, a big old zero is returned. I guess if the DB is down, everything's free!
Admin
read the code. resp is defaulted to 0.
If there is a row, it gets a value, otherwise it leaves resp alone.
and then returns it.
The original poster got it right - it returns 0 if dual is empty - which can happen in 9i and before (in 10g with fast dual - unlikely)
Admin
Stop faking. You're not real Mr Tom Kyte, are you? Unless he's a namesake of yours.
Admin
There's nothing I hate worse than random abbreviations in variable names. Why 'String quer = null'? Is 'String query = null' simply too much to type? I see this kind of thing all the time.
Admin
Actually the problem is that they are using double datatype as amount and they have found out that using sql seem to return the rigth value.
Have had the same problem with c++, there is no round function, had serious temptation to use oracle sql as well.
Admin
Hear, hear. Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea?
Admin
Ugh, tell me about it. I know someone who, I am not making this up, uses an automated script to get rid of vowels in his identifiers. I gss thr s vwl shrtg r smthng.
Admin
TRWTF is that they directly put the variables into the query. They should have at least used named variables nods
Admin
Ken Thompson was once asked what he would do differently if he were redesigning the UNIX system. His reply: "I'd spell creat with an e."
Admin
This reminds me of a developer who used to do everything in Oracle. This was a different developer from the one who did everything in C.
Once, I had to replace her code to do 128-bit DES3 encryption (yes, that's not a typo) by Java code, which was quite an interesting challenge, especially so because DES encryption is usually 64-bit (DES) or 192-bit (DES3). This was something like, DES2?
Admin
Admin
They used Oracle for BigNum support.
TRWTF is the conversion to double...
Admin
Wait for it... wait for it... he already did!
Admin
Admin
(evil laugh) Layers!!!! (even more evil laugh) We MUST have MORE layers!!!!
Admin
Me.
Admin
He had to abbreviate it, because he was afraid "query" was a reserved word.
Admin
This article has made my day !!! :))
Admin
When I read the code snippet, in my mind I saw all of the townsfolk locking their doors and slamming their shutters as Marshall Eli stands in the middle of the town crossroads.
Admin
Would rs.first() be true if dual contains no rows?
Admin
Using doubles for calculations on monetary amounts!? At least there was a attempt to close the connection in a finally.
Admin
wow, so there's and Exception... catch it, print the stack trace and return 0.
Admin
fd = crate("fred.txt", 0664);
Admin
Admin
Obviously, TRWTF is not putting whitespace around binary operator ;)
return cost - discount;
Admin
I was sure this was going to end with:
put it out of its misery, by erasing the out dated, rogue application from the network.
Admin
Joe client is gonna be pretty pissed off when he finds out you 'rounded off' his MONEY.
This could have been done in an attempt to get proper BCD data types to be used in the calculation, but there's nothing telling the database to do it that way either.
Admin
Avoiding some sort of floating point error? Or keeping consistent floating math? Or maybe it evolved from something more monstrous...
Actually I just kicked back some code last week that used a temp table to filter some data.
Admin
The reason for using a database for subtraction, addition etc. is of course quite clear. If theyr definition of subtraction changes in the near or far future, a simple change in the database will solve all problems, while the job of going through each and every file to fix the problem would require quite a lot of work.
Admin
They could also ask it to Wolfram Alpha and then parse the returning webpage :-)
http://www.wolframalpha.com/input/?i=5-7
Captcha veniam
Admin
These things are fun, but it's really just another example of a project that ran out of time or ambition or direction.
Speculation, but once-upon-a-time at the start of the project, somebody decided the didn't want business logic in the GUI (is good!)
Someone else agreed, and someone else said they should stick it in a nice stored procedure, because that can be reused, and it's sitting next to the data we'll use for the calculation and we have development resource for it, and blah, blah, blah, fucking blah.
Anyway. The developer in question wrote in in such a way as to prove the route - the GUI can talk to the DB, there are no firewall or permission problems, and they can get back the magic scalar value as required.
I'd follow exactly this approach rather than spend time chasing down infrastructural problems and getting bit on the arse later.
But the calculation never was more complicated, or the vast reusable enterprise calculation engine was never written, or the developer moved on and nobody cared enough.
But I'd guess the developer was right.
Admin
Get with the enterprisey times! Do it in the cloud! Use Google Calculator!
Admin
I would replace this with a call to a local instance of Excel. Perhaps I'd be even more creative and use a JavaScript ScriptEngine to evaluate the string.
Admin
There's plenty of optimisation opportunities before you need to do the calculation client side! Surely he would have done better to get in a database consultant who could have helped tune that query...?
Admin
2 - 2 == 5
Admin
Where to begin? Using SQL for addition (when the processor supports it natively), breaking standards when naming class level variables (see: dbm), and setting a local object reference to null RIGHT BEFORE the fucking function exits.
Who do I have to kill?
Admin
Admin
This was in commercial software that we bought the source for, btw.
Admin
Make calculateCostSQL a "Human Task", so whenever invoked an automated email containing the parameters is sent to a Senior Arithmetic Analyst, who performs the subtraction (using a database), pulls up the Subtraction Response form, and submits the difference, which is then placed in the Cost Calculation queue for the application to receive.
Sure, it needlessly slows processing time, but it evenly distributes the work over more company resources.