View mode: basic / threaded / horizontal-split · Log in · Help
January 02, 2011
Re: Less commas
Walter:

> If you really want to be productive with this, rather than sitting back and 
> thinking up imaginary problems, do things like peruse the bug database of a 
> large open source project. Look for patterns of problems that might be headed 
> off with language solutions.

A common bug in Linux kernel:

if(!state->card->
 ac97_status&CENTER_LFE_ON)
    val&=~DSP_BIND_CENTER_LFE;

The fix is to replace (!E & C) with (!(E & C)).

Currently D acts like C:

void main() {
   uint x, y;
   if (!x & y) {}
}

- 96 instances of this bug in Linux from 2.6.13 (August 2005) to v2.6.28 (December 2008).
- 58 instances of this bug in 2.6.20 (February 2007)
- 2 in Linux-next (October 10, 2009)

They have faced and reduced the number of such bugs using Coccinelle, see pages 8-9 here:
http://coccinelle.lip6.fr/papers/fosdem10.pdf

See you later,
bearophile
January 02, 2011
Re: Less commas
bearophile wrote:
> A common bug in Linux kernel:
> 
> if(!state->card->
>   ac97_status&CENTER_LFE_ON)
>      val&=~DSP_BIND_CENTER_LFE;
> 
> The fix is to replace (!E & C) with (!(E & C)).
> 
> Currently D acts like C:
> 
> void main() {
>     uint x, y;
>     if (!x & y) {}
> }
> 
> - 96 instances of this bug in Linux from 2.6.13 (August 2005) to v2.6.28 (December 2008).
> - 58 instances of this bug in 2.6.20 (February 2007)
> - 2 in Linux-next (October 10, 2009)
> 
> They have faced and reduced the number of such bugs using Coccinelle, see pages 8-9 here:
> http://coccinelle.lip6.fr/papers/fosdem10.pdf

This is great stuff, bearophile. Thanks for finding that. Please add this as an 
enhancement request to bugzilla (disallowing (!x&y) expressions).
January 02, 2011
Re: Less commas
On 2/01/11 8:04 PM, Walter Bright wrote:
> bearophile wrote:
>> A common bug in Linux kernel:
>>
>> if(!state->card->
>> ac97_status&CENTER_LFE_ON)
>> val&=~DSP_BIND_CENTER_LFE;
>>
>> The fix is to replace (!E & C) with (!(E & C)).
>>
>> Currently D acts like C:
>>
>> void main() {
>> uint x, y;
>> if (!x & y) {}
>> }
>>
>> - 96 instances of this bug in Linux from 2.6.13 (August 2005) to
>> v2.6.28 (December 2008).
>> - 58 instances of this bug in 2.6.20 (February 2007)
>> - 2 in Linux-next (October 10, 2009)
>>
>> They have faced and reduced the number of such bugs using Coccinelle,
>> see pages 8-9 here:
>> http://coccinelle.lip6.fr/papers/fosdem10.pdf
>
> This is great stuff, bearophile. Thanks for finding that. Please add
> this as an enhancement request to bugzilla (disallowing (!x&y)
> expressions).

That really surprises me that it's a common bug. Isn't it obvious that ! 
has higher precedence than &? Or have I totally misunderstood the cause 
of the bug?
January 02, 2011
Re: Less commas
On 1/2/2011 12:56 PM, Peter Alexander wrote:
> On 2/01/11 8:04 PM, Walter Bright wrote:
>> bearophile wrote:
>>> A common bug in Linux kernel:
>>>
>>> if(!state->card->
>>> ac97_status&CENTER_LFE_ON)
>>> val&=~DSP_BIND_CENTER_LFE;
>>>
>>> The fix is to replace (!E & C) with (!(E & C)).
>>>
>>> Currently D acts like C:
>>>
>>> void main() {
>>> uint x, y;
>>> if (!x & y) {}
>>> }
>>>
>>> - 96 instances of this bug in Linux from 2.6.13 (August 2005) to
>>> v2.6.28 (December 2008).
>>> - 58 instances of this bug in 2.6.20 (February 2007)
>>> - 2 in Linux-next (October 10, 2009)
>>>
>>> They have faced and reduced the number of such bugs using Coccinelle,
>>> see pages 8-9 here:
>>> http://coccinelle.lip6.fr/papers/fosdem10.pdf
>>
>> This is great stuff, bearophile. Thanks for finding that. Please add
>> this as an enhancement request to bugzilla (disallowing (!x&y)
>> expressions).
> 
> That really surprises me that it's a common bug. Isn't it obvious that ! has
> higher precedence than &? Or have I totally misunderstood the cause of the bug?

