[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] [PATCH] -Wconversion-null
From:       Douglas Gregor <dgregor () apple ! com>
Date:       2012-03-18 3:52:59
Message-ID: 4034484E-FA6F-47FC-89DA-F805291C738A () apple ! com
[Download RAW message or body]



Sent from my iPhone

On Mar 17, 2012, at 11:50 AM, "James K. Lowden" <jklowden@schemamania.org> wrote:

> On Thu, 15 Mar 2012 21:31:39 -0500
> Joshua Cranmer <pidgeot18@gmail.com> wrote:
> 
> > I should be 
> > able to look at code and not have to reason about the formal
> > underlying algebraic model to figure out what the intent is
> 
> You don't really mean that, do you?  What is programming except the use
> of logical constructs, and how is it possible to program in any
> language without know the meaning expressed through its syntax?  
> 
> Regarding bit-wise operators, I didn't make that case.  They're
> relatively rarely used, and even Dennis Ritchie expressed some regret
> over their precedence.  Logical operators, on the other hand, appear in
> all but the most trivial programs. 
> 
> > most people don't memorize the precedence charts and instantly 
> > plan for minimizing parenthesis usage, especially when you consider
> > that precedence does vary between languages
> 
> I'm not prepared to make any claim about what most programmers do or
> think.  I have a hard time believing, per above, that much useful work
> can be accomplished in C++ without knowing the precedence of C++
> operators.  
> 
> If you know a language that 1) defines operator precedence and 2)
> defines OR before AND, I'd be interested to hear.  I was unable to find
> one.  For that reason I reject the "multi-language confusion"
> hypothesis.  
> 
> AFAIK the question of bugs stemming from logical operator confusion
> hasn't been carefully studied. Rather than assume I'm smarter than the
> poor schlump using my compiler, I prefer to think that whatever I know,
> anyone else can learn, too

Turning these warnings on in our codebase yielded a significant number of real bugs \
with very few false positives. 

> Note you're positing a very peculiar kind of ignorance: the
> programmer who isn't sure of the precedence *and* decides not to use
> parentheses to make the logic clear to *himself*.  I would not presume
> to try to help such a person, and I don't think Clang should, either.  

They exist, and I've returned their bug reports with an explanation of the precedence \
rules. Clang helped them already. 

Programmers make mistakes, even when they know the precedence rules perfectly. Code \
gets refactored, and bugs get introduced. 

You are following a well-trodden path with your line of argument against Wparentheses \
and similar and I personally am not interested in going down it again. Real data from \
real codebases supports the hypothesis that these warnings do more good than harm, \
and no "programmers should know better" argument will change that. 

  - Doug

_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic