Click here to Skip to main content
15,888,527 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: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 1:05
pasztorpisti7-Sep-13 1:05 
GeneralRe: Most Unhelpful Message Ever Pin
Andy Brummer1-Aug-13 9:09
sitebuilderAndy Brummer1-Aug-13 9:09 
GeneralRe: Most Unhelpful Message Ever Pin
Argonia1-Aug-13 21:36
professionalArgonia1-Aug-13 21:36 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 1:01
pasztorpisti7-Sep-13 1:01 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 0:59
pasztorpisti7-Sep-13 0:59 
GeneralRe: Most Unhelpful Message Ever Pin
jeron12-Aug-13 5:30
jeron12-Aug-13 5:30 
GeneralRe: Most Unhelpful Message Ever Pin
Chad3F2-Aug-13 13:03
Chad3F2-Aug-13 13:03 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 0:49
pasztorpisti7-Sep-13 0:49 
There are several different kind of runtime errors that are fatal and unpractical to handle in your code. Some of these errors (like null pointer exception/access violation/SIGSEGV/SIGBUS and similar fatal errors) must be handled by your top level crash/exception/signal handlers. Some other errors (like can't create thread, out of memory) are practical to handle by calling your own critical error handler function like CRITICAL("Couldn't create thread!"). This critical handler never returns, logs an error message or shows a messagebox and debugbreaks or terminates the program depending whether you run the program in a debugger or not. What would you do if you call the Start() method of a thread and it returns false??? In most programs you simply cant handle such serious errors so its better to return with nothing (void) from the Start() method and to handle the error inside the Start() method by calling CRTICAL(). What do you do if the pthread_mutex_init() or pthread_mutex_lock() call fails??? Because these have return value! In my opinion these functions shouldn't return anything because handling these errors is impractical, the library should inform you with some debug breaks or internal critical handlers. For example in debug builds/debug sessions pthread_mutex_destroy() should debug break in debug sessions or log/fatal exit in release if you try to destroy a mutex that is held by a thread, pthread_mutex_init should also do the same. I convert these errors to CRITICAL() in my encapsulated mutex classes.

CRITICAL() is a much better approach then seeing the accumulating code that dumbly tries to handle for example thread creation errors here and there (usually untested error handlers that would crash or deadlock sooner or later after an unsuccessful thread creation). Same is true for memory management. If these errors happen than something really wrong is going on with the machine/OS. Instead of handling these errors its better to write and design the program to operate well if the given amount of resources are available (memory, video memory, cpu performance, free disk space, ...)

Probably that exit(0) code should be replaced with a CRITICAL() call.
GeneralRe: Most Unhelpful Message Ever Pin
Chad3F7-Sep-13 12:40
Chad3F7-Sep-13 12:40 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 13:09
pasztorpisti7-Sep-13 13:09 
GeneralRe: Most Unhelpful Message Ever Pin
BillW3330-Aug-13 5:35
professionalBillW3330-Aug-13 5:35 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 0:34
pasztorpisti7-Sep-13 0:34 
QuestionWhich code you suggest? Pin
Rajesh Anuhya24-Jul-13 20:04
professionalRajesh Anuhya24-Jul-13 20:04 
AnswerRe: Which code you suggest? PinPopular
NeverJustHere24-Jul-13 21:02
NeverJustHere24-Jul-13 21:02 
GeneralRe: Which code you suggest? Pin
Reelix25-Jul-13 21:36
Reelix25-Jul-13 21:36 
GeneralRe: Which code you suggest? Pin
KP Lee26-Jul-13 17:21
KP Lee26-Jul-13 17:21 
AnswerRe: Which code you suggest? Pin
_Damian S_24-Jul-13 21:02
professional_Damian S_24-Jul-13 21:02 
AnswerRe: Which code you suggest? PinPopular
Ingo25-Jul-13 3:42
Ingo25-Jul-13 3:42 
AnswerRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 4:48
professionalZurdoDev25-Jul-13 4:48 
GeneralRe: Which code you suggest? PinPopular
OriginalGriff25-Jul-13 5:04
mveOriginalGriff25-Jul-13 5:04 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 5:11
professionalZurdoDev25-Jul-13 5:11 
GeneralRe: Which code you suggest? Pin
Sentenryu25-Jul-13 7:15
Sentenryu25-Jul-13 7:15 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 7:32
professionalZurdoDev25-Jul-13 7:32 
GeneralRe: Which code you suggest? Pin
OriginalGriff25-Jul-13 8:26
mveOriginalGriff25-Jul-13 8:26 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 8:28
professionalZurdoDev25-Jul-13 8:28 

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.