Jump to page: 1 2
Thread overview
Super Lint
Sep 20, 2006
Walter Bright
Sep 20, 2006
Pragma
Sep 20, 2006
J Duncan
Sep 20, 2006
Walter Bright
Sep 20, 2006
Ivan Senji
Sep 20, 2006
Walter Bright
Sep 20, 2006
Frits van Bommel
Sep 20, 2006
Lutger
Sep 20, 2006
xs0
Sep 20, 2006
Walter Bright
Sep 20, 2006
Frits van Bommel
Sep 23, 2006
Kevin Bealer
Sep 20, 2006
Derek Parnell
Sep 21, 2006
Luís Marques
Sep 21, 2006
Miles
September 20, 2006
I've been interested in various ideas for static checking for common bug patterns for D. For example:

	for (int i = 0; i < 10; i++)
	{	foo();
		break;
	}

would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?
September 20, 2006
Walter Bright wrote:
> I've been interested in various ideas for static checking for common bug patterns for D. For example:
> 
>     for (int i = 0; i < 10; i++)
>     {    foo();
>         break;
>     }
> 
> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?


Well, one could throw from within foo(), but that would still abort the loop on the first pass.  Nope, there's no legitimate use I can think of.

Are you considering making a lint tool for D?

-- 
- EricAnderton at yahoo
September 20, 2006
Pragma wrote:
> Walter Bright wrote:
>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>
>>     for (int i = 0; i < 10; i++)
>>     {    foo();
>>         break;
>>     }
>>
>> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?
> 
> 
> Well, one could throw from within foo(), but that would still abort the loop on the first pass.  Nope, there's no legitimate use I can think of.
> 
> Are you considering making a lint tool for D?
> 
No, not a lint tool.... A SUPER LINT Tool!!! :) I cant wait
September 20, 2006
Pragma wrote:
> Walter Bright wrote:
>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>
>>     for (int i = 0; i < 10; i++)
>>     {    foo();
>>         break;
>>     }
>>
>> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?
> 
> 
> Well, one could throw from within foo(), but that would still abort the loop on the first pass.  Nope, there's no legitimate use I can think of.
> 
> Are you considering making a lint tool for D?

Not exactly. Lint finds things that might be bugs, but my experience with Lint is it flags legitimate code patterns as bugs. I'd prefer to do things that are out and out bugs, like the example above.
September 20, 2006
Walter Bright wrote:
> Pragma wrote:
>> Walter Bright wrote:
>>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>>
>>>     for (int i = 0; i < 10; i++)
>>>     {    foo();
>>>         break;
>>>     }
>>>
>>> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?
>>
>>
>> Well, one could throw from within foo(), but that would still abort the loop on the first pass.  Nope, there's no legitimate use I can think of.
>>
>> Are you considering making a lint tool for D?
> 
> Not exactly. Lint finds things that might be bugs, but my experience with Lint is it flags legitimate code patterns as bugs. I'd prefer to do things that are out and out bugs, like the example above.

But is it safe do declare the above example as a bug? Maybe that break is placed there to see what just one pass of the loop does (maybe for debugging purposes).
September 20, 2006
Ivan Senji wrote:
> Walter Bright wrote:
>> Pragma wrote:
>>> Walter Bright wrote:
>>>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>>>
>>>>     for (int i = 0; i < 10; i++)
>>>>     {    foo();
>>>>         break;
>>>>     }
>>>>
>>>> would be flagged as a suspicious use of break.

> But is it safe do declare the above example as a bug? Maybe that break is placed there to see what just one pass of the loop does (maybe for debugging purposes).

That certainly is the question. I don't think I'd want to see such code in released source, but:

1) is it legitimate for debug/test code?
2) can it come about as the side effect of some other coding pattern?
3) if it is made illegal, is that going to be a bigger problem than it solves?
4) does it really solve a problem?

For example, it could happen with (example found on the internet):

	for (int i = 0; i < 10; i++)
	{
		if (condition)
			action();
			break;
	}

where the user forgot to put { } around the else clause. It's sort of like how:

	for (int i = 0; i < 10; i++);
	{
		...
	}

