Click here to Skip to main content
15,887,979 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: Please, I need encouragement :( Pin
OriginalGriff5-Aug-22 18:53
mveOriginalGriff5-Aug-22 18:53 
GeneralRe: Please, I need encouragement :( Pin
David O'Neil5-Aug-22 19:12
professionalDavid O'Neil5-Aug-22 19:12 
GeneralRe: Please, I need encouragement :( Pin
OriginalGriff5-Aug-22 19:21
mveOriginalGriff5-Aug-22 19:21 
GeneralRe: Please, I need encouragement :( Pin
David O'Neil5-Aug-22 19:27
professionalDavid O'Neil5-Aug-22 19:27 
GeneralRe: Please, I need encouragement :( Pin
PIEBALDconsult5-Aug-22 10:35
mvePIEBALDconsult5-Aug-22 10:35 
GeneralRe: Please, I need encouragement :( Pin
trønderen5-Aug-22 11:16
trønderen5-Aug-22 11:16 
GeneralRe: Please, I need encouragement :( Pin
PIEBALDconsult5-Aug-22 11:30
mvePIEBALDconsult5-Aug-22 11:30 
GeneralRe: Please, I need encouragement :( Pin
trønderen5-Aug-22 12:52
trønderen5-Aug-22 12:52 
For my preferred coding style, there would be no problem, as I put the opening brace at the line of the statement using the block, i.e. at the end of the if statement. That would be require the closing brace to be commented out as well - and the compiler would tell you, if you forgot to.

Assuming your bracing style with separate brace lines, you could of course do the same: Move the # endif down one line and add a # to the closing brace line. Whichever solution you choose, I dislike it: I assume that the block between the braces is indented. This is misleading when the 'if (X>0)' is not compiled.

However, I would never disable validation of X, and most certainly not by an #if directive. I would have made EnableValidationOfX a variable, so that it can be enabled without recompiling, in the binary environment where you experience a problem with invalid X values.

If you insist on the #if, and refuse to include the braces in the conditional compilation, I would prefer that the compiler gives a warning if you compile with EnableValidationOfX is false. If this coding style is common to you, you should probably disable the "Redundant braces" warning altogether.

There is another construct where I guess that lots of others disagree: In a switch(), I like to indent the statements in each case from the case label. I also frown when I see an indent/undent with no brace: Braces and indents go hand in hand. So I like to add braces around the lines of each case. But C class languages do not require case to be a block (also, a single statement is not defined to be a block), so the braces are redundant. If we got the compiler to warn about redundant braces, I would want it to have options to allow my coding style of making each case alternative a block. (But I guess a lot of you would scream at my use of redundant braces in switch() statements!)

One thing I like about lint is that you can insert a lint comment that disables a check for this line only. If you occasionally, but not very often, use constructs like the one above, a similar mechanism for suppressing the warning at this occasion as a special case, would be very nice. It would also serve as a documentation to other programmers to explain that the braces are indeed intended.
GeneralRe: Please, I need encouragement :( Pin
PIEBALDconsult5-Aug-22 13:09
mvePIEBALDconsult5-Aug-22 13:09 
GeneralRe: Please, I need encouragement :( Pin
theoldfool5-Aug-22 11:39
professionaltheoldfool5-Aug-22 11:39 
GeneralRe: Please, I need encouragement :( Pin
#realJSOP6-Aug-22 0:03
mve#realJSOP6-Aug-22 0:03 
GeneralRe: Please, I need encouragement :( Pin
0x01AA6-Aug-22 1:43
mve0x01AA6-Aug-22 1:43 
GeneralRe: Please, I need encouragement :( Pin
#realJSOP7-Aug-22 2:02
mve#realJSOP7-Aug-22 2:02 
GeneralRe: Please, I need encouragement :( Pin
DRHuff6-Aug-22 7:01
DRHuff6-Aug-22 7:01 
GeneralRe: Please, I need encouragement :( Pin
BernardIE531711-Aug-22 16:25
BernardIE531711-Aug-22 16:25 
GeneralWidows11 Pin
Slow Eddie5-Aug-22 3:05
professionalSlow Eddie5-Aug-22 3:05 
GeneralRe: Widows11 Pin
Maximilien5-Aug-22 3:20
Maximilien5-Aug-22 3:20 
GeneralRe: Widows11 Pin
Cp-Coder5-Aug-22 3:23
Cp-Coder5-Aug-22 3:23 
GeneralRe: Widows11 Pin
Nelek5-Aug-22 3:39
protectorNelek5-Aug-22 3:39 
GeneralRe: Widows11 Pin
Mike Hankey5-Aug-22 3:58
mveMike Hankey5-Aug-22 3:58 
GeneralRe: Widows11 Pin
jmaida5-Aug-22 8:27
jmaida5-Aug-22 8:27 
GeneralRe: Widows11 Pin
OriginalGriff5-Aug-22 4:05
mveOriginalGriff5-Aug-22 4:05 
GeneralRe: Widows11 Pin
Cp-Coder5-Aug-22 4:44
Cp-Coder5-Aug-22 4:44 
GeneralRe: Widows11 Pin
jsc425-Aug-22 4:53
professionaljsc425-Aug-22 4:53 
GeneralRe: Widows11 Pin
OriginalGriff5-Aug-22 4:56
mveOriginalGriff5-Aug-22 4:56 

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.