Richard said:
Fiddlesticks. To illustrate, here's a paraphrase of code I wrote
recently, in another language:
switch (object.type) {
case TextFrame:
if (adjust_content)
fit_header_width(object);
fit_frame_content(object);
object.length+=descender;
break;
case ImageFrame:
if (adjust_content) {
fit_image_frame_minimal(object);
if (object.content.width<object.width)
fit_image_frame_maximal();
}
fit_frame_content(object);
break;
default:
message("Can't fit that.");
break;
}
where adjust_content is a (user-provided) parameter to the fitting
procedure. Care to explain how I'd have done this more clearly with a
single switch?
Richard
To every sad experience there are exceptions. Your example is simple
enough that it is still clear, although it might have been clearer had
the actions for each case been factored out as separate subroutines
with names that indicate what they do, i.e.
switch (object.type) {
case TextFrame:
fitText(adjust_content,object);
break;
case ImageFrame:
fitImage(adjust_content,object);
break;
default:
message("Can't fit that.");
break;
}
where the if's are factored into the subroutines. If your language
permits ? marks in names you could indicate the conditionality by
naming the routines ?fitText and ?fitImage , and it would be even
clearer. But these are stylistic decisions and "de gustibus non
disputandum est", after all.
How bad it gets depends on how deeply it is nested. Moreover, there
are other useful decision structures, such as decision tables. One
is not limited to FSM's, of course.
--
Julian V. Noble
Professor Emeritus of Physics
http://galileo.phys.virginia.edu/~jvn/
"For there was never yet philosopher that could endure the
toothache patiently."
-- Wm. Shakespeare, Much Ado about Nothing. Act v. Sc. 1.