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 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 
PIEBALDconsult wrote:
I think it's more a question of, if you write a function (perhaps a library function) that takes one or more pointers, do you check them for null or let them blow up? And why?


IMHO, the biggest questions would be:
  1. Is the operation in the null-pointer situation defined by the interface standard?

  2. Would the null-pointer situation have a logical meaning (e.g. it may be useful for a function that reads data from a stream to have an option to simply throw away some data; allowing the function to take a null pointer for such usage may be more elegant than requiring the use of a separate function)?

  3. Are there any circumstances that could case a null pointer to be passed in accidentally?

  4. How would the probable consequence of passing in a null pointer compare with the best result one could achieve?
Incidentally, I found myself annoyed at the design of some TCP libraries which returned the same sort of failure code when a non-blocking write attempt was done on a port whose buffer was full, as when such an attempt was performed on a port that was closed. The full-buffer case needs to be easily distinguishable from the closed-port case, since one will want to wait in the former case but not the latter. In my own libraries, I allow a write to a closed port to immediately return 'success', but then check whether the port is actually open. If the port closed unexpectedly, the data I'm sending will vanish into the aether, but the program won't crash. I may not know how much data vanished in the aether, but oftentimes (1) it won't matter, and (2) it may be impossible to know for certain if some packets gets sent but never acked. A closed port isn't quite the same thing as a null pointer, but I think some of the philosophical arguments are similar.
GeneralRe: NULL Checking and Defensive Programming Pin
mbcvamsidhar23-Dec-08 8:07
mbcvamsidhar23-Dec-08 8:07 
GeneralRe: NULL Checking and Defensive Programming Pin
Yuriy Levytskyy24-Dec-08 23:58
Yuriy Levytskyy24-Dec-08 23:58 
GeneralRe: NULL Checking and Defensive Programming Pin
Wenff14-Jan-09 1:22
professionalWenff14-Jan-09 1:22 
GeneralThreading horror Pin
Tony Pottier13-Dec-08 12:45
Tony Pottier13-Dec-08 12:45 
GeneralRe: Threading horror Pin
PIEBALDconsult14-Dec-08 5:45
mvePIEBALDconsult14-Dec-08 5:45 
JokeRe: Threading horror PinPopular
notmasteryet15-Dec-08 15:40
notmasteryet15-Dec-08 15:40 
GeneralRe: Threading horror Pin
Lutosław16-Dec-08 7:13
Lutosław16-Dec-08 7:13 
GeneralRe: Threading horror Pin
geoffs16-Dec-08 19:43
geoffs16-Dec-08 19:43 
GeneralIterating an Enum? Pin
justastupidgurl13-Dec-08 5:05
justastupidgurl13-Dec-08 5:05 
GeneralRe: Iterating an Enum? Pin
PIEBALDconsult13-Dec-08 5:54
mvePIEBALDconsult13-Dec-08 5:54 
GeneralRe: Iterating an Enum? Pin
justastupidgurl13-Dec-08 20:24
justastupidgurl13-Dec-08 20:24 
GeneralRe: Iterating an Enum? Pin
PIEBALDconsult14-Dec-08 5:44
mvePIEBALDconsult14-Dec-08 5:44 
GeneralRe: Iterating an Enum? [modified] Pin
notmasteryet15-Dec-08 4:11
notmasteryet15-Dec-08 4:11 
GeneralRe: Iterating an Enum? Pin
PIEBALDconsult15-Dec-08 11:01
mvePIEBALDconsult15-Dec-08 11:01 
GeneralHow to be popular among your colleagues PinPopular
notmasteryet11-Dec-08 15:30
notmasteryet11-Dec-08 15:30 
GeneralRe: How to be popular among your colleagues Pin
Thomas Weller11-Dec-08 20:15
Thomas Weller11-Dec-08 20:15 
GeneralRe: How to be popular among your colleagues Pin
Mycroft Holmes11-Dec-08 21:58
professionalMycroft Holmes11-Dec-08 21:58 

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.