lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: [lmi] A matter of style


From: Vadim Zeitlin
Subject: Re[2]: [lmi] A matter of style
Date: Wed, 7 Mar 2007 01:58:00 +0100

On Tue, 06 Mar 2007 01:52:54 +0000 Greg Chicares <address@hidden> wrote:

GC> >  For this reason to apply you would presumably have to insert a new line
GC> > just before "return" as there is not much sense in adding it below it. And
GC> > to be honest I really don't see how can you forget to add braces then.
GC> 
GC> Probably we all have some personal blind spots. I think I might
GC> have made this mistake myself; I know I've seen others make it
GC> in lmi code, and it can be painful to track down if it's not
GC> rejected in code review.

 I agree in principle but in this particular case if you do somehow write

        if ( condition )
                something;
                return;
        something-else;

the compiler will warn about unreachable code after return. Unfortunately I
see that -Wunreachable-code warning is not used in LMI makefiles but I
think this is a problem on its own as this warning is sometimes very useful
as it can find many other problems in the code and not only the trivial
ones like above (although this is useful as well, of course).

 So I'd like to recommend to try to enable -Wunreachable-code for LMI
compilation and then allow writing just

        if ( condition )
                return;

as forgetting to add the braces will result in a warning.


GC> My worst blind spot is writing equality comparisons with '='.
GC> Try as I might, I cannot learn to do that correctly. But I have
GC> successfully learned to write constants on the left, and that
GC> lets the compiler save me in most cases.

 I had my fair share of ==/= typos in if conditions too. But, again, while
I think it could have been a problem 15 years ago (I don't remember to be
honest) the compilers have completely taken care of this since then as
*any* compiler warns about such mistakes now (unless you disable the
warning, but then you deserve what you get). IMHO it's an incomparably
better solution than using unnatural comparison order which makes you
stumble when both writing and (worse) reading the code.

GC> >  So IMHO using just the usual "return" would be better.
GC> 
GC> Yet then I'd re-raise my original objection.

 Even if -Wunreachable-code can be enabled?

 Thanks,
VZ





reply via email to

[Prev in Thread] Current Thread [Next in Thread]