Best Practices in Rev development
Devin Asay
devin_asay at byu.edu
Thu Jun 21 14:31:29 EDT 2007
Joe,
> On Jun 21, 2007, at 11:02 AM, Stephen Barncard wrote:
>
>> for me a great advantage of SWITCH is the opportunity for fast and
>> easy multiple if statements done this way instead:
>>
>> SWITCH pKey
>> CASE "B"
>> CASE return
>> CASE "P"
>> printThePage
>> default
>> doDefaultThing
>> END SWITCH
>>
>> easy to read, easy to write.
On Jun 21, 2007, at 12:07 PM, Joe Lewis Wilkins wrote:
> I agree, much cleaner and easier to follow and write, so long as
> you don't forget to exit each of the case statements so as not to
> have subsequent ones executed as well. I believe this is a feature
> in Rev, though I'd prefer if it weren't.
Until this week I might have agreed with you--the concept that a case
statement would automatically match subsequent cases unless you
explicitly add a 'break' command seemed bothersome and obscure. But
then I began making some changes to a scheduling program I am working
on. I wanted to do one thing if the scheduled event fell in the 1st
or 2nd week of the month and something else if it fell in the 3rd or
4th week and something else still if it fell in the 5th week.
I could have said
switch tWeeknum
case 1
doThing1
break
case 2
doThing1
break
case 3
doThing2
break
case 4
doThing2
break
case 5
doThing3
break
end switch
Instead, I was able to use the very quick and readable:
switch tWeeknum
case 1
case 2
doThing1
break
case 3
case 4
doThing2
break
case 5
doThing3
break
end switch
It was the first time I'd found this feature useful, and now I'm
really glad it's there. Suddently the 'break' statements don't seem
so irksome.
Regards,
Devin
Devin Asay
Humanities Technology and Research Support Center
Brigham Young University
More information about the use-livecode
mailing list