is illegal in D (note the ; after the closing parenthesis). I've known people to spend many hours trying to track down this nearly invisible bug.
September 20, 2006
Walter Bright wrote:
> I've been interested in various ideas for static checking for common bug patterns for D. For example:
> 
>     for (int i = 0; i < 10; i++)
>     {    foo();
>         break;
>     }
> 
> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?

Well, I occasionally write something similar:

for (int i = 0; i < max_retries; i++) {
    try {
        foo();
    } catch (Exception e) {
        continue;
    }
    break;
}

I'm not sure if it's related, though (does the continue make Lint shut up?). I have no "legitimate" ideas about breaking unconditionally, though, except for debugging.


xs0
September 20, 2006
Walter Bright wrote:
> Ivan Senji wrote:
>> Walter Bright wrote:
>>> Pragma wrote:
>>>> Walter Bright wrote:
>>>>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>>>>
>>>>>     for (int i = 0; i < 10; i++)
>>>>>     {    foo();
>>>>>         break;
>>>>>     }
>>>>>
>>>>> would be flagged as a suspicious use of break.
> 
>> But is it safe do declare the above example as a bug? Maybe that break is placed there to see what just one pass of the loop does (maybe for debugging purposes).
> 
> That certainly is the question. I don't think I'd want to see such code in released source, but:
> 
> 1) is it legitimate for debug/test code?

Most legal code will probably be legitimate for /some/ debug/test code. The question is, would you want to run a tool like this on such code? (I'm presuming this will be an exteral tool)
Besides, if debug code like this is found, I'd hope a tool like this would alert me to the fact I forgot to remove some debugging code.

> 2) can it come about as the side effect of some other coding pattern?

Probably not as written, but how about this variant:

    for (int i = 0; i < 10; i++)
    {
        if (foo()) continue;
        break;
    }

Granted, it should be relatively simple to detect a continue statement that has an effect on the loop since it can't hide in function calls.
I can't think of any other reason to use an unconditional break except the above-mentioned debug scenario.

> 3) if it is made illegal, is that going to be a bigger problem than it solves?

Illegal or just flagged by this "super lint"?
I've never used lint, but my understanding is that it's an external tool that checks for common errors (that are still legal code). As such, it can't actually make things illegal, just advise against them when found.

> 4) does it really solve a problem?
> 
> For example, it could happen with (example found on the internet):
> 
>     for (int i = 0; i < 10; i++)
>     {
>         if (condition)
>             action();
>             break;
>     }
> 
> where the user forgot to put { } around the else clause. It's sort of like how:
> 
>     for (int i = 0; i < 10; i++);
>     {
>         ...
>     }
> 
> is illegal in D (note the ; after the closing parenthesis). I've known people to spend many hours trying to track down this nearly invisible bug.

This is a tougher question. Though it may be nice to have it warn about multiple indented statements (without {}s) after a conditional or loop statement, that might be a more common problem than unconditional breaks.
Of course, that would mean it has to pay attention to formatting, which might complicate things.
September 20, 2006
xs0 wrote:
> Walter Bright wrote:
>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>
>>     for (int i = 0; i < 10; i++)
>>     {    foo();
>>         break;
>>     }
>>
>> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?
> 
> Well, I occasionally write something similar:
> 
> for (int i = 0; i < max_retries; i++) {
>     try {
>         foo();
>     } catch (Exception e) {
>         continue;
>     }
>     break;
> }

Hmm. That does look like a quite reasonable use case.
September 20, 2006
Walter Bright wrote:
> xs0 wrote:
>> Walter Bright wrote:
>>> I've been interested in various ideas for static checking for common bug patterns for D. For example:
>>>
>>>     for (int i = 0; i < 10; i++)
>>>     {    foo();
>>>         break;
>>>     }
>>>
>>> would be flagged as a suspicious use of break. Are there any legitimate uses of break in this manner? Any thoughts and ideas in this direction?
>>
>> Well, I occasionally write something similar:
>>
>> for (int i = 0; i < max_retries; i++) {
>>     try {
>>         foo();
>>     } catch (Exception e) {
>>         continue;
>>     }
>>     break;
>> }
> 
> Hmm. That does look like a quite reasonable use case.

It also looks like a quite /detectable/ use case. Just look for a continue statement somewhere in that loop (and outside any nested ones).
« First   ‹ Prev
1 2