• (cs) in reply to SenTree
    SenTree:
    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...).
    I guess that would probably count as The Papadimoulis Corollary to Muphry's Law, wouldn't it?
  • (cs) in reply to DaveK
    DaveK:
    P.s. We have your for loops. Send ten thousand quatloos or you'll never see them again!

    I'm all out of quatloos, do you accept internets?

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

    So, for future reference, that's:
    Comedy: Not funny.
    Wow, what else sucks in your universe, Captain Miserable?

    [inb4 "no u"]

  • (cs) in reply to dtech
    dtech:
    P.s. We have your for loops. Send ten thousand quatloos or you'll never see them again!

    I'm all out of quatloos, do you accept internets?

    Only the giant pink rubber kind that are 6800 miles on each side.
  • (cs) in reply to Not THAT Alex
    Not THAT Alex:
    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.

    Back in college, we implemented a pseudocode example for an AVL tree we found in our Data Structures textbook, only to find that said code would never work. The "rebalance tree" condition would never be reached, so the code was worthless.

    We threw away the "implementation" and cooked up one ourselves; it later served as the "example code" for the next generations, who we warned not to waste their time with the textbook "example".

  • (cs) in reply to DaveK
    DaveK:
    SenTree:
    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...).
    I guess that would probably count as The Papadimoulis Corollary to Muphry's Law, wouldn't it?
    Good thought.
  • Jay (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?

    So what's the problem? I'm sure that in the code that processes this input, he simply writes:

    if (value==4)
      year=2007;
    else if (value>=8 && value<=10)
      year=value+2000;
    else if (value>=11 && value<=14)
      year=value+2001;
    else
      year=FALSE;
    

    It makes perfect sense when you envision the application as a whole.

  • Darkstar (unregistered)

    I don't get it. What was the problem again?

  • Darkstar (unregistered)

    I don't get it. What was the problem again?

  • Darkstar (unregistered)

    I don't get it. What was the problem again?

  • Darkstar (unregistered)

    I don't get it. What was the problem again?

  • (cs) in reply to Darkstar

    break; // combo breaker!

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

    Wow, you actually did the math or something there?

    You spend way too much time thinking about my arse. I guess it's my own fault for raising it.

    rimsho--errr, I mean "ba-da-dum-tissh"

  • Piercy (unregistered)

    i rarely post saying this shouldnt be on here... he is a novice, and obviously didnt understand not really a WTF? the fact that it reached here is more likely to be the WTF!

  • diaphanein (unregistered) in reply to Jay
    Jay:
    if (value==4)
      year=2007;
    else if (value>=8 && value<=10)
      year=value+2000;
    else if (value>=11 && value<=14)
      year=value+2001;
    else
      year=FILENOTFOUND;
    

    It makes perfect sense when you envision the application as a whole.

    Corrected that for you.

  • (cs)

    I think that's the "Replace Conditional with Polymorphism and Conditional" refactoring.

  • zob (unregistered)

    Could be that he intented to make each case different later then forgot or changed his mind but didn't rewrite the code

  • gorobei (unregistered) in reply to Dr. F

    Technically, it isn't cargo cult, it's just stupid code.

    CCP requires the use of an idiom that doesn't do anything, the author doesn't understand, but is there because it was thought to fix something in the past, and so is always used.

  • (cs) in reply to diaphanein
    diaphanein:
    Jay:
    if (value==4)
      year=2007;
    else if (value>=8 && value<=10)
      year=value+2000;
    else if (value>=11 && value<=14)
      year=value+2001;
    else
      year=FILENOTFOUND;
    It makes perfect sense when you envision the application as a whole.
    Corrected that for you.
    Thank you. I'm glad I read ahead before fixing it myself.
  • Rich (unregistered) in reply to Code Dependent
    Code Dependent:
    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
    You just picked a bunch of random words.

    Here's a hint kid. When you're making a witty retort, try to make it witty.

  • Todd (unregistered) in reply to Code Dependent
    Code Dependent:
    seconddevil:
    There is a name for that pattern, The Copy and Paste Pattern

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

    Sigh, glad I am not the only one to deal with hard coded year drop downs. Towards the end of my first year at my first job, a user of the application I recently was assigned to maintain came over and she asked me, "Could you add a new year to the call center? Lula, used to do it for us every year, but I don't know who could do it now?"

    My boss fired the only female programmer and I took over all her crap. The users hated that she was fired and I took over but after a while of them working with someone that could speak english and could write code that didn't need updated every year they started to warm up to me.

  • (cs) in reply to Rich
    Rich:
    Code Dependent:
    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
    You just picked a bunch of random words.

    Here's a hint kid. When you're making a witty retort, try to make it witty.

    Keep studying on it. Maybe it'll come to you eventually. If not, show your lack of comprehension again tomorrow, and I'll explain it to you.

  • (cs) in reply to Todd
    Todd:
    Sigh, glad I am not the only one to deal with hard coded year drop downs. ...she asked me, "Could you add a new year to the call center?"
    That's funny, because what the user asked for regarding this application is that the default year (the selected listitem) be moved up to 2008.

    I've requested to have a project manager meet with the customer to find out what the date range represents and what its bounds should be, so that I can generate the listitems dynamically. Whether that gets approval or not remains to be seen.

  • Asdf (unregistered) in reply to danixdefcon5
    danixdefcon5:
    Not THAT Alex:
    In a textbook?! OK, now that explains a lot.
    Back in college, we implemented a pseudocode example for an AVL tree we found in our Data Structures textbook, only to find that said code would never work. The "rebalance tree" condition would never be reached, so the code was worthless.

    We threw away the "implementation" and cooked up one ourselves; it later served as the "example code" for the next generations, who we warned not to waste their time with the textbook "example".

    Then there are the textbooks that are obsessed with linked lists and recursion. I've even seen one that recommended using recursion to get from one end of a linked list to the other.

    TRWTF: the original code didn't use recursion to "reuse the code".

  • Anonymous (unregistered) in reply to Code Dependent
    Code Dependent:
    Rich:
    Code Dependent:
    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
    You just picked a bunch of random words.

    Here's a hint kid. When you're making a witty retort, try to make it witty.

    Keep studying on it. Maybe it'll come to you eventually. If not, show your lack of comprehension again tomorrow, and I'll explain it to you.

    I think everyone got your obvious (attempt at a) joke. The point was that you just picked a bunch of random words to make up the acronym. You might as well have called it "Phone Elaine Now Igor Samsonov".

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

    Wow, you actually did the math or something there?

    You spend way too much time thinking about my arse. I guess it's my own fault for raising it.

    rimsho--errr, I mean "ba-da-dum-tissh"

    Unfortunately I did, yes! I even divided by 365.25 to take account for leap years AND rounded up to cut you some slack (note to self - leave the house more often).

    Wait a second... you said 'arse' then 'math'. Shouldn't that be 'ass' then 'math' or 'arse' then 'maths'?

  • (cs) in reply to Anonymous
    Anonymous:
    Code Dependent:
    Rich:
    Code Dependent:
    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
    You just picked a bunch of random words.

    Here's a hint kid. When you're making a witty retort, try to make it witty.

    Keep studying on it. Maybe it'll come to you eventually. If not, show your lack of comprehension again tomorrow, and I'll explain it to you.

    I think everyone got your obvious (attempt at a) joke. The point was that you just picked a bunch of random words to make up the acronym. You might as well have called it "Phone Elaine Now Igor Samsonov".

    Personal Emulation of Nubile Isis Society

    Isis is the earth-mother, the goddess of fertility.

    Nubile means a female of consenting age, sexually active.

    Emulation means aspiring to be like someone, as good as or better than them, imitating their activity.

    So what we have here is someone doing her personal best to become a young sexually active goddess of fertility.

    Oh, wait... we forgot "Society". It isn't one... it's a whole fellowship of them! A society of young sexually active fertility goddesses: a brothel. Or maybe it's a temple full of priestesses of Isis.

    But don't feel bad because you didn't get that. "Liberate Apes Before Imprisoning Apes" really is more your speed. So go on back and play with the other kiddies now, and let the adults tend to the grownup stuff.

    Addendum (2009-03-11 22:08): By the way... good move, going anonymous for your post. Really good move.

  • Anon (unregistered)

    People who use underscores as the first character of variables need to be punched.

    Seriously.

    if (_somevar != _start_date) { _blow_chunks.add (_chunk); _chunk.isChunky = true; }

    --_doSomeMoreShit;

    if (_chunk.isChunky && 0 >= _blow_chunks.Length && _doSomeMoreShit++ > 1) { for (int _x = 0; _x < _theNumberOfHairsOnMyHead; _x++) _hairs_left -= _x; }

    Try debugging that shit at midnight.

  • Dave (unregistered)

    That only looks like each case does the same thing. I've "worked" on enough enterprise software to know the real design pattern here. DetailPanelFactory.getInstance uses reflection on it's return address to determine which case branch it was called from.

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

    Wow, you actually did the math or something there?

    You spend way too much time thinking about my arse. I guess it's my own fault for raising it.

    rimsho--errr, I mean "ba-da-dum-tissh"

    Unfortunately I did, yes! I even divided by 365.25 to take account for leap years AND rounded up to cut you some slack (note to self - leave the house more often).

    Ah, there's your bug. You should have used 365.2425, to allow for the one extra leap day every four centuries.
    Bobbo:
    Wait a second... you said 'arse' then 'math'. Shouldn't that be 'ass' then 'math' or 'arse' then 'maths'?
    It should be 'arse' and then 'meths', assuming your arse is as dirty as your mind!
  • (cs) in reply to Anon
    Anon:
    People who use underscores as the first character of variables need to be punched.

    Seriously.

    No, absolutely they should be punched, no disagreement from me. And here's what you should punch them with:
    n1256 ISO C language standard ISO/IEC 9899 (aka 'C99'):
    7.1.3 Reserved identifiers
    [ . . . ]
    —All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. —All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
    Anon:
    Try debugging that shit at midnight.
    It's not just that it's ugly to read. It can also have bizarre random unexpected side-effects on either compiler or run-time library. You do *not* want to play that game if you don't specially enjoy wasting days fixing utterly pointless heisenbugs.
  • Adrian Pavone (unregistered) in reply to DaveK
    DaveK:
    Anon:
    People who use underscores as the first character of variables need to be punched.

    Seriously.

    No, absolutely they should be punched, no disagreement from me. And here's what you should punch them with:
    n1256 ISO C language standard ISO/IEC 9899 (aka 'C99'):
    7.1.3 Reserved identifiers
    [ . . . ]
    —All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. —All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
    Anon:
    Try debugging that shit at midnight.
    It's not just that it's ugly to read. It can also have bizarre random unexpected side-effects on either compiler or run-time library. You do *not* want to play that game if you don't specially enjoy wasting days fixing utterly pointless heisenbugs.

    While all the above is true, a quick perusal of the MSDN documentation shows that M$ appears to be using the underscore for all privately scoped variables. input variables for methods use no underscore, and public variables (invariable a property) uses a capital.

    As such, I don't find it at all surprising that this programming style has been picked up by the masses. However, when every single variable in every single form uses underscores, which happens when the idea is misunderstood, it becomes amazingly complex very fast.

    In response to the earlier persons "code snippet" that they said to debug late at night, for one, camel case should be being used if using the underscore for privately scoped variables mentality, and for two (and much more importantly) your design style changed for a number of variables, with some having camelCase and some having under_scores. Pick one and stick to it, will make your code much more maintainable at midnight.

  • _TrXtR_ (unregistered)

    I'm leaving on friday. I'm glad I dont have to keep exposing myself to this.

      public String doClientSearchResultSelectAction() {
    
        String page = PAGE_LOCAL;
    
        if (getQuoteSession().getSearchClientSession().getFromPage().equals(ADD_BENEFICIARY)) {
          getQuoteSession().getBeneficiaryClientSession().setSelectedObject(setSelectedClient());
          page = INVESTMENT_DETAILS;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(ADD_CESSION)) {
          getQuoteSession().getCessionPageSession().setSelectedObject(setSelectedClient());
          page = ADD_CESSION;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(ADD_LIFE_ASSURED)) {
          getQuoteSession().getInsuredLifeClientSession().setSelectedObject(setSelectedClient());
          page = INVESTMENT_DETAILS;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(EDIT_LIFE_ASSURED)) {
          getQuoteSession().getInsuredLifeMaintenancePage().setSelectedObject(setSelectedClient());
          page = EDIT_LIFE_ASSURED;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(RIDER_BENEFITS)) {
          getQuoteSession().getRiderBenefitPageSession().setSelectedObject(setSelectedClient());
          page = RIDER_BENEFITS;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(EDIT_CONTRIBUTION_PAYER)) {
          getQuoteSession().getContributionPayerPageSession().setSelectedObject(setSelectedClient());
          page = EDIT_CONTRIBUTION_PAYER;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(EDIT_CONTRIBUTION_PAYER)) {
          getQuoteSession().getContributionPayerPageSession().setSelectedObject(setSelectedClient());
          page = EDIT_CONTRIBUTION_PAYER;
        } else if (getQuoteSession().getSearchClientSession().getFromPage().equals(INTRODUCTION)) {
          getQuoteSession().getIntroductionPageSession().setSelectedObject(setSelectedClient());
          page = INTRODUCTION;
        }
    
        getQuoteSession().getSearchClientSession().setFromPage(null);
        return page;
      }
    
  • _____ (unregistered)

    would this be appropriate?

    case CONST1: case CONST2: case CONST3: HideousEnterpriseyClassFactoryFactory.CreateHideousEnterpriseyClassFactory() break;

  • Pieter (unregistered)

    What about:

    There should only be ONECONST, seeing as it seems to be same type of object, then you just

    def Panel_Instance(VARIABLE) _panelInstance = DetailPanelFactory.getInstance(VARIABLE); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); end

    Panel_instance(ONECONST)

    DONE!

  • Pieter (unregistered) in reply to Pieter

    EEK, s/ONECONST/VARIABLE/g

  • Bob (unregistered)

    Utterly redundant code comments are annoying:

    "// add the new panelItem to the panelCollection"

  • Todd (unregistered) in reply to Code Dependent
    Code Dependent:
    Todd:
    Sigh, glad I am not the only one to deal with hard coded year drop downs. ...she asked me, "Could you add a new year to the call center?"
    That's funny, because what the user asked for regarding this application is that the default year (the selected listitem) be moved up to 2008.

    I've requested to have a project manager meet with the customer to find out what the date range represents and what its bounds should be, so that I can generate the listitems dynamically. Whether that gets approval or not remains to be seen.

    No, they literally couldn't log calls for the next year's events because they couldn't pick the next year and the user was the project manager. The company was pretty well run from the business side, virtually no red tape, just I replaced a shitty programmer that just hard coded "2004", "2005", "2006" into a drop down.

  • m@tt (unregistered)
    case SOME_CONST1:
    case SOME_CONST2:
    case SOME_CONST3:
    case SOME_CONST4:
            _panelInstance  = DetailPanelFactory.getInstance(type);
            _panelInstance.parseXML(panelList);
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance);
    break;
    

    ding! fries are done!

  • (cs) in reply to Piercy
    Piercy:
    i rarely post saying this shouldnt be on here... he is a novice, and obviously didnt understand not really a WTF? the fact that it reached here is more likely to be the WTF!

    How is this not a WTF? Some Paula was hired to write code. Sure they are new, but they were HIRED to write code, and this is what they produced. Sure maybe Paula was hired to be trained on the job, but I seriously doubt that.

  • Winkel (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?

    That's called the "Mirror with Distortion" or "Carnival Mirror" Design Pattern. We see it a lot around these parts.

  • titrat (unregistered)

    The real WTF are the comments in code.

    a much more stringent version:

    case SOME_CONST1: // if SOME_CONST came true ...
    
           // get panel factory from DetailPanelFactory
            _panelInstance  = DetailPanelFactory.getInstance(CONST1);
    
           // parse xml of panelList to panelInstance
            _panelInstance.parseXML(panelList);
           
            // add the new panelItem to the panelCollection
            _panelCollection.addItem(_panelInstance);
            
            // increment i by one
            i = i + 1;
    break; // break
    

    Only code which is explained twice will be understood from the compiler :_)

  • _dew_ (unregistered) in reply to Teh

    omg

  • anon (unregistered)

    no, the real wtf is copy-pasta they should have written it as case SOME_CONST1: case SOME_CONST2: case SOME_CONST3: case SOME_CONST4: _panelInstance = DetailPanelFactory.getInstance(type); _panelInstance.parseXML(panelList); // add the new panelItem to the panelCollection _panelCollection.addItem(_panelInstance); break;

    or use an if statement in a similar fashion

  • Cbuttius (unregistered) in reply to Teh
    Teh:
    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; }

    You bitwise-or together your constants?

  • (cs)

    I suppose the option to fire the developer was not considered?

  • nobodyfamous (unregistered)

    This is what the book "Code Complete" recommends, FWIW. Explicit case statements for each condition, rather than relying on fall-through. 'course, the design could probably be reworked, but this one snippet looks "OK" according to CC's rules.

  • anonymous (unregistered)

    I can actually top this. Some code that I found in one of our many Access/VBA monstrosities...

    Function OpenForms(strFormName As String) As Integer
    ' This function is used in the Click event of command buttons that
    ' open forms on the Main Switchboard. Using a function is more efficient
    ' than repeating the same code in multiple event procedures.
    On Error GoTo Err_OpenForms

    <span style="color:#008000;">' Open specified form.</span>
    DoCmd.OpenForm strFormName
    

    Exit_OpenForms: Exit Function

    Err_OpenForms: MsgBox Err.Description Resume Exit_OpenForms End Function

    "Not that bad," you might say, "aside from the hideous code and ridiculous comments, that sounds like a halfway decent idea". But wait. Scroll down, and you find that the other 20 buttons on the form have On Click events that look strangely familiar:
    Private Sub Command38_Click()
    On Error GoTo Err_Command38_Click

    <span style="color:blue;">Dim </span>stDocName <span style="color:blue;">As String
    Dim </span>stLinkCriteria <span style="color:blue;">As String</span>
    
    stDocName = <span style="color:#808080;">"frmTemp"</span>
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    

    Exit_Command38_Click: Exit Sub

    Err_Command38_Click: MsgBox Err.Description Resume Exit_Command38_Click

    End Sub

    After looking at the On Click events for all 21 buttons on the form, I found that this clever programmer's function to avoid "repeating the same code in multiple event procedures" gets used a grand total of exactly once.

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

Log In or post as a guest

Replying to comment #:

« Return to Article