problems/risks due to programming language, stories requested

Erann Gat gat at robotics.Jpl.Nasa.Gov
Sat Mar 10 02:55:58 AEST 1990


In article <672 at software.software.org>, ciardo at software.org (Gianfranco Ciardo) writes:
> Using subroutines is not going to help you make the code shorter, more compact,
> or less repetitious (which is not) in a case like this:
> 
>           switch (what_to_do) {
>                     case FIVE_THINGS:
>                             <statementA>;
>                     case FOUR_THINGS:
>                             <statementB>;
			[etc.]
>                     case ONE_THING:
>                             <statementE>;
>                     case NOTHING:
>                             break;
>           }

No, but writing the code like this will:

	if (what_to_do >= ONE_THING) <statementE>;
	if (what_to_do >= TWO_THINGS) <statementD>;
	if (what_to_do >= THREE_THINGS) <statementC>;
	if (what_to_do >= TWO_THINGS) <statementB>;
	if (what_to_do >= ONE_THING) <statementA>;

If you wish to quibble over my use of inequalities, replace them with
a disjunction of equalities.

Erann Gat                  gat at robotics.jpl.nasa.gov



More information about the Comp.lang.c mailing list