• Sandor (unregistered)

    case 1 first; case 2 first; case 3 first; case else WTF; //This should never occur

  • mitschke (unregistered)

    Who stole my code?

  • (cs)

    I see a pattern here.

  • (cs) in reply to Code Dependent
    Code Dependent:
    I see a pattern here.
    Obviously, the switch needs to be wrapped up in a for loop!

    signed, The For Loop Re-Imprisonment Front.

    P.s. We have your for loops. Send ten thousand quatloos or you'll never see them again!

  • Anon (unregistered)

    Well, the code's being reused. What more do you want?

  • Litote. (unregistered)

    What's this got to do with design patterns? This is just tat code.

  • Teh (unregistered)

    I think I have to change my glasses, I'm now seeing like quadruple

    I found the pattern... right-click and click "View source"

  • (cs)

    There is a name for that pattern, The Copy and Paste Pattern

  • Osno (unregistered)

    This should have been solved with an if, like this:

    if (v == SOME_CONST1) { _panelInstance = DetailPanelFactory.getInstance(type); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); } if (v == SOME_CONST2) { _panelInstance = DetailPanelFactory.getInstance(type); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); } if (v == SOME_CONST3) { _panelInstance = DetailPanelFactory.getInstance(type); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); } if (v == SOME_CONST4) { _panelInstance = DetailPanelFactory.getInstance(type); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); }

  • (cs)

    Yeah, nothing wrong with copy and paste. If you've written something and it works, there's no need to keep writing it again and again.

    No, the real WTF is the use of non-descriptive names like SOME_CONST1. That should never happen!

  • Mr^B (unregistered) in reply to Litote.
    Litote.:
    What's this got to do with design patterns? This is just tat code.

    _panelInstance = DetailPanelFactory.getInstance(type);

    It's clearly using design patterns!

  • Tom (unregistered)

    This allows you to have at least 4 unit tests instead of just 1.

  • whoever (unregistered)

    It's really a WTF, it should use a reusable class to do this, like this:

    PanelInstanceManager _panelInstance  = new PanelInstanceManager();
    case SOME_CONST1:
            _panelInstance.setInstanceItem(DetailPanelFactory.getInstance(type));
            _panelInstance.getInstanceItem().parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance.getInstanceItem());
    break;
    
    case SOME_CONST2:
            _panelInstance.setInstanceItem(DetailPanelFactory.getInstance(type));
            _panelInstance.getInstanceItem().parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance.getInstanceItem());
    break;
    
    case SOME_CONST3:
            _panelInstance.setInstanceItem(DetailPanelFactory.getInstance(type));
            _panelInstance.getInstanceItem().parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance.getInstanceItem());
    break;
    
    case SOME_CONST4:
            _panelInstance.setInstanceItem(DetailPanelFactory.getInstance(type));
            _panelInstance.getInstanceItem().parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance.getInstanceItem());
    break;
    
  • (cs) in reply to seconddevil
    seconddevil:
    There is a name for that pattern, The Copy and Paste Pattern
    A common derivative of copy-and-paste programming is the "Copy, Paste and Mis-edit" style. I ran across this textbook example when I was tasked with implementing a customer-requested embellishment to an application.

    <asp:DropDownList ID="DdlMonth" runat="server"> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> <asp:ListItem Value="5">5</asp:ListItem> <asp:ListItem Value="6">6</asp:ListItem> <asp:ListItem Value="7">7</asp:ListItem> <asp:ListItem Value="8">8</asp:ListItem> <asp:ListItem Value="9">9</asp:ListItem> <asp:ListItem Value="10">10</asp:ListItem> <asp:ListItem Value="11">11</asp:ListItem> <asp:ListItem Value="12">12</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DdlYear" runat="server"> <asp:ListItem Value="4">2007</asp:ListItem> <asp:ListItem Value="8">2008</asp:ListItem> <asp:ListItem Value="9">2009</asp:ListItem> <asp:ListItem Value="10">2010</asp:ListItem> <asp:ListItem Value="11">2012</asp:ListItem> <asp:ListItem Value="12">2013</asp:ListItem> <asp:ListItem Value="13">2014</asp:ListItem> <asp:ListItem Value="14">2015</asp:ListItem> </asp:DropDownList>

    Note: in DdlYear, the value of 2007 is 4. 2008 through 2010 values are their respective last one or two digits. 2011 is missing, and 2012 through 2015 are off by one in their values. Obviously what happened is the (pseudo-)developer entered the code for DdlMonth, then copy-and-pasted from it to get DdlYear. And then, true to the programming style, mis-edited it.

    This application is over three years old, and this has never been caught until now.

    Side note: why in hell would anybody hard-code Year values into a DDL?

  • (cs)

    since when do we poke fun at novices? :( i remember writing garbage like this when i first started out too

  • Teh (unregistered)

    Reuse! with a while

    while (v == SOME_CONST1 | SOME_CONST2 | SOME_CONST3 | SOME_CONST4 ) { _panelInstance = DetailPanelFactory.getInstance(type); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); break; }

  • Not THAT Alex (unregistered) in reply to Pim
    Pim:
    Yeah, nothing wrong with copy and paste. If you've written something and it works, there's no need to keep writing it again and again.

    No, the real WTF is the use of non-descriptive names like SOME_CONST1. That should never happen!

    I might be wrong, but I suppose that's because they intend to use this same piece of code again...

    I don't know about Design, but I can certainly see a pattern here.

  • Skip (unregistered)

    I'm pretty sure I worked with this guy...we had an intern who would dutifully churn out 200 lines of code like this a day.

  • Not THAT Alex (unregistered) in reply to Code Dependent
    Code Dependent:
    seconddevil:
    There is a name for that pattern, The Copy and Paste Pattern
    A common derivative of copy-and-paste programming is the "Copy, Paste and Mis-edit" style. I ran across this textbook example when I was tasked with implementing a customer-requested embellishment to an application.

    <asp:DropDownList ID="DdlMonth" runat="server"> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> <asp:ListItem Value="5">5</asp:ListItem> <asp:ListItem Value="6">6</asp:ListItem> <asp:ListItem Value="7">7</asp:ListItem> <asp:ListItem Value="8">8</asp:ListItem> <asp:ListItem Value="9">9</asp:ListItem> <asp:ListItem Value="10">10</asp:ListItem> <asp:ListItem Value="11">11</asp:ListItem> <asp:ListItem Value="12">12</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DdlYear" runat="server"> <asp:ListItem Value="4">2007</asp:ListItem> <asp:ListItem Value="8">2008</asp:ListItem> <asp:ListItem Value="9">2009</asp:ListItem> <asp:ListItem Value="10">2010</asp:ListItem> <asp:ListItem Value="11">2012</asp:ListItem> <asp:ListItem Value="12">2013</asp:ListItem> <asp:ListItem Value="13">2014</asp:ListItem> <asp:ListItem Value="14">2015</asp:ListItem> </asp:DropDownList>

    Note: in DdlYear, the value of 2007 is 4. 2008 through 2010 values are their respective last one or two digits. 2011 is missing, and 2012 through 2015 are off by one in their values. Obviously what happened is the (pseudo-)developer entered the code for DdlMonth, then copy-and-pasted from it to get DdlYear. And then, true to the programming style, mis-edited it.

    This application is over three years old, and this has never been caught until now.

    Side note: why in hell would anybody hard-code Year values into a DDL?

    In a textbook?! OK, now that explains a lot.

  • Tuxie (unregistered)

    Clearly the developer should had used a DetailPanelCollectionFactoryObserverManagerFactoryInterface instead.

  • Don't get it (unregistered)

    It reminds me of a simple web page a consultant implemented. About 15 check boxes on it. About 38,000 lines of code to handle it. Turned out to be a lot of gloppy code, cut and pasted 15 times.

  • m0ffx (unregistered) in reply to DaveK
    DaveK:
    Code Dependent:
    I see a pattern here.
    Obviously, the switch needs to be wrapped up in a for loop!

    signed, The For Loop Re-Imprisonment Front.

    P.s. We have your for loops. Send ten thousand quatloos or you'll never see them again!

    'Quatloo'? Is that a squat toilet?

  • Anonymous (unregistered) in reply to Don't get it
    Don't get it:
    It reminds me of a simple web page a consultant implemented. About 15 check boxes on it. About 38,000 lines of code to handle it. Turned out to be a lot of gloppy code, cut and pasted 15 times.
    And now it's on his resume as "- Designed and coded a complex web survey application".
  • Your Name (unregistered) in reply to Don't get it
    Don't get it:
    It reminds me of a simple web page a consultant implemented. About 15 check boxes on it. About 38,000 lines of code to handle it. Turned out to be a lot of gloppy code, cut and pasted 15 times.

    The Real WTF is it took 2533 and a third lines to handle 15 check boxes.

  • (cs) in reply to Anonymous
    Anonymous:
    And now it's on his resume as "- Designed and coded a complex web survey application".
    We had a craptastic "programmer" working here several years ago, who was only kept on so the boss wouldn't look like he'd made the same mistake twice (his predecessor had lasted two weeks). In the year that he was here he only produced one application -- a single web page which accepted user input and sent an email. He used to come around to various ones of us asking elementary questions. One conversation I remember:

    "Hey, Code, do you know how to call a routine after a user makes a selection in a listbox?"

    "Use the onchanged event."

    "Onchanged event?"

    "Here, I'll show you." (show him)

    "Cool. Yeah, that's how I was going to do it, but I was wondering if there might be a better way."

    Out of curiosity, I looked this guy up on LinkedIn recently. He has his position with us listed as "Senior Software Developer".

  • Les (unregistered)

    S/he got paid $ per line of code.

  • St Mary's Hospital for the Tedious Tedium (unregistered)

    Well, this code was optimized to make small ZIP files out of the source code.

    He got one thing right, at least.

  • (cs) in reply to m0ffx
    m0ffx:
    DaveK:
    Code Dependent:
    I see a pattern here.
    Obviously, the switch needs to be wrapped up in a for loop!

    signed, The For Loop Re-Imprisonment Front.

    P.s. We have your for loops. Send ten thousand quatloos or you'll never see them again!

    'Quatloo'? Is that a squat toilet?

    What on earth would I want ten thousand toilets for when I've only got one arse to sit on them with? I'd wear it through to the bone before I got half-way through done with them!
  • T-Biscuit (unregistered) in reply to A Nonny Mouse
    A Nonny Mouse:
    since when do we poke fun at novices? :( i remember writing garbage like this when i first started out too

    Yeah, leave the n00b alone, fellas.

  • Dr. F (unregistered)

    Ah, I love the smell of Cargo Cult Programming in the morning!

  • Dr. F (unregistered) in reply to Dr. F

    D'oh!

  • diaphanein (unregistered)

    If at first you don't succeed, copy, paste and fail again.

  • (cs) in reply to Dr. F
    Dr. F:
    D'oh!
    When you are in edit mode, you'll see a link above the text input box that says BBCode Okay. Click on it.
  • Bobbo (unregistered) in reply to DaveK
    DaveK:
    What on earth would I want ten thousand toilets for when I've only got one arse to sit on them with? I'd wear it through to the bone before I got half-way through done with them!

    What, your arse has a 14 year life-span?

    And shouldn't you be in school?? Thinking about it, I shouldn't really be talking to you about your arse should I...

  • Anonymous (unregistered)

    Yeh, you may laugh... but thats how Command and Singleton patterns were born.... just give him a couple of weeks...

  • (cs)

    Maybe in some bizzaro world programmers aren't allowed to create their own methods.

  • C.L.I.T. Commander (unregistered) in reply to DaveK
    DaveK:
    The For Loop Re-Imprisonment Front.

    Is this related at all to the Coalition for the Liberation of Itinerate Tree-dwellers?

    Or the Liberate Apes Before Imprisoning Apes movement?

  • fistposter (unregistered)

    If it switches on type, it would be straight-forward to avoid copy and paste programming.

    case SOME_CONST1:
            _panelInstance  = DetailPanelFactory.getInstance(CONST1);
            _panelInstance.parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance);
    break;
    
    case SOME_CONST2:
            _panelInstance  = DetailPanelFactory.getInstance(CONST2);
            _panelInstance.parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance);
    break;
    
    case SOME_CONST3:
            _panelInstance  = DetailPanelFactory.getInstance(CONST3);
            _panelInstance.parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance);
    break;
    
    case SOME_CONST4:
            _panelInstance  = DetailPanelFactory.getInstance(CONST4);
            _panelInstance.parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance);
    break;
    

    Copy and paste this!

  • (cs) in reply to C.L.I.T. Commander
    C.L.I.T. Commander:
    Is this related at all to the Coalition for the Liberation of Itinerate Tree-dwellers?

    Or the Liberate Apes Before Imprisoning Apes movement?

    Personal Emulation of Nubile Isis Society

  • baldywilson (unregistered)

    The real WTF is the fact that the anonymous submitter decided to send this code to the Daily WTF when the subby was supposed to be mentoring this guy. It's not the novice programmer that's the problem here, its his mentor who clearly can't do his job.

  • Anonymous (unregistered)

    Novice or not, some coder looked at this and thought to himself "this is an appropriate way to implement this logic". This, to me, highlights a fundamental flaw in the entire mindset of the coder. Find a different career.

  • Cro (unregistered) in reply to Code Dependent

    Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.

    CAPTCHA: vulputate

  • Bobbo (unregistered) in reply to Cro
    Cro:
    Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.

    Genius.

    Cro:
    CAPTCHA: vulputate

    QED.

  • Cro (unregistered)

    Or, if I could actually spell (and capitalise correctly);

    the Committee for the Liberation and Integration of Terrifying life fOrms and their Rehabilitation Into Society.

  • (cs) in reply to Bobbo
    Bobbo:
    Cro:
    Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.

    Genius.

    Well yes, but Grant Naylor's genius, not Cro's.
  • Anonymous (unregistered) in reply to Cro
    Cro:
    Or, if I could actually spell (and capitalise correctly);

    the Committee for the Liberation and Integration of Terrifying life fOrms and their Rehabilitation Into Society.

    It's organisms, not lifeforms. It's supposed to be making a humourous acronym, remember? But, FYI, even if correct it wouldn't have been funny. Just so you know for future reference.

  • Cro (unregistered) in reply to DaveK
    DaveK:
    Bobbo:
    Cro:
    Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.

    Genius.

    Well yes, but Grant Naylor's genius, not Cro's.

    Never claimed originality, mate...! :)

  • (cs) in reply to C.L.I.T. Commander
    C.L.I.T. Commander:
    DaveK:
    The For Loop Re-Imprisonment Front.

    Is this related at all to the Coalition for the Liberation of Itinerate Tree-dwellers?

    Or the Liberate Apes Before Imprisoning Apes movement?

    Well, let's see:
    me:
    How would you like a kick in the flrif, then?
    Nahh, it's just not the same.
  • (cs) in reply to Cro
    Cro:
    DaveK:
    Bobbo:
    Cro:
    Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.

    Genius.

    Well yes, but Grant Naylor's genius, not Cro's.

    Never claimed originality, mate...! :)

    Sorry, wasn't meant to sound accusatory, just giving the original source. Boys from the Dwarf! *wrist-snap*
  • (cs)

    Just curious - is there an equivalent to Muphry's law for humourous corrections to novices' code ? (Some of the offerings don't exhibit the same behaviour as the original...).

Leave a comment on “Using Design Patterns...or not...”

Log In or post as a guest

Replying to comment #248612:

« Return to Article