| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
Oracle is great for all things enterprise. Enterprise data storage, enterprise basic mathematics, it has it all!
|
|
It's FutureProof! They can add variable discounts in the future from the DB by just modifying the SQL statement and the DB.
|
|
OMG! Eli totally screwed up the descriptive method name by not using SQL!
|
|
OK, so we know where the Marshal is. But where's LeBeouf?
|
|
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. |
|
But the original returns 0 if the DUAL table is empty... :S
|
|
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 |
Re: The Marshal
2011-02-14 09:19
•
by
Mr obvious
(unregistered)
|
You haven't used Oracle much, have you? |
|
He should have used a stored procedure. That's TRWTF
|
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.) |
|
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.
|
|
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!
|
|
read the code. resp is defaulted to 0.
if(rs.first()) resp = rs.getDouble("result"); 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) |
Stop faking. You're not real Mr Tom Kyte, are you? Unless he's a namesake of yours. |
|
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.
|
|
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. |
Hear, hear. Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea? |
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. |
|
TRWTF is that they directly put the variables into the query. They should have at least used named variables *nods*
|
http://en.wikiquote.org/wiki/Kenneth_Thompson 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." |
|
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? |
It was actually meant to be 'queer'. You know, as in 'strange'. |
|
They used Oracle for BigNum support.
TRWTF is the conversion to double... |
Wait for it... wait for it... he already did! |
Who hasn't done something like this? |
|
(evil laugh) Layers!!!! (even more evil laugh) We MUST have MORE layers!!!!
|
Me. |
He had to abbreviate it, because he was afraid "query" was a reserved word. |
|
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.
|
Would rs.first() be true if dual contains no rows? |
|
Using doubles for calculations on monetary amounts!? At least there was a attempt to close the connection in a finally.
|
|
wow, so there's and Exception... catch it, print the stack trace and return 0.
|
I dunno, maybe he meant, like, at the end. fd = crate("fred.txt", 0664); |
Yeah, if only there was a way to call plain old C functions like round() from C++. I guess you need a multi-layered OOP framework for this ... |
|
Obviously, TRWTF is not putting whitespace around binary operator ;)
return cost - discount; |
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. |
|
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. |
|
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. |
|
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.
|
|
They could also ask it to Wolfram Alpha and then parse the returning webpage :-)
http://www.wolframalpha.com/input/?i=5-7 Captcha veniam |
Re: The Marshal
2011-02-14 12:00
•
by
Sean Inglis
(unregistered)
|
|
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*. |
|
Get with the enterprisey times!
Do it in the cloud! Use Google Calculator! |
|
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.
|
|
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...?
|
2 - 2 == 5 |
|
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? |
ROFLMAO |
There's nothing wrong with that use of temp tables (at least not as you stated it). I turned a 10.5 hour-long query into an 8 second one by unrolling nested WHERE NOT EXISTS with a temp table. This was in commercial software that we bought the source for, btw. |
Why not integrate it into the workflow? 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. |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |