November 15, 2009
On Sun, 15 Nov 2009 15:03:39 -0600, Andrei Alexandrescu wrote:


> I'm not sure where that leaves us. Others - please add your experience.

Once Euphoria had implemented the 'fallthru' statement, it was like a weight lifted from the code. It just looked better and was far easier to write code. A small change, but an wonderfully liberating change. A bit like the effect of using [$] rather than [length].

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
November 15, 2009
Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> Don wrote:
>>> And looking at how rarely it's actually used by someone who thinks he uses it a lot, convinces me that intentional use of fall-through is much less common than bugs introduced by leaving out a break statement.
>>
>> Except that I cannot recall ever having a bug from leaving out a break <g>.
> 
> I can. I'm not sure where that leaves us. Others - please add your experience.
> 
> Andrei

Just did a quick scan of phobos1. Found 5 instances of fallthrough, not including one around line 182, format.d

    case Mangle.Tdchar:
      ti = typeid(dchar);
    default:
      ti = null;

I have a hard time believing that was intentional, although it as near as I can tell it will never be executed.

"Written by Walter Bright"

hm.

November 15, 2009
Andrei Alexandrescu

> Link?

If you do a search with Google with:
switch bug "missing break"
Or:
switch bug "fall through"
Or:
switch most common programming bugs

You will see a ton of pages.
Wikipedia says this is a common bug:
http://en.wikipedia.org/wiki/Switch_statement
A bug in Python:
http://bugs.python.org/issue4772
Gcj:
http://gcc.gnu.org/ml/java/2001-12/msg00153.html
Page on C++ pitfalls:
http://www.gauravcreations.com/tutorials/c_pitfalls.html
It's error 825 on Gimpel:
http://www.gimpel.com/html/pub90/msg.txt
Ona page of common C bugs:
http://drpaulcarter.com/cs/common-c-errors.php#2.1
Another in Gcc:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31137
More:
http://pear.php.net/bugs/bug.php?id=5020
http://sourceware.org/ml/gdb-patches/2006-04/msg00234.html
https://savannah.cern.ch/bugs/?15576
http://aspn.activestate.com/ASPN/Mail/Message/php-Dev/901756
http://opensource.atlassian.com/projects/hibernate/browse/HHH-448
A page that warns again them:
http://www.jaggersoft.com/pubs/CVu09_1.html
Listed by Linus:
http://lkml.org/lkml/2005/9/30/219
Java findbugs is supposed to find them:
http://osdir.com/ml/java.findbugs.general/2005-01/msg00020.html
In boost:
http://www.boost.org/doc/tools/jam/jam/history.html

If you keep searching you can find a good amount of them.
It's not the most common kind of bug, but it seems common enough to deserve warnings, lints, several pages of "C/C++ traps & tricks", etc.

There is also a well know bug by AT&T, but it's a little different: http://www.gowrikumar.com/blog/2009/01/06/att-break-bug/

Bye,
bearophile
November 16, 2009
Walter Bright, el 15 de noviembre a las 12:13 me escribiste:
> Don wrote:
> >And looking at how rarely it's actually used by someone who thinks he uses it a lot, convinces me that intentional use of fall-through is much less common than bugs introduced by leaving out a break statement.
> 
> Except that I cannot recall ever having a bug from leaving out a break <g>.

A lot of people do.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Yo soy peperino el que siempre pone el vino, yo soy aquel que come los
huevos con tocino.
	-- Peperino PĆ³moro
November 16, 2009
bearophile wrote:
> A bug in Python:
> http://bugs.python.org/issue4772

That is the only one I checked, and it was not a case fall-through bug. It was failure to provide a default.

November 16, 2009
Ellery Newcomer wrote:
> Just did a quick scan of phobos1. Found 5 instances of fallthrough, not
> including one around line 182, format.d
> 
>     case Mangle.Tdchar:
>       ti = typeid(dchar);
>     default:
>       ti = null;
> 
> I have a hard time believing that was intentional, although it as near
> as I can tell it will never be executed.
> 
> "Written by Walter Bright"
> 
> hm.
> 

LOL! Looks like you got me there. It appears here: http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/format.d?rev=132
in the first version of that switch statement.

I'll check in a fix.

Lesson learned: Never open source your software! <g>
November 16, 2009
Walter Bright, el 15 de noviembre a las 18:10 me escribiste:
> Ellery Newcomer wrote:
> >Just did a quick scan of phobos1. Found 5 instances of fallthrough, not including one around line 182, format.d
> >
> >    case Mangle.Tdchar:
> >      ti = typeid(dchar);
> >    default:
> >      ti = null;
> >
> >I have a hard time believing that was intentional, although it as near as I can tell it will never be executed.
> >
> >"Written by Walter Bright"
> >
> >hm.
> >
> 
> LOL! Looks like you got me there. It appears here: http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/format.d?rev=132
> in the first version of that switch statement.
> 
> I'll check in a fix.
> 
> Lesson learned: Never open source your software! <g>

Yes, you might get a good quality software when doing that, who wants that!? =)

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
I am so psychosomatic it makes me sick just thinking about it!
	-- George Constanza
November 16, 2009
On 2009-11-15 16:03:39 -0500, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> said:

> Walter Bright wrote:
>> Don wrote:
>>> And looking at how rarely it's actually used by someone who thinks he uses it a lot, convinces me that intentional use of fall-through is much less common than bugs introduced by leaving out a break statement.
>> 
>> Except that I cannot recall ever having a bug from leaving out a break <g>.
> 
> I can. I'm not sure where that leaves us. Others - please add your experience.

I did not get my habit of adding a "// fallthrough" comment because someone told me I should. It was after experiencing too many "forgotten break" bugs that I began to do this so that now if I read some of my code that doesn't explicitly mention it wants falltrhough, it looks immeditately suspicious. Thus, it helps detecting bugs earlier.

Apparently, Walter's whitespace convention accomplish the same goal. I wonder from where it comes...

Most of those missing break bugs I catch early when debugging or reviewing, but that is still needlessly time-consuming considering it'd be pretty simple for the compiler to make sure everything is all right.


-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

November 16, 2009
Walter Bright:

> That is the only one I checked, and it was not a case fall-through bug. It was failure to provide a default.

Sorry...
Most of those bugs seem about the missing break, but indeed it seems that the missing default is an even more common bug, that's why I have said "It's not the most common bug".

Bye,
bearophile
November 16, 2009
On Sun, Nov 15, 2009 at 1:16 PM, Chad J <chadjoan@__spam.is.bad__gmail.com> wrote:
> Walter Bright wrote:
>> Don wrote:
>>> And looking at how rarely it's actually used by someone who thinks he uses it a lot, convinces me that intentional use of fall-through is much less common than bugs introduced by leaving out a break statement.
>>
>> Except that I cannot recall ever having a bug from leaving out a break <g>.
>
> That's because you're a cyborg.
>
> Have some pity on us mere mortals ;)

Yeh, you have to wondoer, is the goal to write a language that's perfect for yourself or perfect for the widest audience possible?

--bb