Re: Case Statements
Re: Case Statements
- Subject: Re: Case Statements
- From: Brennan <email@hidden>
- Date: Wed, 13 Feb 2002 21:36:42 +0100
Jim Schram <email@hidden> wrote
>
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.
Hear hear! Strong agreement! Bleat bleat!
C's 'switch..case' is horrible. It's absolutely not what we want in Applescript.
BTW, given that Director's lingo shares the same syntactical roots as Applescript (i.e. hypertalk) it might interest people to see how it's done there;
case x of
1 : dothis -- all on one line
2 : dothis
doThat
andThenDoThis -- multiple lines
3 :
doSomething
dosomethingDifferent -- multiple lines, but a bit tidier
otherwise : -- this particular colon is optional, as is the otherwise clause itself
doSomethingDefault
end case
Notice that this is closer to Pascal than C (thank goodness), and it is not a cascade. There's no 'continue' either, even though that would be useful on occasion. Lingo's 'case' compiles to the exact same bytecode as an equivalent 'else if', so there's no performance advantage. Why have it then? Well, it really is 'tidier'. I like tidy code.
Interestingly, you can even use arbitrary booleans as long as you enclose the cases in parentheses:
case TRUE of
(a and b) : doThis
((x = y) or someBooleanVariable) : doThat
(z > 5 and z < 10) : dosomethingDifferent
end case
... although the maintenance advantages over 'else if' start to break down here. It's still much easier to read though. This kind of syntax would be extremely useful if it *were* a cascade.
I still vote for the filter reference form ('whose') in lists as a far higher priority though.
Brennan
_______________________________________________
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.