• Chris Perkins (unregistered) in reply to Someone, Somewhere, outwhere
    Anonymous:
    ...so let's expand this function (translated into php for clarity)...

    Translated into PHP for CLARITY?

    Now THAT'S funny.

  • Christoffer (unregistered)

    The real WTF is obviously that the application is called "the application" and not "The Application".

  • (cs) in reply to Bela

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p> 

  • This isn't java (unregistered) in reply to slavik

    You guys still seem to question whether this is java or not.  Java doesn't have an ArrayList.Count so it's not java.  But it does exist in the .NET ArrayList. 

     

  • J. B. Rainsberger (unregistered)

    The first lesson I learned about XP is that it can't magically turn a bunch of average people into high performers. In retrospective, I'm embarrassed at having needed to learn that lesson again, but that's how it went.

  • (cs)

    first.. the function returns NULL or an array
    I'd return an array, empty or not. But not NULL.

    public ArrayList GetRoles()
    {
      .....
      return null;
    }


    then we check for a not-null member?/method? and branch from there. Id probably do that too.

      if (this.getRols() != null)
      {
     ....
      }


    then it gets weird..

    we seem to be in an instance of *this*. proven by the call to this.getRols()
    which leads me to believe that instance *this* has a method getRols()
    or has a member of class getRols. Probably the later.

    Then there is the <<< NEVER RE-EVALUATE SOMETHING NEEDLESSLY. >>> thing within the loop

        while (roles.Count < getRols().Count)
        {
        }
    <FONT color=#0000ff>consider a generic for() loop:</FONT>

    <FONT color=#0000ff> for(min;max;increment){}</FONT>

    <FONT color=#0000ff>I would hope to NEVER see any function() in the second argument. like:</FONT>

    <FONT color=#0000ff> for(min;max();increment){}</FONT>

    unless getRols() is a moving target, it's needless re-evaluation.

    so we see...
        while (roles.Count < getRols().Count)
        {
         ... where getRols() is re-tested each iteration. That sucks.
         
         ... then we re-instantiate role...or no... getRols() is a static class
           RoleClass role = (RoleClass)getRols().Item[roles.Count];
         
         ... so role object can feed roles.Count via the roles.add() method ... to increment it
          roles.Add(role);
       }

     so that we can finally return roles as an array.
     return roles;
     
    Seems to me, the WTF is that a class was built simply to populate an array. Not to mention it needs a subordinant to actually perform the population.

    This is abstraction at it's finest - aside from the needless loop gymnastics.

  • (cs) in reply to Chris Perkins

    Anonymous:
    Anonymous:
    ...so let's expand this function (translated into php for clarity)...
    Translated into PHP for CLARITY? Now THAT'S funny.

    I like PHP.. it's fun. 

    Bring it on Brother.

  • (cs) in reply to Ross Patterson
    Anonymous:
    Yup, that's Brooks all right. TMMM was controversial at the time, but he followed it up with "No Silver Bullet", an essay that basically claimed that there was nothing that would improve productivity by several orders of magnitude. Not even Agile Scrum methodologies du jour :-)

    Except for maybe the part about bothering to unit test your code. ;-)

  • SpasticWeasel (unregistered) in reply to An apprentice

    Doesn't getRols() indicate that it is a method. Which means that the underlying code for the method is executed every time it is called? Which means that whatever is in getRols() is done twice for every iteration through the loop?

  • (cs)
    <font size="3">These guys obviously never heard of loop unrolling.</font>

    public ArrayList GetRoles()
    {
    if (this.getRols() != null)
    {
    ArrayList roles = new ArrayList();
    if(getRols().Count == 0)
    {
    }
    else if(getRols().Count == 1)
    {
    RoleClass role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    }
    else if(getRols().Count == 2)
    {
    RoleClass role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    }
    else if(getRols().Count == 3)
    {
    RoleClass role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    }

    /*

    Snip (9000 lines)

    */

    else if(getRols().Count == 1000)
    {
    RoleClass role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);

    /*

    Snip (2000 lines)

    */
    }
    else
    {
    return null;
    }
    return roles;
    }
    return null;
    }


  • NotQuiteReal (unregistered) in reply to Bitruder
    You meant to see:


    public
    ArrayList GetRoles()
    {
    return this.getRols()
    }
  • test (unregistered) in reply to Shizzle

    Anonymous:
    Well, at least it works.  I guess that is what makes it a WTF.  In Java, (I'm sure C#, a blatant copy of Java, has similiar) you could reduce it to...

    public ArrayList getRoles() {
        return getRols() == null ? null : new ArrayList(getRols());
    }

    better that way :

    public ArrayList getRoles() {
        return getRols() == null ? null : new ArrayList().addAll(getRols());
    }

  • (cs) in reply to jspenguin
    jspenguin:
    No... roles.Count increases with each item you add to it... I think. Is that C#? It's not Java.

    It'll compile in Java if you do this (note that it's ok to create a class called ArrayList as long as it's not in the java.util package):
    public class RoleClass { }

    public class ArrayList
    {
      RoleClass[] Item;
      int Count;
      public void Add( RoleClass role ) { }

    public ArrayList GetRoles( )
    {
    if (this.getRols() != null)
    {
    ArrayList roles = new ArrayList();
    while (roles.Count < getRols().Count)
    {
    RoleClass role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    }
    return roles;
    }
    return null;
    }

    public ArrayList getRols( )
    {
    ArrayList rv = new ArrayList();
    // TODO: populate somehow with database stuff
    return rv;
    }
    }
    Won't be much use, but eh :)

  • (cs) in reply to Matt
    Anonymous:
    Anonymous:
    ...snip

    catch(Exception e) { throw e; }

    hey .Net Developer - please if you are going to rethrow an exception, just call throw, not throw e.

    This will lose the stack trace and you will never see the real eror.



    Hey, if you're going to just rethrow the same error, why the hell did you bother catching it in the first place?

  • (cs) in reply to Patrys
    Anonymous:
    <font face="Courier New">public Bool GetRollz0rz(int SuperFluous)
    {
        EnterpriseTable paula = new WoodenTable();
        paula.Refactor(GetRoles() == null ? null : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2]));</font>
    <font face="Courier New">    return FileNotFound;</font>
    <font face="Courier New">}
    </font>



    Ummm how do you know GetRoles() returns either null or 3 items? I think you mean:

    <font face="Courier New">public Bool GetRollz0rz(int SuperFluous)
    {
        EnterpriseTable paula = new WoodenTable();
        paula.Refactor(GetRoles() == null ? null :
            GetRoles().Length == 1 : (</font><font face="Courier New">new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">) :
            GetRoles().Length == 2 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1]) :
    </font><font face="Courier New">        GetRoles().Length == 3 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2]) </font><font face="Courier New">:
    </font><font face="Courier New">        GetRoles().Length == 4 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2])</font><font face="Courier New"> </font><font face="Courier New">.Add(GetRoles().Item[3]) </font><font face="Courier New"> </font><font face="Courier New">:
    </font><font face="Courier New">        GetRoles().Length == 5 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2])</font><font face="Courier New">.Add(GetRoles().Item[3])</font><font face="Courier New">.Add(GetRoles().Item[4])</font><font face="Courier New"> </font><font face="Courier New"> </font><font face="Courier New">:
    </font><font face="Courier New">        GetRoles().Length == 6 : (new ArrayList()).Add(GetRoles().Item[0])</font><font face="Courier New">.Add(GetRoles().Item[1])</font><font face="Courier New">.Add(GetRoles().Item[2])</font><font face="Courier New">.Add(GetRoles().Item[3])</font><font face="Courier New">.Add(GetRoles().Item[4])</font><font face="Courier New">.Add(GetRoles().Item[5])</font><font face="Courier New"> </font><font face="Courier New"> </font><font face="Courier New"> </font><font face="Courier New">:
    </font><font face="Courier New">        new Brillant());
    </font><font face="Courier New">   return FileNotFound;</font>
    <font face="Courier New">}</font>
  • (cs)

    hehe, that's bad, but not that bad, or, wait, that's really bad actually... hohoho ;)

  • Anonymous WTFer (unregistered) in reply to Shizzle
    Anonymous:
    Well, at least it works.  I guess that is what makes it a WTF.  In Java, (I'm sure C#, a blatant copy of Java, has similiar) you could reduce it to...

    public ArrayList getRoles() {
        return getRols() == null ? null : new ArrayList(getRols());
    }

    This is assuming, of course, that for some reason you need a copy of the ArrayList instead of the actual instance member of it.  Also, What The F is a "Rol"?

    On the other hand, the coder was rather clever in not having to use a pesky variable to count over the ArrayList, just use the count of the one you are building instead!  (WTF is an iterator, anyway! or even the addAll method!)

    Not really a horrible WTF, but I am glad to see more code here again.



    I call WTF.

    Dude, you're still calling getRols() twice... unless it returns null the first time. No soup for you!

  • spacedman (unregistered) in reply to Anonymous WTFer

    It only 'works' for some value of 'works'. Suppose it calls getRols and its told there are 10 rows. And then while the loop is running someone else deletes a row from the database. Uh oh. What happens when it goes to get ist 10th row? Crashtastic. Debug that.

    If you want to get something from a database get it all in one go - or use cursors and tread carefully...

  • anonymous (unregistered) in reply to Anonymous WTFer

    For completness:

    As a C programmer, I will never call a procedure or function inside

    <font color="#0000ff">for ( t=0;t < (max = GetMax(screen));t++){
      DrawPixel(m,t);
    }</font>

    but:

    <font color="#0000ff">max = GetMax(screen);
    for ( t=0;t < max; t++){

      DrawPixel(m,t);

    }
    </font>
    then with OOP the difference of function/method is blended

    <font color="#0000ff">for (t=0;t< screen->getMax();t++){
      DrawPixel(m,t);
    }</font>

    this code is NOT that bad. Is a step away a huge optimization, is suggested to not do that, but is not a rule.
    I mean, a getter mostly is about to get existing values, but to isolate internal from external, so you can change implementations, etc.
    A simple enough getter mean, the perfomance hit is neligible.

    This one is ugly:

    <font color="#0000ff">for (t=0;t< screen->getMaxFromDB();t++){

      DrawPixel(m,t);

    }</font>

    This one is ugly, because mean you are doing a mayor work you can avoid.

    Yet another implementation, for speed, if Max not change, is to have a global variable (but you need to fill that global first on initialization!):

    f<font color="#0000ff">or (t=0;t < screenSpecs.maxx;t++){
      DrawPixel(m,t);
    }</font>

    or even a DEFINE

    <font color="#0000ff">#define SCREEN_MAXX 768

    for (t=0;t < SCREEN_MAXX ;t++){

      DrawPixel(m,t);

    }</font>

    The better optimization is to rewrite withouth a loop:
    <font color="#0000ff">
    DrawLine( m,0,m, SCREEN_MAXX);

    </font>On a good lang , maybe you can even do that:<font color="#0000ff">

    screen.line( orgX: m , orgY: 0,
                         endX: m, endY:  screen.SCREEN_MAXX);
    </font>
    --Tei












  • Tbee (unregistered) in reply to Shizzle

    Judging from the name of the submitter, "Rol" is Dutch for "Role". But since two roles are called "Rollen", this "Rols" must a mixture between English and Dutch, famously known as Denglish.

  • IDK (unregistered) in reply to JustThat
    JustThat wrote the following post at 08-08-2006 7:32 PM:

    Oh, my, yes. Translating it into php certainly made it clearer...

    ...kinda like cleaning a window with mud.


    That wouldn't do any difference :)


  • some moron (unregistered) in reply to You're all stupid
    Anonymous:

    I'll start by saying this is the first visit to www.thedailywtf.com .

    While this article is what I would consider a "WTF?", the comments on here are by far worse. Don't criticize code you can't even read properly. My lord.



    on the contrary... people should criticize code they haven't read properly as much as they possibly can.

    the entertainment they provide is far superior to the original wtf itself.

    where did beanbag girl go? not as classy as fússball girl, but I'm sure she wears bigger earrings!


  • Yariv (unregistered) in reply to tlf

    What might be really interesting is that, if another user removes a role from the data base when the method is just about to retrieve the last role, an ArrayIndexOutOfBounds will be thrown! Its not only preforemence, since getRols might really return different values, which will bring a variety of interesting behaviours.

  • Sofayeti (unregistered) in reply to Anymoose Jr

    as a jr developer myself:


    public ArrayList GetRoles(){
        ArrayList roles = getRols();
        return roles==null?   null  : roles.Clone();
    }


    or if I am feeling "clever"...


    public ArrayList GetRoles(){
        ArrayList roles;
        return null==roles=getRols()? roles : roles.Clone();
    }




    I really think you should improve on your code formatting. And I don't mean the &nbsp;. Readability is a goal that cannot be overvalued.

    Sofayeti
  • some moron (unregistered) in reply to Sofayeti
    Anonymous:

    as a jr developer myself:


    public ArrayList GetRoles(){
        ArrayList roles = getRols();
        return roles==null?   null  : roles.Clone();
    }


    or if I am feeling "clever"...


    public ArrayList GetRoles(){
        ArrayList roles;
        return null==roles=getRols()? roles : roles.Clone();
    }




    I really think you should improve on your code formatting. And I don't mean the &nbsp;. Readability is a goal that cannot be overvalued.

    Sofayeti


    notice the quoting of "clever". proposed option 1 doesn't look too bad.
  • (cs) in reply to Sarusa
    Anonymous:
    You know, there's nothing really wrong with using junior programmers as long as you have someone in charge who knows what s/he's doing and can mentor them. That's the real WTF here.


    Oh no, you must be another non-believer!  Cast your demons -- its time you convert and realize that Brooks was right:  The only way its OK to use junior programmers is if you are willing to pay ten of them to do the job of one good senior developer.  It has been proven time and time again.

    Check out the Mythical Man Month, by Fred Brooks, for other project management gems.

        dZ.

  • (cs) in reply to Name withheld to protect the innocent
    Anonymous:
    Anonymous:
    In Java, (I'm sure C#, a blatant copy of Java, has similiar) you could reduce it to...


    C'mon.  Everyone knows that C# is a blatant copy of Delphi, not Java.  :)


    But insn't Java a blatant copy of Turtle Graphics' Logo?

        -dZ.
  • (cs) in reply to GoatCheez
    GoatCheez:

    16 times... wow... that's REALLY bad... REALLY REALLY bad. Are you sure these were junior developers and were not monkeys?

    ;-P



    Monkeys typically hit the database about 12 times per loop, so I think it was probably junior developers this time.

        dZ.
  • (cs) in reply to You're all stupid
    Anonymous:

    I just thought it was funny how many people said, "OMG it's always null what a bad programmer" or "here's a better (bloated) 25 line way of doing this extremely simple and redundant function".  It had humor beyond the article itself.


    Welcome to the Real Point of this forum!

        dZ.
  • (cs) in reply to Yaytay
    Anonymous:

    Anonymous:

    On the importance chain Integrity > Performance  always.

    Not always.

    Very rare for something to be "always" in this business.

    Sometimes a quick rough idea is good enough.

    But nearly always, I'd have to give you that.



    Roger, is that you??

    How many tight-assed, obsessive "argument hi-jackers" are actually out there?  You know what I mean, where conversations usually go like this:

    - Could you pass me that blue pen, please?
    - There is no blue pen
    - But... its right there on the desk!
    - Oh, that pen: its not blue.
    - WTF? Its blue! I have the black one, the one over there is red, and this one is blue.
    - No, its not blue.  Technically, its a white cylindrical pen, with a sorta cyanish cap, with blue *ink*, but its definitely not a "blue pen".
    - {clenching teeth} Could you pass me, then, the cylindrical white pen, with a sorta cyanish cap, that writes in blue ink, please?
    - {grinning} Sure, here you go.

    {I then stab him in the eye with the fscking blue pen}

    Lighten up!

        dZ.


  • Dagur (unregistered) in reply to BiggBru

    That's what the germans thought in ww2 before their fancy tanks lost to the russian t-34's

  • zamies (unregistered) in reply to First-time-poster
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    public ArrayList GetRoles()
    {
    if (this.getRols() != null)
    {
    ArrayList roles = new ArrayList();
    while (roles.Count < getRols().Count)
    {
    RoleClass role = (RoleClass)getRols().Item[roles.Count];
    roles.Add(role);
    }
    return roles;
    }
    return null;
    }



    this isn't really making me scream  wtf.   At least we are seeing code examples again.

    It's possible you need to look more closely, and realize that every getRols() is hitting the database.  Especially all those buggers in the while loop...



    especially when this->getRols() (Love that name by the way) already does what this->getRoles() tries to do
  • TC (unregistered) in reply to NT
    Anonymous:
    And as someone above pointed out, regardless of whether getRols hits the database or not, the above mentioned is still the case and its still a major WTF because every time getRols() is called unnecessarily it pushes a new instances of that function onto the stack, allocating memory and stealing cpu time unnecessarily. The fact that it does hit the database magnifies the problem because then it gets to steal time away resources from the machine the database resides on as well as eat network bandwidth.


    Actually, growing/shrinking the stack uses trivial amounts of CPU time and doesn't "allocate" memory in any sane (compiled to machine code, for the most part) language/platform (and even in Java/.NET it should be possible to JIT compile it so it doesn't allocate memory).

    It looks like code written in .NET<2.0, since 2.0 has generics (which are fluffy). I think it does serve a function, though, and that's to perform the cast to RoleClass (the class name is another WTF). In .NET, you can overload both explicit and implicit casts, e.g. a = (string[])listOfStrings could be equivalent to listOfStrings.ToArray().

    Nevertheless, the code is so bad it's probably a port of something in VB or so, written by someone who hasn't learned about features in .NET. I fondly remember using various hacks to get my code to run properly (except back then I used RB), but this is inexcusable with a decent set of classes (not that .NET is decent).

    Captcha = zork
  • Dave (unregistered) in reply to matt

    Anonymous:

    this isn't really making me scream wtf.   At least we are seeing code examples again.

    WTF!!

  • (cs) in reply to First-time-poster
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    public ArrayList GetRoles()
    {
      if (this.getRols() != null)
      {
        ArrayList roles = new ArrayList();
        while (roles.Count < getRols().Count)
        {
          RoleClass role = (RoleClass)getRols().Item[roles.Count];
          roles.Add(role);
        }
        return roles;
      }
      return null;
    }



    this isn't really making me scream  wtf.   At least we are seeing code examples again.

    It's possible you need to look more closely, and realize that every getRols() is hitting the database.  Especially all those buggers in the while loop...



    Ouch.

  • Dave (unregistered) in reply to Someone, Somewhere, outwhere

    Anonymous:
    every call to getRols() performs a multiple-row-resultant query on the database

    so let's expand this function (translated into php for clarity), and include what it's calling..

     

    WTF!

  • US Navy Commander (unregistered) in reply to Matt
    Anonymous:
    [...]please if you are going to rethrow an exception, just call throw, not throw e. This will lose the stack trace and you will never see the real eror.


    Now THERE's the REAL WTF.
  • (cs) in reply to gremlin
    gremlin:
    Anonymous:
    Anonymous:
    ...snip

    catch(Exception e) { throw e; }

    hey .Net Developer - please if you are going to rethrow an exception, just call throw, not throw e.

    This will lose the stack trace and you will never see the real eror.



    Hey, if you're going to just rethrow the same error, why the hell did you bother catching it in the first place?


    A coding double-play, maybe? Gates-to-Ballmer-to-Ellison

  • KattMan (unregistered) in reply to JustThat

    You know on a side note:

    I had a debate with brooks once through email (part of which was printed in the programmer's journal) and my final conclusion was that while his theory is sound he was totally wrong in his assessment.

    It basically came down to this:

    He stated that adding programmers will slow down a project, end of story, finito.  I countered by saying that if that were the case no project would have more than one programmer but in reality, adding programmers will reduce the time to production.  He countered basically saying He was right and I was wrong and that was the way of the world.  This is where our published correspondence ended, of course he was the one controlling it.

    The extended version went one more step.  The entire issue is about Return On Investment (ROI).  One programmer will take 100% of the time to complete a project, a 3 week project takes 3 weeks. Two programmers does not cut the time in half to 1.5 weeks but rather reduces it to maybe 2 weeks.  In man-hours we increased the time (making him correct in theory) but in reality we reduced the time to market (making me correct in practice).  I stated that there will come a time where you start adding programmers and get a negative ROI but until such time you are shortening your time to market albiet with increased cost.

    The problem with this is that most project managers either think adding someone will cut the time equally (a flat ROI) or listen to Brooks without understanding the context and always refuse to add more help when it really is needed.

  • KattMan (unregistered) in reply to KattMan

    I should say that the above is written with the assumption that the programmers involved are compitant;  Incompitant programmers start out with a negative ROI.

  • (cs) in reply to dasmb
    dasmb:
    Anonymous:

    So.... What happens when getRols() returns null?



    It never should.  If somebody has no roles, you should be returning the empty set, not null.  That's why we use collections.


    My thoughts exactly.

    Incidentally, the legacy portions of our system (which are still in the majority, though my boss is hoping to rectify that soon) depended on a database component which had the following helpful properties:

    * It did its own connection pooling. Which was broken. It would never release connections, and it would return them to the pool without doing any reinitialization.  This created some MAJOR headaches when one component did BEGIN TRANSACTION and never did a COMMIT or ROLLBACK, then the connection (still in the transaction) was returned to the pool and handed off to the next component... causing mysterious data loss, until I figured out that's what it was.

    * Most of the code was written in VB6 (honestly, as bad as VB is, it's far easier to write stuff in than C++). Using parametrized SQL Server stored procedure invocations (good). But VB isn't strongly typed.  Therefore, in order to avoid needing CCur() and CInt() and whatnot everywhere, the code did this:
    1. Fetch all of the parameters for the stored proc from the database.
    2. Take the parameters passed in from the caller, match them up to the list in #1, and use VariantChangeType to convert them automatically.

    This was clever and convenient. Unfortunately, there was no caching involved here, so some procs with *lots* of parameters actually spent more time getting the parameter info than executing the proc.

    Oh, incidentally, this was really only necessary because the one type conversion SQL Server won't do automatically is string -> currency (varchar -> money).

    * Here's the part relevant to your message I quoted above: In a gross blunder, the component returned the recordset object through an output parameter into a variant.  Futhermore, under most circumstances, instead of an empty recordset, it would return Nothing.  Otherwise, it might return VT_NULL or VT_EMPTY. It wasn't consistent. This led to this beautiful code (thanks to a lack of short-circuit evaluation):

    dim recordset, error as long
    error = conn.ExecuteStoredProc("my_sp", recordset)
    if error = 0 then
       if IsObject(recordset) then
        if not Recordset Is Nothing then
          ' code
        end if
      end if
    end if

  • Foo (unregistered)
    Alex Papadimoulis:
    public ArrayList GetRoles()
    {
      if (this.getRols() != null)
      {
        ArrayList roles = new ArrayList();
        while (roles.Count < getRols().Count)
        {
          RoleClass role = (RoleClass)getRols().Item[roles.Count];
          roles.Add(role);
        }
        return roles;
      }
      return null;
    }

    getRols(), as you may have guessed, also returned an ArrayList; but unlike GetRoles(), it went to the database to retreive the user's roles.



    LOL! That's friggin' hilarious! every time you hit the top of the while loop you're running a new query!!! WTF? Do you expect new roles to be appended while you're building your ArrayList? WTF? What's wrong with the first Array List? WTF? If you have to cast to RoleClass can't you do it in the original getRols call? WTF? Why is it getRols and not getRoles?

    Funniest DWTF in a long time.
  • ChiefCrazyTalk (unregistered) in reply to Name withheld to protect the innocent
    Anonymous:
    Anonymous:
    In Java, (I'm sure C#, a blatant copy of Java, has similiar) you could reduce it to...


    C'mon.  Everyone knows that C# is a blatant copy of Delphi, not Java.  :)

    Very true, since they were written by the same guy who Microsoft "Stole" away from Borland - Anders whats-his-name.

    CAPTCHA = (for) shizzle!

  • (cs) in reply to You're all stupid

    <!--StartFragment -->

    I'm also stupid:

    I just thought it was funny how many people said, "OMG it's always null what a bad programmer" or "here's a better (bloated) 25 line way of doing this extremely simple and redundant function".  It had humor beyond the article itself.

    That's one of the great things with this site, and has been mentioned several times before... It's actually not impossible that Alex ('Alex') uses TDWTF as some sort of psychology experiment by presenting fabricated 'WTF stories' just to lure 'WTF people' into proving themselves to be just that. Perhaps some of us will even turn up in some academic papers, or even a book! Now THAT would be the real WTF?!?!?!?

  • Mark Hooijkaas (unregistered) in reply to GoatCheez

    To make matters even worse (not taht it matters a lot if the code is bad). The code doesn't seem to be very thread safe. If the database changes during the execution of this function (e.g. adding or removing a role), it is possible that the array returns contains invali entries that never have existed in such a combination. I guess it is a good thing that teh function isn't thread safe though. Imagine this function to synchronize or lock the table or whatever. That could bring the application to a grinding halt in the worst case.

    Even worse, if the original GetRols function doesn't guarantee the order of the rows returned (as the SQL standard doesnt impose) it is possible that certain entries are duplicated while others are removed.

  • someone (unregistered) in reply to US Navy Commander
    Anonymous:
    Anonymous:
    [...]please if you are going to rethrow an exception, just call throw, not throw e. This will lose the stack trace and you will never see the real eror.


    Now THERE's the REAL WTF.


    true.  but I think the guy said something to that affect later on.  he was just replying to the dodgy code sample at the top of page 2.

    I see this pointless catchcng and throwing all the time and it drives me mad.  it makes people think they are writing error handling code, but all they are doing is losing the cause of the real error.

    CAPTCH: WTF
  • Shizzle (unregistered) in reply to Anonymous WTFer
    Anonymous:
    Anonymous:
    Well, at least it works.  I guess that is what makes it a WTF.  In Java, (I'm sure C#, a blatant copy of Java, has similiar) you could reduce it to...

    public ArrayList getRoles() {
        return getRols() == null ? null : new ArrayList(getRols());
    }

    This is assuming, of course, that for some reason you need a copy of the ArrayList instead of the actual instance member of it.  Also, What The F is a "Rol"?

    On the other hand, the coder was rather clever in not having to use a pesky variable to count over the ArrayList, just use the count of the one you are building instead!  (WTF is an iterator, anyway! or even the addAll method!)

    Not really a horrible WTF, but I am glad to see more code here again.



    I call WTF.

    Dude, you're still calling getRols() twice... unless it returns null the first time. No soup for you!



    You should have read the very next message before you take my soup away.  But I hope you feel better about yourself now.
  • eddiedatabaseboston (unregistered) in reply to Someone, Somewhere, outwhere
    Anonymous:

    translated into php for clarity


    Most WTFy comment ever.

  • Yaytay (unregistered) in reply to KattMan
    Anonymous:

    The extended version went one more step.  The entire issue is about Return On Investment (ROI).  One programmer will take 100% of the time to complete a project, a 3 week project takes 3 weeks. Two programmers does not cut the time in half to 1.5 weeks but rather reduces it to maybe 2 weeks.  In man-hours we increased the time (making him correct in theory) but in reality we reduced the time to market (making me correct in practice).  I stated that there will come a time where you start adding programmers and get a negative ROI but until such time you are shortening your time to market albiet with increased cost.

    Even with the addition of a second body I would expect the project to take longer to complete if it's a three week project - simply because it takes too long for bod number 2 to learn what bod number 1 is thinking.
    You will also end up with a less cohesive whole.

    Not that I'm agreeing with what you say Brooks said, you can reduce time to market by adding bods, but you have to bloody careful about how you do it - and I would argue that very few shops are.

    I'd also claim (with nothing but my own experience to back this up) that adding bods is considerably worse than starting off with more bods - and I mean right back at the planning stage.

  • anonymous (unregistered) in reply to eddiedatabaseboston
    Anonymous:
    Anonymous:

    translated into php for clarity


    Most WTFy comment ever.




    function getRols()
    {
           $sql = "SELECT * FROM `roles`";
           $res = mysql_query($sql);
           $retval = array();
           while ($row = mysql_fetch_object($res))
              $retval[] = $row;
           return $retval;
    }


    PHP converted to XML:


    <getRols>
     <DeclarationBlock>
     <declarevar name="sql"><[CDDATA[
                     SELECT * FROM `roles`
     ]]></declarevar>
     <declarevar name="res">
      <functioncall name="mysql_query">sql</functioncal>
     </declarevar>
     </DeclarationBlock>
     <ImplementationBlock>
     <while>
       <iteratorrule>
            <let var="row">
                 <mysql_fech>res</mysql_fech>
             </let>
       </iteratorrule>
      <executerule>
            <le var="retval.current">row</let>
      </executerule>
     </while>
     <return>retval</return>
     </ImplementationBlock>
    </getRols>

    Anyway is better to move SELECT * FROM `roles` to a DTD.

Leave a comment on “The Juniors' Whopper”

Log In or post as a guest

Replying to comment #:

« Return to Article