Is there ANY chance we can fix the bitwise operator precedence rules?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jun 18 19:22:47 PDT 2010


Jonathan M Davis wrote:
> bearophile wrote:
> 
>> 2) switch cases that don't end with goto or break:
>>
>> void main() {
>>     int x, y;
>>     switch (x) {
>>         case 0: y++;
>>         default: y--;
>>     }
>> }
> 
> I, for one, _want_ case statements to be able to fall through. It would be 
> horribly painful in many cases if they couldn't. Now, requiring a separate 
> statement like fallthrough or somesuch instead of break might not be a bad 
> idea, but requiring that each case end with a break would seriously restrict 
> the usefulness of switch statements.

I agree. But the basic idea is to do extra work if you're doing 
something unusual, and falling through is unusual.

A while ago it was proposed to require each case block to end with a 
control flow transfer statement (break, continue, return, throw, or goto 
case XXX). The latter allows fall through in the rare cases that were 
needed, requiring just a bit of extra umph from the programmer. Perfect 
solution.

My recollection of the matter is that Walter rejected the proposal 
claiming that he uses fall through all the time. Don ran some 
measurements over Walter's own code and proved him copiously wrong. 
Walter had no retort to that argument, so he veered into a critique of 
the goto case XXX solution saying it's unmaintainable: when you moving 
code around you want to keep on falling through but with goto you'd need 
to update the goto target. However, it can be argued that logically you 
want to continue processing at some specific logical point, not to 
blindly fall through to whatever the heck code happens to be there.

So ultimately the whole thing fizzled. Apparently the current situation 
is optimal for programmers who use fall through "all the time", who move 
code that is fallen into all the time, have weird expectations of code 
after the move, and never check that jumps are made to the right labels.

As an aside, I think it's an interesting psychological phenomenon: I 
think we often have skewed beliefs about the frequency of our patterns. 
It often happens that switchers to a new language believe they won't be 
able to make it through the day without feature X (bitfields, anyone? 
:o)) yet practical experience soon shows otherwise.


Andrei


More information about the Digitalmars-d mailing list