Click here to Skip to main content
15,897,704 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: NULL Checking and Defensive Programming PinPopular
Deflinek18-Dec-08 23:07
Deflinek18-Dec-08 23:07 
GeneralRe: NULL Checking and Defensive Programming Pin
AshokParikh18-Dec-08 23:38
AshokParikh18-Dec-08 23:38 
GeneralRe: NULL Checking and Defensive Programming Pin
Robert Surtees19-Dec-08 2:56
Robert Surtees19-Dec-08 2:56 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult19-Dec-08 2:58
mvePIEBALDconsult19-Dec-08 2:58 
GeneralRe: NULL Checking and Defensive Programming Pin
bmcleod19-Dec-08 3:28
bmcleod19-Dec-08 3:28 
GeneralRe: NULL Checking and Defensive Programming Pin
notmasteryet19-Dec-08 3:37
notmasteryet19-Dec-08 3:37 
GeneralRe: NULL Checking and Defensive Programming Pin
Le centriste19-Dec-08 4:58
Le centriste19-Dec-08 4:58 
GeneralRe: NULL Checking and Defensive Programming Pin
Randor 19-Dec-08 5:54
professional Randor 19-Dec-08 5:54 
Your not on crack, I also follow the same defensive programming philosophy. Checking pointers for NULL does not harm performance at all and anyone who tells you that is mentally deficient. Instructions executed on modern processors are measured in MIPS[^] which is to say millions of instructions per second. Current processors are capable of executing billions of instructions each second.

Of course checking for NULL pointers is a philosophy however its one that I follow. I always check for NULL pointers before using them and when I am done using my pointer I assign it a NULL value. Its two simple rules that I follow and guarantees that I never have a NULL pointer exception in my code.

In my opinion a program should *never* crash to the desktop. I believe it is the engineers duty to detect the NULL pointer exception or other unhandled exceptions and prompt the user with a dialog stating that a critical error has occured and allow the user to attempt a graceful shutdown of the application. A combination of NULL pointer checks, variable validation and a global structured exception handler[^] gives applications stability and reliability. Not all software is created equal, I want mine to be in the top percentage.

Only arrogant programmers do not follow these types of rules, they seem to think their code will never crash. Eventually they are wrong, usually when some poor guy has been working for 6 hours and forgot to save his work.

Best Wishes,
-David Delaune
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic20-Dec-08 15:21
Nemanja Trifunovic20-Dec-08 15:21 
GeneralRe: NULL Checking and Defensive Programming Pin
Randor 20-Dec-08 18:30
professional Randor 20-Dec-08 18:30 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic21-Dec-08 4:16
Nemanja Trifunovic21-Dec-08 4:16 
GeneralRe: NULL Checking and Defensive Programming [modified] Pin
Nemanja Trifunovic19-Dec-08 12:07
Nemanja Trifunovic19-Dec-08 12:07 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult19-Dec-08 17:10
mvePIEBALDconsult19-Dec-08 17:10 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic20-Dec-08 12:55
Nemanja Trifunovic20-Dec-08 12:55 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult20-Dec-08 13:44
mvePIEBALDconsult20-Dec-08 13:44 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic20-Dec-08 14:46
Nemanja Trifunovic20-Dec-08 14:46 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult20-Dec-08 17:00
mvePIEBALDconsult20-Dec-08 17:00 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic20-Dec-08 17:08
Nemanja Trifunovic20-Dec-08 17:08 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic21-Dec-08 4:19
Nemanja Trifunovic21-Dec-08 4:19 
GeneralRe: NULL Checking and Defensive Programming Pin
Dave Kreskowiak20-Dec-08 20:28
mveDave Kreskowiak20-Dec-08 20:28 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic21-Dec-08 4:00
Nemanja Trifunovic21-Dec-08 4:00 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult21-Dec-08 4:02
mvePIEBALDconsult21-Dec-08 4:02 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic21-Dec-08 4:06
Nemanja Trifunovic21-Dec-08 4:06 
GeneralRe: NULL Checking and Defensive Programming Pin
Randor 20-Dec-08 14:40
professional Randor 20-Dec-08 14:40 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic20-Dec-08 15:25
Nemanja Trifunovic20-Dec-08 15:25 

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.