November 16, 2009
Steven Schveighoffer wrote:
> On Mon, 16 Nov 2009 03:27:22 -0500, Don <nospam@nospam.com> wrote:
> 
>> Requiring 'goto' to implement fall-through would run into the prejudice against 'goto'. It's necessary to persuade managers that "goto case XXX;" isn't a bad, evil goto that eats babies. I have no idea if that's difficult or not. Otherwise, I think it's a superb solution.
>> (providing that empty fall-through case statements remain valid; disallowing them would be really annoying).
> 
> It hasn't hurt C# at all...
> 
> http://msdn.microsoft.com/en-us/library/06tc147t(VS.80).aspx
> 
> I haven't had any issues with it.  This reminds me of the != null problem.  Now if only Walter made as many mistakes with switch case fallthrough as he did with != null :)
> 
> Walter, at some point, you should heed the complaints of the masses even if it doesn't affect you.  It's like a politician who lives in a nice neighborhood ignoring the requests of his constituents for more police protection in higher crime areas because he doesn't live there.  Except it's worse, because we can't vote you out :)
> 
> Also keep in mind that this does *not* change the power of switch at all, since goto already covers fallthrough.  One thing I learned from the != null to !is null change is that I stopped writing the offending code when I get immediate feedback.  It just gets ingrained in my brain better.  So having to write goto next_case;  all the time is going to be much less of a chore than you think, because you'll just learn to avoid that mistake in the first place.

My thoughts exactly. But that being said, if a guy can't design his own language to cater for what he thinks he frequently does (massive, overwhelming, and exhausting evidence to the contrary notwithstanding), then where is freedom in this world?

:o)

Andrei
November 16, 2009
On Nov 17, 09 02:37, Andrei Alexandrescu wrote:
> KennyTM~ wrote:
>> On Nov 17, 09 01:40, Andrei Alexandrescu wrote:
>>> Bill Baxter wrote:
>>>> On Mon, Nov 16, 2009 at 8:24 AM, Andrei Alexandrescu
>>>> <SeeWebsiteForEmail@erdani.org> wrote:
>>>>> Walter Bright wrote:
>>>>>> Andrei Alexandrescu wrote:
>>>>>>> I was hoping the lesson learned would be to fix switch as was
>>>>>>> suggested.
>>>>>> I checked, because it wasn't written in the way I usually write
>>>>>> things,
>>>>>> and sure enough it wasn't code I wrote :-)
>>>>>>
>>>>>> From the changelog for D 0.129: "Incorporated Ben Hinkle's new
>>>>>> std.format
>>>>>> which can print general arrays."
>>>>>>
>>>>>> http://www.digitalmars.com/d/1.0/changelog1.html#new0129
>>>>> So people are liable to make the mistake.
>>>>>
>>>>> Andrei
>>>>>
>>>>
>>>> What about when you want to fall through to a multiple label? Or a
>>>> range label?
>>>>
>>>> case 0:
>>>> // do stuff
>>>> goto case ??;
>>>> case 1: .. case 9:
>>>> // do more stuff
>>>> goto case ??;
>>>> case 10,20,30:
>>>> // still more stuff
>>>>
>>>> The obvious answer would seem to be just "pick any one".
>>>> I just bring it up because I haven't seen that ... uh case ...
>>>> mentioned by anyone.
>>>>
>>>> --bb
>>>
>>> You must pick the median :o).
>>>
>>> Andrei
>>
>> No way we'll need to write "goto case 3.5;" :p
>
> (Just for precision's sake)
>
> median != average
>
> Andrei

The median of [1,3,4,10000] is 3.5.
November 16, 2009
On Mon, 16 Nov 2009 15:01:47 -0500, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> Steven Schveighoffer wrote:
>> On Mon, 16 Nov 2009 03:27:22 -0500, Don <nospam@nospam.com> wrote:
>>
>>> Requiring 'goto' to implement fall-through would run into the prejudice against 'goto'. It's necessary to persuade managers that "goto case XXX;" isn't a bad, evil goto that eats babies. I have no idea if that's difficult or not. Otherwise, I think it's a superb solution.
>>> (providing that empty fall-through case statements remain valid; disallowing them would be really annoying).
>>  It hasn't hurt C# at all...
>>  http://msdn.microsoft.com/en-us/library/06tc147t(VS.80).aspx
>>  I haven't had any issues with it.  This reminds me of the != null problem.  Now if only Walter made as many mistakes with switch case fallthrough as he did with != null :)
>>  Walter, at some point, you should heed the complaints of the masses even if it doesn't affect you.  It's like a politician who lives in a nice neighborhood ignoring the requests of his constituents for more police protection in higher crime areas because he doesn't live there.  Except it's worse, because we can't vote you out :)
>>  Also keep in mind that this does *not* change the power of switch at all, since goto already covers fallthrough.  One thing I learned from the != null to !is null change is that I stopped writing the offending code when I get immediate feedback.  It just gets ingrained in my brain better.  So having to write goto next_case;  all the time is going to be much less of a chore than you think, because you'll just learn to avoid that mistake in the first place.
>
> My thoughts exactly. But that being said, if a guy can't design his own language to cater for what he thinks he frequently does (massive, overwhelming, and exhausting evidence to the contrary notwithstanding), then where is freedom in this world?

You are totally free to make a language that nobody uses :)

