- 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
I feel OP's pain.
I still find things like this, in code I'm given to review:
...except I've formatted for neatness.
Admin
I had once in a piece of VB-code
If x = 0 Then y = 1 ElseIf x = 1 Then y = 2 ElseIf x = 2 Then y = 3
etc up to 11.
This was to select the right name of the month from an array. This code wasn't just once there but was copied all over the place. I cried a little on the inside.
Admin
I'm also quite scared by the default: break;, to be honest
Admin
You mind if I have some of your tasty beverage to wash this value down with?
Admin
Being in a pedantic mood this morning I'll point out that the replace,ent code is not he same as what it replaced. It lacks the default case of doing nothing if the fi or doesn't match one of the predefined names. Thus a new and subtle bug has been introduced.
Admin
"Thus a new and subtle bug has been introduced."
Or fixed.
Admin
And pray that fieldName contains only the previously defined values.
Admin
This reminds me of a piece of code I once had the misfortune to inherit. Software running a cash register. The transaction processing loop (which chewed through everything you'd done, resulting in something that was a human readable receipt) spanned twentyfour screens layed out just like this.
I could sort of see how this happened ("We have loyalty coupons now? No worries, I'll make a case in the TPL for that"). It didn't make a fun piece of code to inherit, though.
Admin
Exactly what I was thinking! It needs a whitelist (or maybe more likely blacklist, context depending).
Admin
I once had a (supposedly senior) coworker populate the hours in a day like;
_dropdownList.Items.Clear(); _dropdownList.Items.Add("1"); _dropdownList.Items.Add("2"); ...[snip] _dropdownList.Items.Add("24");
Admin
case "<FRIST>": theCommands = theCommands.Replace("<FRIST>", WashTheValue(reader["FieldValue"].ToString(), reader["OrderingFieldID"].ToString(), reader["PriceFormat"].ToString())); break; Oh please... wash the value!!!
Admin
There's something the original code does that the replacement code doesn't: doing nothing when the template field name isn't in the list.
Admin
Eh, my crystal balls say the old code used to have strategically-places parseInt()s for some of the fields.
Admin
Admin
'CLEMATIS' made me giggle more than it should have.
Admin
Or not because, this: "Even worse, as fields were added, someone would have to go in and update this block of code."
Admin
I'm having trouble finding the mouse wheel on my phone.