Click here to Skip to main content
15,887,083 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.

 
GeneralNo that isn't going to work Pin
jschell26-Jan-24 6:13
jschell26-Jan-24 6:13 
GeneralRe: No that isn't going to work Pin
PIEBALDconsult26-Jan-24 6:37
mvePIEBALDconsult26-Jan-24 6:37 
GeneralThanks to Chris PinPopular
pkfox26-Jan-24 2:49
professionalpkfox26-Jan-24 2:49 
GeneralRe: Thanks to Chris Pin
dandy7226-Jan-24 7:17
dandy7226-Jan-24 7:17 
GeneralRe: Thanks to Chris Pin
pkfox26-Jan-24 7:57
professionalpkfox26-Jan-24 7:57 
GeneralRe: Thanks to Chris Pin
theoldfool26-Jan-24 13:10
professionaltheoldfool26-Jan-24 13:10 
GeneralRe: Thanks to Chris Pin
Nelek26-Jan-24 21:05
protectorNelek26-Jan-24 21:05 
Generalif else Style Pin
BernardIE531725-Jan-24 17:50
BernardIE531725-Jan-24 17:50 
Greetings & Kind Regards

I seek advice and knowledge of others' practice re/ a minor matter of style. In particular to be specific I vacillate betwixt and between two forms of final statement of if ... else ... series of statements assuming every possible condition is accounted for as shown in simple specimen / example / sample below (not snippet as it is not a snip of a larger code base).

1st style :
if(expression == true) {...}
else {...}

2nd style :
if(expression == true) {...}
else if(expression == false) {...}

Note it is the final statement I am inquiring regards. Do your kind selves accept the default final result as shown in 1st style or perform explicit unnecessary test as shown in 2nd style for no other reason than to make the code self documenting and easier to understand in particular for a complex lengthy series of conditions.

btw in 2nd style on occasion I add as final statement else throw who_the_heck_knows_what_happened;

Thank You Kindly

[edit] I have concluded kind Jacquers is quite correct. As it happened upon some coding just now of a simple series of such it was evident an explicit final test results in confusion as it is clearly not necessary. However in a lengthy complex series an explicit test makes code self documenting and so simpler to understand. KISS

modified 26-Jan-24 0:31am.

GeneralRe: if else Style Pin
Jacquers25-Jan-24 17:56
Jacquers25-Jan-24 17:56 
GeneralRe: if else Style Pin
Gerry Schmitz25-Jan-24 19:01
mveGerry Schmitz25-Jan-24 19:01 
GeneralRe: if else Style Pin
trønderen26-Jan-24 0:16
trønderen26-Jan-24 0:16 
GeneralRe: if else Style PinPopular
Sander Rossel25-Jan-24 20:43
professionalSander Rossel25-Jan-24 20:43 
GeneralRe: if else Style Pin
CPallini25-Jan-24 20:48
mveCPallini25-Jan-24 20:48 
GeneralRe: if else Style Pin
pkfox25-Jan-24 21:10
professionalpkfox25-Jan-24 21:10 
GeneralRe: if else Style Pin
trønderen26-Jan-24 0:28
trønderen26-Jan-24 0:28 
GeneralRe: if else Style Pin
Richard MacCutchan26-Jan-24 1:34
mveRichard MacCutchan26-Jan-24 1:34 
GeneralRe: if else Style Pin
trønderen26-Jan-24 2:23
trønderen26-Jan-24 2:23 
GeneralRe: if else Style Pin
jschell26-Jan-24 5:38
jschell26-Jan-24 5:38 
GeneralRe: if else Style Pin
pkfox26-Jan-24 2:45
professionalpkfox26-Jan-24 2:45 
GeneralRe: if else Style Pin
CPallini26-Jan-24 2:52
mveCPallini26-Jan-24 2:52 
GeneralRe: if else Style Pin
Richard MacCutchan26-Jan-24 3:19
mveRichard MacCutchan26-Jan-24 3:19 
GeneralRe: if else Style Pin
honey the codewitch26-Jan-24 8:13
mvahoney the codewitch26-Jan-24 8:13 
GeneralRe: if else Style Pin
Graeme_Grant26-Jan-24 20:32
mvaGraeme_Grant26-Jan-24 20:32 
GeneralRe: if else Style Pin
k505426-Jan-24 5:51
mvek505426-Jan-24 5:51 
GeneralRe: if else Style Pin
charlieg26-Jan-24 9:58
charlieg26-Jan-24 9: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.