November 15, 2009 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 16, 2009 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 Re: About switch case statements... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chad J | 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 |
Copyright © 1999-2021 by the D Language Foundation