• Oracle Marketer (unregistered)

    Oracle is great for all things enterprise. Enterprise data storage, enterprise basic mathematics, it has it all!

  • BlackBart (unregistered)

    It's FutureProof! They can add variable discounts in the future from the DB by just modifying the SQL statement and the DB.

  • (cs)

    OMG! Eli totally screwed up the descriptive method name by not using SQL!

  • (cs)

    OK, so we know where the Marshal is. But where's LeBeouf?

  • Ben (unregistered)

    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.

  • Qvazar (unregistered)

    But the original returns 0 if the DUAL table is empty... :S

  • Mojo (unregistered)

    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

  • Mr obvious (unregistered) in reply to Qvazar
    Qvazar:
    But the original returns 0 if the DUAL table is empty... :S
    You haven't used Oracle much, have you?
  • andres (unregistered)

    He should have used a stored procedure. That's TRWTF

  • no name (unregistered) in reply to Mr obvious
    Mr obvious:
    Qvazar:
    But the original returns 0 if the DUAL table is empty... :S
    You haven't used Oracle much, have you?

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

  • TST (unregistered)

    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.

  • Mikey (unregistered) in reply to Mr obvious

    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!

  • tkyte (unregistered) in reply to Mr obvious

    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)

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

  • (cs)

    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.

  • dr dirsa (unregistered)

    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.

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

    Hear, hear. Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea?

  • anon (unregistered) in reply to Smitty
    Smitty:
    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.

    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.

  • SG_01 (unregistered)

    TRWTF is that they directly put the variables into the query. They should have at least used named variables nods

  • (cs) in reply to Cantabrigian
    Cantabrigian:
    Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea?
    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."

  • (cs)

    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?

  • (cs) in reply to Smitty
    Smitty:
    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.
    It was actually meant to be 'queer'. You know, as in 'strange'.
  • (cs)

    They used Oracle for BigNum support.

    TRWTF is the conversion to double...

  • anon (unregistered) in reply to dpm
    dpm:
    Cantabrigian:
    Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea?
    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."

    Wait for it... wait for it... he already did!

  • frits (unregistered) in reply to Smitty
    Smitty:
    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.
    Who hasn't done something like this?
  • (cs)

    (evil laugh) Layers!!!! (even more evil laugh) We MUST have MORE layers!!!!

  • (cs) in reply to frits
    frits:
    Smitty:
    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.
    Who hasn't done something like this?

    Me.

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

    He had to abbreviate it, because he was afraid "query" was a reserved word.

  • (cs)

    This article has made my day !!! :))

  • (cs)

    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.

  • Mark (unregistered) in reply to tkyte
    tkyte:
    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)

    Would rs.first() be true if dual contains no rows?

  • - (unregistered)

    Using doubles for calculations on monetary amounts!? At least there was a attempt to close the connection in a finally.

  • someone (unregistered)

    wow, so there's and Exception... catch it, print the stack trace and return 0.

  • (cs) in reply to anon
    anon:
    dpm:
    Cantabrigian:
    Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea?
    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."

    Wait for it... wait for it... he already did!

    I dunno, maybe he meant, like, at the end.

    fd = crate("fred.txt", 0664);

  • foo (unregistered) in reply to dr dirsa
    dr dirsa:
    Have had the same problem with c++, there is no round function
    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 ...
  • Neo (unregistered)

    Obviously, TRWTF is not putting whitespace around binary operator ;)

    return cost - discount;

  • (cs)
    He simply strung up the code and put it out of its misery, replacing the entire body with a simple 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.

  • (cs) in reply to foo

    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.

  • zdux (unregistered)

    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.

  • martiert (unregistered)

    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.

  • Spike (unregistered)

    They could also ask it to Wolfram Alpha and then parse the returning webpage :-)

    http://www.wolframalpha.com/input/?i=5-7

    Captcha veniam

  • Sean Inglis (unregistered) in reply to Oracle Marketer

    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.

  • Ollie Jones (unregistered)

    Get with the enterprisey times! Do it in the cloud! Use Google Calculator!

  • (cs)

    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.

  • Paul (unregistered) in reply to Oracle Marketer

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

  • Pytry (unregistered) in reply to martiert
    martiert:
    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.

    2 - 2 == 5

  • (cs)

    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?

  • (cs) in reply to frits
    frits:
    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.
    ROFLMAO
  • (cs) in reply to zdux
    zdux:
    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.

    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.

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

Leave a comment on “The Marshal”

Log In or post as a guest

Replying to comment #:

« Return to Article