Click here to Skip to main content
15,891,431 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Alister Morton12-Sep-19 4:42
Alister Morton12-Sep-19 4:42 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
TrinityRaven12-Sep-19 4:47
TrinityRaven12-Sep-19 4:47 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 4:52
mvahoney the codewitch12-Sep-19 4:52 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
TrinityRaven12-Sep-19 5:23
TrinityRaven12-Sep-19 5:23 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 5:54
mvahoney the codewitch12-Sep-19 5:54 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 6:50
kalberts12-Sep-19 6:50 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
TrinityRaven12-Sep-19 7:46
TrinityRaven12-Sep-19 7:46 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 10:13
kalberts12-Sep-19 10:13 
TrinityRaven wrote:
I didn't say don't use null. I said don't return null
Yes, that's exactly what I pointed out in my loop example: You accept a loop to run until the next element is null unless determining the next element is so complex that it has been pulled out as a function.

If you do that, pull it out as a function, and follow your rule, then the function cannot return the next element the way the simpler inline code (with no function definition) did. The function would have to raise an exception when reaching the end of the list, and the call to the function would have to be wrapped in a try-catch, the exception handler would treat the exception as "ok, so then we set next element to null, so that the while check will terminate the loop", rather than simply accept a the next element as null from the function.

I find that to be an outright silly way of coding - and I don't think that you seriously suggest it. "don't return null" wasn't meant that absolutely; there are cases where communicating a null value to a calling function as something perfectly normal is ... perfectly normal. I say: That happens quite often. You say: OK, in some very special circumstances, like the one with "next object", you could accept it, as an exceptional case. - The question is where to draw the line. But the line is there.

I have seen code that tries to hide nulls by returning pseudo objects: If you ask for, say, a person's spouse, you never receive "null" or "none" or "void", but a person object that has a special identifier member like "no person". Testing for the returned person object being a person with a "no person" identifier is not more convenient by any criteria. You might forget to do that check, too, an reference attributes of this person object, that it doesn't have, because it is a "no person".

Finally: You make an absolute assumption that the called routine remembers to always define the return value to something non-null. I have had cases where the null check on the return value revealed errors in the called function, in a "graceful" way. If my programming style had been "You don't have to check for null returns, because functions do not return null", the error would have been caught much later.

Nowadays, we are using static code analysis tools that do a very thorough check on pointer use. If there is any chance whatsoever that a pointer is null or unassigned when dereferenced, you receive a warning. I have experienced flow paths with 20+ decision points, running through four levels of function calls, telling me that "What you did (or didn't do) there, at the start of the chain, might lead to the pointer you dereference at the end of the chain is null, if this and that and that condition is fulfilled". (And, if I make no use of the returned value, the analyzer is quiet - there is no danger.)
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Bruce Greene12-Sep-19 4:51
Bruce Greene12-Sep-19 4:51 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Ira Greenstein12-Sep-19 5:07
Ira Greenstein12-Sep-19 5:07 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 6:52
kalberts12-Sep-19 6:52 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Ira Greenstein12-Sep-19 8:11
Ira Greenstein12-Sep-19 8:11 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Roger House12-Sep-19 8:05
Roger House12-Sep-19 8:05 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 8:07
mvahoney the codewitch12-Sep-19 8:07 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 9:40
kalberts12-Sep-19 9:40 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
firegryphon12-Sep-19 9:26
firegryphon12-Sep-19 9:26 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Dan Begent16-Sep-19 18:41
Dan Begent16-Sep-19 18:41 
GeneralMs. Monopoly: new board game that gives more money to women players that to men Pin
Daniel Pfeffer11-Sep-19 5:10
professionalDaniel Pfeffer11-Sep-19 5:10 
GeneralRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
PeejayAdams11-Sep-19 5:30
PeejayAdams11-Sep-19 5:30 
GeneralRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
  Forogar  11-Sep-19 7:26
professional  Forogar  11-Sep-19 7:26 
GeneralRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
Dan Neely12-Sep-19 2:43
Dan Neely12-Sep-19 2:43 
GeneralRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
Sander Rossel11-Sep-19 5:49
professionalSander Rossel11-Sep-19 5:49 
GeneralRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
raddevus11-Sep-19 7:22
mvaraddevus11-Sep-19 7:22 
RantRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
lopatir11-Sep-19 5:56
lopatir11-Sep-19 5:56 
GeneralRe: Ms. Monopoly: new board game that gives more money to women players that to men Pin
Marc Clifton11-Sep-19 6:21
mvaMarc Clifton11-Sep-19 6:21 

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.