I haven't read the paper, probably should, but is it counting found, fixed,
introduced?  Each of those are different data points.  Also of interest would be
any indicator of total bug counts during that same period.  We're talking about
a LONG period of time here (5-6 years) and a rather large code base that does a
lot of low level bit manipulations.

Later,
Brad
January 02, 2011
Re: Less commas
Peter Alexander <peter.alexander.au@gmail.com> wrote:

> That really surprises me that it's a common bug. Isn't it obvious that !  
> has higher precedence than &? Or have I totally misunderstood the cause  
> of the bug?

No, you got the cause right. However, how often are you actually
interested in doing (!foo)&bar?

The language can very well disallow such syntax, because most of the
time, it's not what you want it to do.

-- 
Simen
January 02, 2011
Re: Less commas
Walter Bright wrote:

> disallowing (!x&y) expressions

While `!x&y' may be replaced by `y&!x',
for `!x&&y' an isomorphic change is not possible.

-manfred
January 02, 2011
Re: Less commas
Peter Alexander wrote:
> That really surprises me that it's a common bug. Isn't it obvious that ! 
> has higher precedence than &? Or have I totally misunderstood the cause 
> of the bug?

That's the interesting part, and why I suggested that studying recurring 
patterns of real life bugs is productive. What we think might be a problem vs 
what actually is a problem can be very different.
January 02, 2011
Re: Less commas
Walter Bright wrote:
> That's the interesting part, and why I suggested that studying recurring 
> patterns of real life bugs is productive. What we think might be a 
> problem vs what actually is a problem can be very different.

This also reminds me of how the reliability of aircraft engines was improved 
during WW2. The engines were mounted on a test stand and simply run at full 
power until they broke. The broken part was analyzed, redesigned, installed, and 
the engine run again until it broke. Rinse, repeat.
January 02, 2011
Re: Less commas
On Sun, 02 Jan 2011 20:56:48 +0000
Peter Alexander <peter.alexander.au@gmail.com> wrote:

> > This is great stuff, bearophile. Thanks for finding that. Please add
> > this as an enhancement request to bugzilla (disallowing (!x&y)
> > expressions).  
> 
> That really surprises me that it's a common bug. Isn't it obvious that ! 
> has higher precedence than &? Or have I totally misunderstood the cause 
> of the bug?

That's not such surprising: a study on the topic (operator priority) has shown a very high frequency of such errors (in C). The public were all highly educated, tranined, experienced, programmers. 
On the other hand, the same study showed how ridiculous the proportion of lines of code holding poly-operator expressions is (which comparatively still highers the relative frequency of errors).
A logical conclusions is , I guess: is it worth complexifying a language (by a sub-language just for expressions, which is often the bigger and most complicated part of a parser) & causing loads of bugs for a need that arises even 1000th lines of code?

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com
January 02, 2011
Re: Less commas
On Sun, 02 Jan 2011 13:21:33 -0800
Walter Bright <newshound2@digitalmars.com> wrote:

> That's the interesting part, and why I suggested that studying recurring 
> patterns of real life bugs is productive. What we think might be a problem vs 
> what actually is a problem can be very different.

Thank you for pointing (& re-pointing) at that, Walter.

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home