It's more efficient to reuse an existing function than write a new one



  • A business requirement requires us to take several snapshots of several db tables in our production environment each day. Some folks would simply duplicate table X with XHist and add timestamp and snaphot-number columns. This way it's queryable.

    My newly appointed team lead decided instead to create a table with timestamp, snapshot-number and several blob fields, each representing a serialized array of objects that would be in the corresponding db table. Each row totalled about 30 meg. Naturally he had to write a class to query for a row and deserialize it into the corresponding lists of objects. Ok, whatever. It would only be queried twice a day, at most, so performance was not really an issue.

    I was recently handed a new business requirement to determine if any snapshots had been made yet today. Now I freely admit I'm no db-wiz, but I came up with (pseudo code):

    boolean snapshotHasBeenMadeToday() {
      String sql = "select 1 from theTable " +  // oracle
                   "where exists (select 1 from theTable where theDate>=trunc(sysdate))";
      // hibernate stuff omitted
      return !query.list().isEmpty();
    }

    This would short ciruit the query upon finding the first matching row, and return a very small result set.

    During a code review, my lead pointed out that I should use his existing function:

      if (getLatestSnapshot() == null) {
         // no snapshot today
      } else {
         // snapshoat already made today
      }
    

    I pointed out that his method would:

    • scan the entire table, and if a row existed:
    • serialize the whole 30meg
    • transmit the whole thing to the client
    • deserialize the whole 30meg on the client
    • deserialize each blob into the corresponding arrays of objects
    • cause massive memory allocation and subsequent garbage collection on both sides, for no real gain

    He said that this was irrelevant because it's more efficient to reuse an existing function that write a new one.

     



  •  Put a brainfuck interperter into one of your functions and tell him that he should always use that method, since he would never have to write a new function...



  • When it's safe to do so please feel free to share the name of your tech lead and the name of the company so we will know who to avoid.

    Thanks!



  • @dtech said:

     Put a brainfuck interperter into one of your functions and tell him that he should always use that method, since he would never have to write a new function...

     

     

    The hell with brainfuck, us Whitespace:

    http://en.wikipedia.org/wiki/Whitespace_(programming_language)

     

     



  • @snoofle said:

    He said that this was irrelevant because it's more efficient to reuse an existing function that write a new one.

    Why is this kind of fuckery so often found in people in leadership positions? Is there a law that defines this phenomenon?



  • @Smitty said:

    Why is this kind of fuckery so often found in people in leadership positions? Is there a law that defines this phenomenon?
     

    It may be worth pointing out that one definition of "leader" is "the clear piece of tape at the beginning of a cassette that you can't record anything on".



  • @da Doctah said:

    It may be worth pointing out that one definition of "leader" is "the clear piece of tape at the beginning of a cassette that you can't record anything on".

     

     what in the hell is a cassette?



  • @da Doctah said:

    @Smitty said:

    Why is this kind of fuckery so often found in people in leadership positions? Is there a law that defines this phenomenon?
     

    It may be worth pointing out that one definition of "leader" is "the clear piece of tape at the beginning of a cassette that you can't record anything on".

    I also thought that tech lead meant a tech who is as dense (see no. 5) as lead.

    Wherever in hell this lead learned his stuff, they probably told him that the "efficiency" of a given program is defined by x / y, where 'x' is an arbitrary value and 'y' is the amount of lines of code you wrote.

    Yes, I've seen it being taught in a college around here, and that's why I went to another one even though the latter was five times farther away from home.



  • @Smitty said:

    @snoofle said:
    He said that this was irrelevant because it's more efficient to reuse an existing function that write a new one.

    Why is this kind of fuckery so often found in people in leadership positions? Is there a law that defines this phenomenon?

    The peter principle?



  • @Tyler said:

    what in the hell is a cassette?

    It may be worth pointing outh that one definition of "cassette" is a fire-clay box in which earthenware may be placed when being fired in an oven.



  • @arty said:

    @Smitty said:
    @snoofle said:
    He said that this was irrelevant because it's more efficient to reuse an existing function that write a new one.
    Why is this kind of fuckery so often found in people in leadership positions? Is there a law that defines this phenomenon?
    The peter principle?
    +1.



    Though that should be a statement, not a question. (Though in this particular situation, 'Peter' seems to have skipped a level - he doesn't come across as a competant programmer either. And the 'Dilbert Principle' doesn't apply, since they're still being obstructive.)



  • @PJH said:

    ...he doesn't come across as a competant programmer either...

    Bingo!



  • I blame the TDWTF principle, which states:

    Employees will be promoted to the exact level that they can cause enough harm to warrant a story being posted on The Daily WTF.



  • @snoofle said:

    @PJH said:

    ...he doesn't come across as a competant programmer either...

    Bingo!

    Do I win wings? Or aren't they needed for buzzword?


  • @snoofle said:

    He said that this was irrelevant because it's more efficient to reuse an existing function that write a new one.
     

    I hear these sorts of statements a lot. Apart from going postal, there only seems to be one answer.

    "Really? Show me the performance numbers please."



  • @Tyler said:

    @da Doctah said:

    It may be worth pointing out that one definition of "leader" is "the clear piece of tape at the beginning of a cassette that you can't record anything on".

     

     what in the hell is a cassette?

     

    Smacks Tyler

    Quit making me feel old.  I'm too young for that shit.



  • @JohnWestMinor said:

    @Tyler said:

    @da Doctah said:

    It may be worth pointing out that one definition of "leader" is "the clear piece of tape at the beginning of a cassette that you can't record anything on".

     

     what in the hell is a cassette?

     

    Smacks Tyler

    Quit making me feel old.  I'm too young for that shit.

    Old? How could these guys make you feel old? :-)



  • @Tyler said:

     what in the hell is a cassette?
    Kids these days... a cassette is a storage device that was once used to store music like this



  •  Nah, for us kids, cassettes were storage devices used on the TI-99/4A, TRS-80s, and when you're fingers were worn down to nubs, to record songs like... http://www.youtube.com/watch?v=0Tb8Jo11uGo

     That said, unfortunately there were times when your little sister would 'borrow' one of your tapes (usually the one with the longest program stored on it) for...gaahhhh...  http://www.youtube.com/watch?v=b9I6QMyGiBU

     On topic...I vote for The Peter Principle as well, although I tend to lean toward the Dilbert side, simply because no matter how much of a mess they make, 'leaders' rarely know enough to impede a determined team, so they're out of the way (more or less), once the project must be completed, and their job is on the line with everyone else's.  'Leaders' tend to be more of a headache early on, eating up 6 months of schedule trying to decide what color manila folders the project heads should be using...



  • @st1d said:

     Nah, for us kids, cassettes were storage devices used on the TI-99/4A, TRS-80s, and when you're fingers were worn down to nubs, to record songs like... http://www.youtube.com/watch?v=0Tb8Jo11uGo

    See, it's meaningful because when he says: "who is Number 1?" the answer could be read either, "you are Number 6" or "you are, Number 6." And different Number 2's used different readings. OooOOOooo!

    (I love that show.)



  • Just wondering, why did you use:

    String sql = "select 1 from theTable " +  // oracle
    "where exists (select 1 from theTable where theDate>=trunc(sysdate))";
     

    and not
    String sql = "select 1 from theTable where theDate>=trunc(sysdate))";



  • @gribunin said:

    Just wondering, why did you use:
    String sql = "select 1 from theTable " +  // oracle
    "where exists (select 1 from theTable where theDate>=trunc(sysdate))";
     

    and not
    String sql = "select 1 from theTable where theDate>=trunc(sysdate))";

    There are two lines in the first example and one in the second, so you get paid twice as much for the former compared to the latter.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.