- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
case 1 first; case 2 first; case 3 first; case else WTF; //This should never occur
Admin
Who stole my code?
Admin
I see a pattern here.
Admin
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!
Admin
Well, the code's being reused. What more do you want?
Admin
What's this got to do with design patterns? This is just tat code.
Admin
I think I have to change my glasses, I'm now seeing like quadruple
I found the pattern... right-click and click "View source"
Admin
There is a name for that pattern, The Copy and Paste Pattern
Admin
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); }
Admin
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!
Admin
_panelInstance = DetailPanelFactory.getInstance(type);
It's clearly using design patterns!
Admin
This allows you to have at least 4 unit tests instead of just 1.
Admin
It's really a WTF, it should use a reusable class to do this, like this:
Admin
<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?
Admin
since when do we poke fun at novices? :( i remember writing garbage like this when i first started out too
Admin
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; }
Admin
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.
Admin
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.
Admin
In a textbook?! OK, now that explains a lot.
Admin
Clearly the developer should had used a DetailPanelCollectionFactoryObserverManagerFactoryInterface instead.
Admin
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.
Admin
'Quatloo'? Is that a squat toilet?
Admin
Admin
The Real WTF is it took 2533 and a third lines to handle 15 check boxes.
Admin
"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".
Admin
S/he got paid $ per line of code.
Admin
Well, this code was optimized to make small ZIP files out of the source code.
He got one thing right, at least.
Admin
Admin
Yeah, leave the n00b alone, fellas.
Admin
Ah, I love the smell of Cargo Cult Programming in the morning!
Admin
D'oh!
Admin
If at first you don't succeed, copy, paste and fail again.
Admin
Admin
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...
Admin
Yeh, you may laugh... but thats how Command and Singleton patterns were born.... just give him a couple of weeks...
Admin
Maybe in some bizzaro world programmers aren't allowed to create their own methods.
Admin
Is this related at all to the Coalition for the Liberation of Itinerate Tree-dwellers?
Or the Liberate Apes Before Imprisoning Apes movement?
Admin
If it switches on type, it would be straight-forward to avoid copy and paste programming.
Copy and paste this!
Admin
Admin
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.
Admin
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.
Admin
Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.
CAPTCHA: vulputate
Admin
Genius.
QED.
Admin
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.
Admin
Admin
Admin
Never claimed originality, mate...! :)
Admin
Admin
Admin
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...).