-Steve
November 16, 2009
Don wrote:
> That's not fall-through, one case is *inside* the 'if' clause of another one!! Wow. Do you really want to encourage that sort of thing?

I think it's more the #if that obfuscates the code. After long experience with #if, I really don't like it, which is why I adamantly resist having fine-grained conditional compilation in D.

The optimizer/code generator has a lot of awful #if's in them, generally as a result of it being hackishly ported to other platforms.

I'm not going to stand up and say the optimizer/code gen is a fine example of elegant software (it isn't), just that it *works* and is remarkably free of bugs.
November 16, 2009
Walter Bright wrote:
> Don wrote:
>> That's not fall-through, one case is *inside* the 'if' clause of another one!! Wow. Do you really want to encourage that sort of thing?
> 
> I think it's more the #if that obfuscates the code. After long experience with #if, I really don't like it, which is why I adamantly resist having fine-grained conditional compilation in D.

True, but the case label inside the if statement is obfuscation too. I bet many C/C++ programmers don't even know that this syntax is allowed...

But we need to keep it for duff's device, I guess.
November 16, 2009
Steven Schveighoffer wrote:
> You are totally free to make a language that nobody uses :)

About 10 years ago, I went out jogging with a colleague who was also a programmer. We were talking about compilers, of course, and he said "what the world really needs is a Java compiler that compiles to native code, not this VM bull." He assured me that such a product would sweep the world.

I told him I thought he was right, and so did a lot of people. So right that about 5 years previously, I did just that (for Symantec). Turns out, nobody wanted it. I told him I could get him a copy. He didn't want it either.

<g>

Another fun story. Back in the 80's, a programmer told a friend that the MOST IMPORTANT thing he looked for in a compiler was compilation speed. My friend told him that was obviously the least important thing to him. Shocked, the programmer asked why? My friend told him that he was using the slowest compiler on the market by a factor of 4. There were several other much faster C++ compilers available, but he stuck with the slow one. The programmer reacted like this thought had never occurred to him.

<g>

More fun stuff. 10 years ago, I was convinced by many people that the world needed a fast javascript engine. I built one that was twice as fast as Jscript, and twenty (that's right, 20) times faster than Mozilla's javascript engine. It passed all the test suites.

I couldn't give it away.


On the other hand, the advice I got when starting to write a C compiler was "who the f*** needs another C compiler?" Nobody thought it was a good idea. Turns out, there was a big market for it!


Now, I'm not saying you're wrong. I'm just saying that making a product that people want isn't as simple as asking them what they want. With the switch thing, there's a cost to all the solutions proposed here - rather klunky to look at and significant extra work to type them in.

Perhaps the reason I don't have trouble with the usual switch statements is because it seems natural to me, as I come from an asm/fortran/basic background, where one would never write:

    foo();
    goto L1;
L1: bar();
    goto L2;
L2: baz();
    goto L3;
L3: asdf();
    return;

and case labels look like, well, labels to me. The goto version is ugly and hard to read.


Reminds me a bit of D a few years back, when people would say D didn't have lambda's. But D did have them! The problem was the syntax was a bit verbose. Simplified the syntax, and suddenly the lambda's got noticed and got used.
November 16, 2009
Walter Bright wrote:
> Reminds me a bit of D a few years back, when people would say D didn't have lambda's. But D did have them! The problem was the syntax was a bit verbose. Simplified the syntax, and suddenly the lambda's got noticed and got used.

D has no tuples.
November 16, 2009
On Mon, 16 Nov 2009 11:58:44 +0300, MIURA Masahiro <echochamber@gmail.com> wrote:

> On 11/16/2009 02:49 AM, Chad J wrote:
>> So, switch-case statements are a frequent source of nasty bugs.  Fixing
>> them (well) requires breaking backwards compatibility.
>>
>> Any chance this will happen for D2?
>
> If I remember correctly, one of D's design policies is
> that a D code that looks like C code should behave like C.
> Are we giving up that policy?

It is a good policy to follow but there are cases where C behavior may differ from D behavior (when code is copy-pasted and not adjusted according to languages difference). I've just posted an example in a different thread:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=101322
November 16, 2009
Andrei Alexandrescu wrote:
> Ellery Newcomer wrote:
>> KennyTM~ wrote:
>>> throw ...;
>>> assert(...);
>>>
>>
>> you can call functions which do these...
> 
> ... which is where the "none"/"bottom" type comes into play!
> 
> Andrei

What what?
November 16, 2009
Ellery Newcomer wrote:
> Andrei Alexandrescu wrote:
>> Ellery Newcomer wrote:
>>> KennyTM~ wrote:
>>>> throw ...;
>>>> assert(...);
>>>>
>>> you can call functions which do these...
>> ... which is where the "none"/"bottom" type comes into play!
>>
>> Andrei
> 
> What what?

http://en.wikipedia.org/wiki/Bottom_type
http://www.cs.washington.edu/research/projects/cecil/www/Release/doc-cecil-stdlib/node4.html

I gave a talk about similar stuff once but I don't know where it is. I also have 70% of an article on it written (and with a funny introduction to boot) but I couldn't find the time * interest to finish.


Andrei