A good use of a bad feature

Root Boy Jim rbj at icst-cmr
Tue May 13 15:45:35 AEST 1986


> root at icst-cmr ((Root Boy) Jim Cottrell) writes:
> [concerning the fall-through case feature]
> >You will find much disagreement on that point, I'm afraid. Fall thru is
> >more flexible. You can always break, but often cases are related so that
> >a particular case requires a superset of another case. It is to DMR's
> >credit that he realized this feature. I sure wouldn't have thought of it.
> 
> An alternate implementation would have been for cases to be distinct by
> default, but "continue" at the bottom of a case would cause a fall-thru.
> (In this model, "break" would be meaningless inside a switch and "continue"
> would be meaningful, instead of the opposite.) 

Interesting. We would give up the ability to contine a loop from within
a switch, but gain the abilty to break from one. This might be a win.

> Given that most use of the
> switch statement *does* have distinct cases, and the exceptions are often
> explicitly labeled /* no break */, I think this would've been better.
> (I would *almost* accept a model with automatic break and no keyword for
> fall-thru, and suffer the occasional goto.)

The point I was trying to make is that given two alternatives, the one
that can simulate the other is more powerful. One could lose this benefit
by being to complex or abstruse, but that is another story. Note that assuming
absence of a feature (break) is easier to generate code for (and get around
from a programming point of view) than assuming presence of same.

> One special instance is where the superset is actually an equivalence, i.e.
> two or more labels on the same code:
> 	case ' ':
> 	case '\t':
> 	case '\n':
> 		white();
> 		break;

Which occurs quite often.

> This would be ugly with the auto-break model, but the solution is to allow
> 	case ' ','\t','\n':
> 		white();
> which I think looks neater anyway.
 
I like it too. Other neat things use this convention. Some bad ones do too.

> (Btw, I find
> 	case '0':
> 	...
> 	case '9':
> 		digit();
> annoyingly verbose in the current model, and often use "if" rather than
> "switch" because of it.)

Or you could use `isdigit'. Or make up a table (say for ascii char syntax
attributes) bitwise encoded, natch!

> Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint

	(Root Boy) Jim Cottrell		<rbj at cmr>
	"One man gathers what another man spills"



More information about the Comp.lang.c mailing list