Click here to Skip to main content
15,896,348 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
Ron Anders11-Sep-19 8:02
Ron Anders11-Sep-19 8:02 
GeneralRe: do any of you others have little coding mantras that save your behind? PinPopular
Sander Rossel11-Sep-19 8:06
professionalSander Rossel11-Sep-19 8:06 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 4:43
kalberts12-Sep-19 4:43 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Maximilien11-Sep-19 8:08
Maximilien11-Sep-19 8:08 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
OriginalGriff11-Sep-19 8:20
mveOriginalGriff11-Sep-19 8:20 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Marc Clifton11-Sep-19 9:03
mvaMarc Clifton11-Sep-19 9:03 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch11-Sep-19 9:12
mvahoney the codewitch11-Sep-19 9:12 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 5:07
kalberts12-Sep-19 5:07 
Marc Clifton wrote:
Don't write an if unless you know what the else does and why.
I have seen programmers consistently adding "else /* do nothing */; after every "if" that doesn't have a natural "else".

I think that clutters up both the logic and the code. Lots of operations are conditional; you perform them when conditions are met. Otherwise you don't, but you don't have to say that expicitly; that is obvious! It follows from the very idea of a conditional operation.

Besides: I prefer to turn up the warning level to maximum while coding. When I take over code with zillions of empty "else"s, I get a zillion warnings about "possibly unintended empty staetement".

What is the real difference between an "if" and, say, a "while"? You suggest that you always should indicate an alternative action when the condition is not met. So how to you specify the alternative action when the "while" condition is not met? If you do not, why not? Isn't that a very similar situation? Why is it less important to know what to do if a "while" condition is false than when an "if" contidion is false?

Actually, I have used one language quite a bit where you could specify what to do when a "while" fails: you could conditionally break out of "for"-loops, and distinguish between breakout and completion of loop:
C++
for listElement in listHead:nextpointer do
  while listElement.key <> wantedKey;
exitfor
  output ("sorry, the wanted key is not in the list");
exitwhile
  output ("found! I can process this list element for you"):
endfor;
This is actually a very nice flow control construction, which is a mess to duplicate in C if you want the "exitfor" and "exitwhile" claused to exexute within the context of the loop (e.g. with access to loop local variables), which is one of the essential points.

I honestly miss that flow construction. Why can't other languages offer it?
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Jörgen Andersson11-Sep-19 9:11
professionalJörgen Andersson11-Sep-19 9:11 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch11-Sep-19 9:14
mvahoney the codewitch11-Sep-19 9:14 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 5:14
kalberts12-Sep-19 5:14 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 5:26
mvahoney the codewitch12-Sep-19 5:26 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 11:57
kalberts12-Sep-19 11:57 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 12:02
mvahoney the codewitch12-Sep-19 12:02 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Rick York11-Sep-19 10:10
mveRick York11-Sep-19 10:10 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch11-Sep-19 10:17
mvahoney the codewitch11-Sep-19 10:17 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Rick York11-Sep-19 13:26
mveRick York11-Sep-19 13:26 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch11-Sep-19 13:30
mvahoney the codewitch11-Sep-19 13:30 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Tony.ADV12-Sep-19 8:35
Tony.ADV12-Sep-19 8:35 
PraiseRe: do any of you others have little coding mantras that save your behind? Pin
Kent K12-Sep-19 2:49
professionalKent K12-Sep-19 2:49 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
David O'Neil11-Sep-19 12:09
professionalDavid O'Neil11-Sep-19 12:09 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch11-Sep-19 12:12
mvahoney the codewitch11-Sep-19 12:12 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 916705711-Sep-19 20:57
Member 916705711-Sep-19 20:57 
PraiseRe: do any of you others have little coding mantras that save your behind? Pin
Gary Wheeler12-Sep-19 2:04
Gary Wheeler12-Sep-19 2:04 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
kalberts12-Sep-19 4:07
kalberts12-Sep-19 4:07 

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.