Re: Since Apple Listens to this List... [Case Statements]
Re: Since Apple Listens to this List... [Case Statements]
- Subject: Re: Since Apple Listens to this List... [Case Statements]
- From: Jim Schram <email@hidden>
- Date: Wed, 13 Feb 2002 01:03:06 -0800
At 7:51 PM +0100 2002/02/12, Emmanuel wrote:
>
Note that "if ... else if ..." is not really equivalent to "case ...",
>
because (at least with C++) execution won't stop on the next "case". You've
>
got to write "break".
>
>
In my experience of C++, the "case" structure generates more errors than
>
"else if", because of that naughty "break" that you always eventually
>
forget to write.
>
>
In fact, if I could, I would suppress the "case" from C++. I owe "case" at
>
least 10 or 20 bugs that would have been avoided with good ol' "if ...
>
else".
It's *very* unfortunate that K&R sort-of got it backwards when designing C... switch statements shouldn't need a break in a case, but rather a continue to handle the rare occasion when you actually *want* one case to fall to the next. For speed, it should evaluate the conditional once, and then scale the result to an index into a jump table (or other optimized jump algorithm). Otherwise you have nothing more than a fancy if-then-else statement, and well, who needs that? AppleScript has enough "pretty syntax" variations as-is(!) In any case (pardon the pun) C style switches are definitely *not* the model to choose for AppleScript, that's for sure. Pascal's quite nice, if a bit limited, but that's just my personal opinion. Anyway...
For those reading this who either "poo-poo" this issue of break-versus-continue behavior in a switch statement as merely one of two equally valid implementations, or that it *should* be the programmer's responsibility to make sure each case breaks correctly, I'd like to remind everyone of an all-important lesson learned the hard way:
It all happened over a decade ago, in 1990, when a software bug in the phone company's switches (caused by the lack of a break in a switch statement) resulted in a chain reaction which propagated outward from its point of origin in New York City until there were no more phone switches running the new version of the software. This pretty much shut down the phone system in the entire region for about nine hours. If the specific conditions which caused the bug to surface hadn't appeared for a few more years (e.g. just long enough for the entire country to upgrade the phone switches' software... but not fix the bug) well, just think of the havoc that would have ensued all across America. Yikes!
Here's a *great* synopsis of this issue by Dennis Burke at California Polytechnic State University:
<
http://www.csc.calpoly.edu/~jdalbey/SWE/Papers/att_collapse.html>
"We don't need no stinking terrorists... we got enough bugs to kill!"
Hmmm... Coincidence? Maybe... I'm not a betting man. ;o)
-- Jim
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.