Click here to Skip to main content
15,890,512 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: Now this is embarassing Pin
Gary R. Wheeler31-Oct-12 3:34
Gary R. Wheeler31-Oct-12 3:34 
GeneralRe: Now this is embarassing Pin
lucien6431-Oct-12 5:00
professionallucien6431-Oct-12 5:00 
GeneralRe: Now this is embarassing Pin
Abhinav S31-Oct-12 5:46
Abhinav S31-Oct-12 5:46 
GeneralRe: Now this is embarassing Pin
Gary R. Wheeler1-Nov-12 3:23
Gary R. Wheeler1-Nov-12 3:23 
QuestionRe: accidental deletion Pin
etkid841-Nov-12 4:38
etkid841-Nov-12 4:38 
AnswerRe: accidental deletion Pin
Gary Wheeler1-Nov-12 6:13
Gary Wheeler1-Nov-12 6:13 
GeneralRe: Now this is embarassing Pin
Martin.Cheng1-Nov-12 23:32
Martin.Cheng1-Nov-12 23:32 
GeneralIs silly bad? PinPopular
Stefan_Lang25-Oct-12 22:53
Stefan_Lang25-Oct-12 22:53 
I've recently stumbled across a line of code that made me itch to post here. I've reconsidered however and moved on. I didn't fix the line however, since it did the right thing, just in a silly way. In retrospect, there was no good reason not to fix it, but then, and that probably what I was thinking, neither was there a reason to fix it.

Some time has passed, and somehow I was reminded of that line in a different context: code maintenance and code readability. I asked myself, why was it that I could immediately recognize the sillyness of that line? Apparently I was able to instantly understand it! When I think of the more elegant solution, I would have had to look at it for a fraction of a second to grasp it's meaning. Not so the 'silly' code: it was so glaring obvious that just skimming over it shouted it's meaning into my face without any conscious effort on my part.

Here's the equivalent of that line (I don't recall what it was literally):
C++
bool flag = (a > b) ? true : false;

The reason it's instantly obvious is that the resulting value is written out in plain text, rather than hidden in the somewhat obscure use of a condition as value. Some might argue there is nothing obscure in assigning a condition, but in spite of doing that exact thing hundreds of times, I still find myself hesitating a fraction of a second every time I see something like that in another persons code.

Now I wonder: just how silly is code that is so obvious that you immediately know what it does? Should you really change that code to something more elegant? Should you even tell the programmer who did that to do it differently in the future?

If it works, that's good. If it's readable, that's even better. And if the programmer feels comfortable doing it that way, why urge him to do it another way? I feel it's a trade-off between improving style and maintainability, and in the end it's only the latter that counts.
GeneralRe: Is silly bad? Pin
BobJanova25-Oct-12 22:58
BobJanova25-Oct-12 22:58 
GeneralRe: Is silly bad? Pin
peterchen25-Oct-12 23:37
peterchen25-Oct-12 23:37 
GeneralRe: Is silly bad? Pin
Stefan_Lang26-Oct-12 0:56
Stefan_Lang26-Oct-12 0:56 
GeneralRe: Is silly bad? Pin
BobJanova26-Oct-12 1:01
BobJanova26-Oct-12 1:01 
GeneralRe: Is silly bad? Pin
Stefan_Lang26-Oct-12 1:53
Stefan_Lang26-Oct-12 1:53 
GeneralRe: Is silly bad? Pin
BobJanova26-Oct-12 2:34
BobJanova26-Oct-12 2:34 
GeneralRe: Is silly bad? Pin
Stefan_Lang26-Oct-12 3:51
Stefan_Lang26-Oct-12 3:51 
GeneralRe: Is silly bad? Pin
Paulo Zemek30-Oct-12 4:43
mvaPaulo Zemek30-Oct-12 4:43 
GeneralRe: Is silly bad? Pin
BlackMilan29-Oct-12 23:09
BlackMilan29-Oct-12 23:09 
GeneralRe: Is silly bad? Pin
Stefan_Lang30-Oct-12 0:13
Stefan_Lang30-Oct-12 0:13 
GeneralRe: Is silly bad? Pin
goodsport30-Oct-12 15:41
goodsport30-Oct-12 15:41 
GeneralRe: Is silly bad? Pin
Member 460889831-Oct-12 21:20
Member 460889831-Oct-12 21:20 
GeneralRe: Is silly bad? Pin
Paulo Zemek30-Oct-12 3:23
mvaPaulo Zemek30-Oct-12 3:23 
GeneralRe: Is silly bad? Pin
Fabio Franco30-Oct-12 10:43
professionalFabio Franco30-Oct-12 10:43 
GeneralRe: Is silly bad? Pin
lucien6431-Oct-12 5:13
professionallucien6431-Oct-12 5:13 
GeneralA very terrifying stored procedure: how can you solve this issue really ??? PinPopular
devenv.exe24-Oct-12 20:07
professionaldevenv.exe24-Oct-12 20:07 
GeneralRe: A very terrifying stored procedure: how can you solve this issue really ??? Pin
HaBiX24-Oct-12 20:29
HaBiX24-Oct-12 20:29 

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.