Click here to Skip to main content
15,884,388 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: It's not the most obvious piece of logic. Pin
KChandos26-Oct-10 6:39
professionalKChandos26-Oct-10 6:39 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon26-Oct-10 9:43
mvePete O'Hanlon26-Oct-10 9:43 
GeneralRe: It's not the most obvious piece of logic. Pin
Richard Deeming26-Oct-10 7:54
mveRichard Deeming26-Oct-10 7:54 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon26-Oct-10 9:44
mvePete O'Hanlon26-Oct-10 9:44 
GeneralRe: It's not the most obvious piece of logic. Pin
FrankLaPiana26-Oct-10 8:44
FrankLaPiana26-Oct-10 8:44 
GeneralRe: It's not the most obvious piece of logic. Pin
Keith Barrow26-Oct-10 10:52
professionalKeith Barrow26-Oct-10 10:52 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon26-Oct-10 11:04
mvePete O'Hanlon26-Oct-10 11:04 
GeneralRe: It's not the most obvious piece of logic. Pin
KP Lee26-Oct-10 13:55
KP Lee26-Oct-10 13:55 
Ahhh, teaching him a lifetime skill huh? I hope most of us, who read bad code go:
Is it working correctly?
if no, write a bug and hope someone assigns you ownership so you can fix it.
Hope it's approved, and whoever is assigned the bug takes the time to fix it.

else: Is this egregiously bad, causing performance issues or something else that might cause severe system problems?
if yes, write a bug etc.

else: Do you work in a best practice shop and this violates a best p?
if yes, write a bug etc.

else: Do you work in a best practice shop
if yes, suggest a new best practice reffering to your source and hope it is adopted and the source is addressed.

else: ask yourself if it is worth suggesting to your manager one more thing that could be improved.
if yes, wow, you have a manager who listens to you and acts on your suggestions, or you are working for a new manager, or you are a perrenial optimist.

else: Join the regular ranks, shake your head about the code you see, and go on with your life.

Maybe I have a gift for seeing bad logic.
It took me three days to convince someone this was a bug:
if (current_thread_count <= maximum_thread_count + thread_count_to_add)
add_new_threads(thread_count_to_add);

It took asking for the specification document because I was told this met specifications. I agreed that this exactly met specifications, the only problem is, that specifications aren't asking for what is intended. Huh, what? It took going to the lap, finding out what values they were configured for (maximum_thread_count=120, thread_count_to_add=25) and showing what that would do. (Say your current count is 119, if you add 25 more, the current count would go to 144. You don't want that to happen, right? "Right." Well, 119 is less than 145... "How did you come up with 145" Well, the first value is 120, the second value is 25, added together they are 145. Well, the light dawns, but we continue the exercise proving that the count would go up to 169 because the loop is immediate when if the statement was true and the request is relatively immediate. In theory the count could go to 170.

Anyway, if there is a heavy enough load the service machines should blow up with a thread allocation error. The lab guy who gave us the numbers, pipes up "Oh, yea, we have that problem all the time!"

I'm thinking it would have been nice to know that the problem existed instead of just reading C# code to get up to speed on what the group was doing while waiting for my next assignment. Also, how can the specs get through code review. The person creating the code doesn't see it. I have so much trouble convincing someone there is a problem. I'm passively reading it and it's so bad it almost hurts my eyes.

I heard the problem was significantly reduced, but still occurs. I was on an assignment so it can wait. (Just like everyone else in the group while I was there.)
GeneralRe: It's not the most obvious piece of logic. Pin
KP Lee26-Oct-10 11:31
KP Lee26-Oct-10 11:31 
GeneralRe: It's not the most obvious piece of logic. Pin
Dalek Dave26-Oct-10 11:37
professionalDalek Dave26-Oct-10 11:37 
GeneralRe: It's not the most obvious piece of logic. Pin
Stephen Hewitt27-Oct-10 19:02
Stephen Hewitt27-Oct-10 19:02 
GeneralIf Indexing Then Loop Pin
AspDotNetDev22-Oct-10 11:23
protectorAspDotNetDev22-Oct-10 11:23 
GeneralRe: If Indexing Then Loop Pin
HimanshuJoshi22-Oct-10 11:31
HimanshuJoshi22-Oct-10 11:31 
GeneralRe: If Indexing Then Loop Pin
PIEBALDconsult22-Oct-10 16:55
mvePIEBALDconsult22-Oct-10 16:55 
GeneralRe: If Indexing Then Loop Pin
ghle26-Oct-10 1:31
ghle26-Oct-10 1:31 
GeneralStored Procs, Packages, Views...Pah! PinPopular
Richard A. Dalton19-Oct-10 4:16
Richard A. Dalton19-Oct-10 4:16 
GeneralRe: Stored Procs, Packages, Views...Pah! PinPopular
Ray Cassick19-Oct-10 6:48
Ray Cassick19-Oct-10 6:48 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Kevin Drzycimski19-Oct-10 7:10
Kevin Drzycimski19-Oct-10 7:10 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
PoweredByOtgc19-Oct-10 7:19
PoweredByOtgc19-Oct-10 7:19 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Jason Christian20-Oct-10 7:00
Jason Christian20-Oct-10 7:00 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Richard A. Dalton19-Oct-10 7:30
Richard A. Dalton19-Oct-10 7:30 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Andrew Rissing19-Oct-10 7:54
Andrew Rissing19-Oct-10 7:54 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Richard A. Dalton19-Oct-10 8:24
Richard A. Dalton19-Oct-10 8:24 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Ray Cassick19-Oct-10 12:32
Ray Cassick19-Oct-10 12:32 
GeneralRe: Stored Procs, Packages, Views...Pah! Pin
Richard A. Dalton20-Oct-10 1:32
Richard A. Dalton20-Oct-10 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.