Click here to Skip to main content
15,898,036 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 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 
PIEBALDconsult wrote:
Because I can,


You can also check for 0x00000001 which is also an invalid value on most systems. Then, you can also check for 0x00000002, 0x00000003, and all other values you know are invalid. Again, why is 0 specific?


PIEBALDconsult wrote:
and a null pointer is generally more likely than an invalid pointer


I completelly dissagree here. A pointer will have a value NULL only if you explicitly set it to NULL - an unitialized pointer is not going to be NULL, and neither a "dangling" pointer.

PIEBALDconsult wrote:
Again I'll invoke the similarity to a condom

Sorry, there is no similarity at all. Condom protects from some but not all dangers. Checking for NULL protects against nothing.


PIEBALDconsult wrote:
If I write a method that takes several pointers, I can check each one and tell the caller exactly which parameter(s) were null, rather than simply blowing up and making the post-mortem team guess what happened.


Your check makes sense only if your function takes input pointers that can legally be zero, and then ignore them. As an error detection, it is worthless. If a caller passes a NULL pointer to a function, it means he set it to be NULL; detecting a NULL here makes sense only if the function is documented to allow NULL as an option.


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 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult20-Dec-08 17:05
mvePIEBALDconsult20-Dec-08 17:05 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult20-Dec-08 17:46
mvePIEBALDconsult20-Dec-08 17:46 
GeneralRe: NULL Checking and Defensive Programming Pin
Nemanja Trifunovic21-Dec-08 3:59
Nemanja Trifunovic21-Dec-08 3:59 
GeneralRe: NULL Checking and Defensive Programming Pin
harold aptroot19-Dec-08 16:20
harold aptroot19-Dec-08 16:20 
GeneralRe: NULL Checking and Defensive Programming Pin
qualitychecker19-Dec-08 22:33
qualitychecker19-Dec-08 22:33 
GeneralRe: NULL Checking and Defensive Programming Pin
supercat922-Dec-08 11:13
supercat922-Dec-08 11:13 
GeneralRe: NULL Checking and Defensive Programming Pin
PIEBALDconsult22-Dec-08 13:23
mvePIEBALDconsult22-Dec-08 13:23 
GeneralRe: NULL Checking and Defensive Programming Pin
supercat923-Dec-08 10:40
supercat923-Dec-08 10:40 

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.