| « Prev | Page 1 | Page 2 | Next » |
Re: Using Design Patterns...or not...
2009-03-11 08:03
•
by
Sandor
(unregistered)
|
|
case 1
first; case 2 first; case 3 first; case else WTF; //This should never occur |
Re: Using Design Patterns...or not...
2009-03-11 08:03
•
by
mitschke
(unregistered)
|
|
Who stole my code?
|
|
I see a pattern here.
|
Re: Using Design Patterns...or not...
2009-03-11 08:16
•
by
DaveK
|
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! |
|
Well, the code's being reused. What more do you want?
|
Re: Using Design Patterns...or not...
2009-03-11 08:18
•
by
Litote.
(unregistered)
|
|
What's this got to do with design patterns? This is just tat code.
|
|
I think I have to change my glasses, I'm now seeing like quadruple
I found the pattern... right-click and click "View source" |
|
There is a name for that pattern, The Copy and Paste Pattern
|
|
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); } |
|
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! |
Re: Using Design Patterns...or not...
2009-03-11 08:39
•
by
Mr^B
(unregistered)
|
_panelInstance = DetailPanelFactory.getInstance(type); It's clearly using design patterns! |
|
This allows you to have at least 4 unit tests instead of just 1.
|
Re: Using Design Patterns...or not...
2009-03-11 08:50
•
by
whoever
(unregistered)
|
|
It's really a WTF, it should use a reusable class to do this, like this:
|
Re: Using Design Patterns...or not...
2009-03-11 08:56
•
by
Code Dependent
|
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? |
|
since when do we poke fun at novices? :( i remember writing garbage like this when i first started out too
|
|
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; } |
Re: Using Design Patterns...or not...
2009-03-11 09:01
•
by
Not THAT Alex
(unregistered)
|
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. |
|
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.
|
Re: Using Design Patterns...or not...
2009-03-11 09:09
•
by
Not THAT Alex
(unregistered)
|
In a textbook?! OK, now that explains a lot. |
|
Clearly the developer should had used a DetailPanelCollectionFactoryObserverManagerFactoryInterface instead.
|
Re: Using Design Patterns...or not...
2009-03-11 09:17
•
by
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.
|
Re: Using Design Patterns...or not...
2009-03-11 09:28
•
by
m0ffx
(unregistered)
|
'Quatloo'? Is that a squat toilet? |
Re: Using Design Patterns...or not...
2009-03-11 09:31
•
by
Anonymous
(unregistered)
|
And now it's on his resume as "- Designed and coded a complex web survey application". |
Re: Using Design Patterns...or not...
2009-03-11 09:44
•
by
Your Name
(unregistered)
|
The Real WTF is it took 2533 and a third lines to handle 15 check boxes. |
Re: Using Design Patterns...or not...
2009-03-11 09:44
•
by
Code Dependent
|
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". |
|
S/he got paid $ per line of code.
|
Re: Using Design Patterns...or not...
2009-03-11 09:55
•
by
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. |
Re: Using Design Patterns...or not...
2009-03-11 10:15
•
by
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! |
Re: Using Design Patterns...or not...
2009-03-11 10:20
•
by
T-Biscuit
(unregistered)
|
Yeah, leave the n00b alone, fellas. |
|
Ah, I love the smell of <a href="http://en.wikipedia.org/wiki/Cargo_cult_programming">Cargo Cult Programming</a> in the morning!
|
Re: Using Design Patterns...or not...
2009-03-11 10:26
•
by
Dr. F
(unregistered)
|
|
D'oh!
|
Re: Using Design Patterns...or not...
2009-03-11 10:37
•
by
diaphanein
(unregistered)
|
|
If at first you don't succeed, copy, paste and fail again.
|
Re: Using Design Patterns...or not...
2009-03-11 10:39
•
by
Code Dependent
|
When you are in edit mode, you'll see a link above the text input box that says BBCode Okay. Click on it. |
Re: Using Design Patterns...or not...
2009-03-11 10:57
•
by
Bobbo
(unregistered)
|
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... |
Re: Using Design Patterns...or not...
2009-03-11 11:03
•
by
Anonymous
(unregistered)
|
|
Yeh, you may laugh... but thats how Command and Singleton patterns were born.... just give him a couple of weeks...
|
|
Maybe in some bizzaro world programmers aren't allowed to create their own methods.
|
Re: Using Design Patterns...or not...
2009-03-11 11:11
•
by
C.L.I.T. Commander
(unregistered)
|
Is this related at all to the Coalition for the Liberation of Itinerate Tree-dwellers? Or the Liberate Apes Before Imprisoning Apes movement? |
Re: Using Design Patterns...or not...
2009-03-11 11:25
•
by
fistposter
(unregistered)
|
|
If it switches on type, it would be straight-forward to avoid copy and paste programming.
Copy and paste this! |
Re: Using Design Patterns...or not...
2009-03-11 11:27
•
by
Code Dependent
|
Personal Emulation of Nubile Isis Society |
Re: Using Design Patterns...or not...
2009-03-11 11:29
•
by
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.
|
Re: Using Design Patterns...or not...
2009-03-11 11:56
•
by
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.
|
Re: Using Design Patterns...or not...
2009-03-11 11:59
•
by
Cro
(unregistered)
|
|
Or the Commitee for the Liberation and Integration of Terrifting Lifeforms and their Rehablibiliation into Society.
CAPTCHA: vulputate |
Re: Using Design Patterns...or not...
2009-03-11 12:01
•
by
Bobbo
(unregistered)
|
Genius.
QED. |
|
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. |
Re: Using Design Patterns...or not...
2009-03-11 12:22
•
by
DaveK
|
Well yes, but Grant Naylor's genius, not Cro's. |
Re: Using Design Patterns...or not...
2009-03-11 12:23
•
by
Anonymous
(unregistered)
|
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. |
Re: Using Design Patterns...or not...
2009-03-11 12:23
•
by
Cro
(unregistered)
|
Never claimed originality, mate...! :) |
Re: Using Design Patterns...or not...
2009-03-11 12:24
•
by
DaveK
|
Well, let's see: Nahh, it's just not the same. |
Re: Using Design Patterns...or not...
2009-03-11 12:25
•
by
DaveK
|
Sorry, wasn't meant to sound accusatory, just giving the original source. Boys from the Dwarf! *wrist-snap* |
|
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...).
|
| « Prev | Page 1 | Page 2 | Next » |