[Submission] D Slices

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue May 31 11:56:39 PDT 2011


On 5/31/11 1:36 PM, Timon Gehr wrote:
> eles wrote:
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
>> article
>>> On 5/31/11 11:10 AM, eles wrote:
>>>> I hope some day someone would not have to write a paper like
>> http://
>>>> drdobbs.com/blogs/cpp/228701625 but targetting... D's biggest
>> mistake
>>>> was to use open-limit on the right.
>>> I sure wish that were the biggest mistake! :o)
>>> Andrei
>>
>> Maybe you are right and there are others, too.
>>
>> Is off-topic, but I won't understand why D did not choose to
>> explicitly declare intentions of "break" or "fall" after branches in
>> switch statements (while dropping implicit "fall").
>>
>> It won't break existing or inherited (from C) code. It will just
>> signal that it is illegal and force the programmer to revise it and
>> to make sure it behaves as intended.
>
> In my understanding, you use switch if you want fall through somewhere and if()
> else if() else ... otherwise. (or you remember to break properly)
>
> Yes, it can cause bugs. The other possibility would be to add excessive verbosity.
> (Have a look into the Eiffel programming language.)
>
> I am happy with how Ds switch works, but I understand your concerns too.
>
> Timon

I think a better guideline is to use switch if you have choices of 
similar likelihood and if/else chains otherwise.

This discussion has been carried before. People have collected metrics 
about their code and others'. It turned out that even Walter, who 
perceives using fall through "all the time" was factually wrong (see 
e.g. 
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=101125).

The evidence collected makes it clear to any reasonable observer that 
enforcing flow of control statements after code in case labels would 
mark a net improvement for D. How big? Probably not bigger than 
operating other improvements. But definitely not negligible.


Andrei


More information about the Digitalmars-d mailing list