Click here to Skip to main content
15,896,111 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.

 
JokeRe: MS, you funny! Pin
Nelek11-Nov-18 2:48
protectorNelek11-Nov-18 2:48 
GeneralRe: MS, you funny! Pin
David O'Neil11-Nov-18 8:05
professionalDavid O'Neil11-Nov-18 8:05 
GeneralRe: MS, you funny! Pin
Dirk Bahle12-Nov-18 10:52
Dirk Bahle12-Nov-18 10:52 
GeneralRe: MS, you funny! Pin
Bernhard Hiller13-Nov-18 22:19
Bernhard Hiller13-Nov-18 22:19 
GeneralThis code is evil Pin
den2k887-Nov-18 4:18
professionalden2k887-Nov-18 4:18 
GeneralRe: This code is evil Pin
Pete O'Hanlon7-Nov-18 6:21
mvePete O'Hanlon7-Nov-18 6:21 
GeneralRe: This code is evil Pin
MarkTJohnson7-Nov-18 6:43
professionalMarkTJohnson7-Nov-18 6:43 
GeneralRe: This code is evil Pin
kalberts14-Nov-18 0:54
kalberts14-Nov-18 0:54 
Currently I am so fortunate that my programming is in a language where (numeric != bool) Smile | :)

In my last plain C project, I happened to set up a "#define ever ;;" so that I could write "for (ever) {..." to make an infinite loop, which is not uncommon in embedded code. (In the CHILL language, made for programming phone switches, "DO FOR EVER ..." is defined in the basic language.) One of the other team members reacted quite fiercly to this, searching through the entire code base for "for (ever)", adding a nasty commit message about "someone" who were trying to make funny jokes in the code, and he changed it to the proper "while (1)". The header project files did define "true" and "false" constants, but he woudn't accept even "while (true)": There is one proper way to make an infinte loop in C, and that is "while (1)".

I was seriously considering to change it to "while (2)", with a commit message that 2 makes it twice as clear that the loop should run for (ever), but I decided not to. My relationship to that guy was bad enough without further provocations.

So, provided "condition" is a bool variable, or an numeric variable that stores nothing but the value of bool expressions, I certainly agree that "!condition" is the proper way. But if "condition" is a numeric value treated as such (e.g. a counter from n down to 0), treating it as a bool for flow control is bad. Then "condition == 0" is far better.

Same with pointers. I detest "if (!nextpointer) { /*leave loop*/" - that should be "if (nextpointer == null)" (or "nil" or "empty" or whatever your favorite language calls is).

Which makes me think of that really nice construction I have encountered in a single language: "FOR currentpointer IN listhead:nextpointer DO..." - "nexpointer" being the name of a pointer member in the class "listhead" (and "currentpointer") points to.
GeneralRe: This code is evil Pin
Rick York7-Nov-18 7:23
mveRick York7-Nov-18 7:23 
GeneralRe: This code is evil Pin
Sander Rossel7-Nov-18 7:44
professionalSander Rossel7-Nov-18 7:44 
GeneralRe: This code is evil Pin
Nathan Minier7-Nov-18 8:25
professionalNathan Minier7-Nov-18 8:25 
GeneralRe: This code is evil Pin
Nathan Minier7-Nov-18 8:25
professionalNathan Minier7-Nov-18 8:25 
GeneralRe: This code is evil Pin
Marc Clifton7-Nov-18 8:28
mvaMarc Clifton7-Nov-18 8:28 
JokeRe: This code is evil Pin
Slacker0077-Nov-18 10:46
professionalSlacker0077-Nov-18 10:46 
GeneralRe: This code is evil Pin
Bernhard Hiller8-Nov-18 22:21
Bernhard Hiller8-Nov-18 22:21 
GeneralRe: This code is evil Pin
den2k888-Nov-18 23:15
professionalden2k888-Nov-18 23:15 
GeneralRe: This code is evil Pin
David O'Neil10-Nov-18 12:51
professionalDavid O'Neil10-Nov-18 12:51 
GeneralRe: This code is evil Pin
Lutosław25-Nov-18 11:35
Lutosław25-Nov-18 11:35 
GeneralKodi Irony PinPopular
#realJSOP6-Nov-18 8:17
professional#realJSOP6-Nov-18 8:17 
GeneralRe: Kodi Irony Pin
David O'Neil6-Nov-18 13:31
professionalDavid O'Neil6-Nov-18 13:31 
JokeRe: Kodi Irony Pin
Bernhard Hiller6-Nov-18 22:50
Bernhard Hiller6-Nov-18 22:50 
GeneralRe: Kodi Irony Pin
Mark_Wallace12-Nov-18 8:52
Mark_Wallace12-Nov-18 8:52 
GeneralRe: Kodi Irony Pin
den2k887-Nov-18 1:58
professionalden2k887-Nov-18 1:58 
GeneralRe: Kodi Irony Pin
Gary Wheeler7-Nov-18 2:23
Gary Wheeler7-Nov-18 2:23 
JokeRe: Kodi Irony Pin
Peter_in_27806-Nov-18 23:22
professionalPeter_in_27806-Nov-18 23:22 

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.