Stylistic question.

J. Landman Gay jacque at hyperactivesw.com
Wed Jun 22 15:41:02 EDT 2022


I find that too many behavior stacks make it difficult to keep track of 
where things are. But the primary downside is that script-only stacks don't 
work with remote debugging. That's a big drawback for me since most of my 
apps these days are for mobile. I do use behaviors quite a bit, but I put 
the scripts into buttons so they can be debugged remotely. Or maybe you 
mean you use regular stacks for behaviors? Those would work.

The switch construct is way more flexible than if/then and much cleaner to 
read and track. I use them all the time. They're especially useful when you 
want to group several conditionals. What don't you like about them? Just 
curious.

--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
On June 22, 2022 8:49:51 AM Mike Kerner via use-livecode 
<use-livecode at lists.runrev.com> wrote:

> For an example like a session during LCG, throwing everything into a single
> script can make it easier to see everything, together, however,
> I absolutely, always, without exception, do this:
> 1) Every object that needs to do something gets its own handler, unless
> there is some reason to allow the behavior to pass up the chain. This
> situation is not one of them.
> 2) I don't use scripts, at all, ever. Every handler is in a behavior stack.
> 3) I don't ever use switch. I can't stand it. If I had to write something
> like the above, I would do something like
> put the short name of the target into snot
> if snot is "first" then
>      doCommandFirst
> else if snot is "another"
>      doCommandAnother
> else if snot is "lastnotleast"
>      doCommandLastNotLeast
> else # uh oh
>      answer "ruh roh."
> end if # snot is "first"
>
> this assumes that the names of the handlers I would be calling are not
> named like the ones in the example, because if they were, you could also
> put the short name of the target into snot
> put "doCommand" & snot into toDo
> try
>      do toDo
> catch e
>      answer "ruh roh."
> end try
>
> On Sun, Jun 19, 2022 at 4:33 PM Alex Tweedly via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>
>> I've noticed that in a lot of the example code I've seen recently,
>> there's a bit of a common pattern.
>>
>> In the card script, there will be code like
>>
>> on mouseUp
>>    switch the short name of the target
>>      case "first"
>>          doCommandFirst
>>          break
>>      case "another"
>>          doCommandAnother
>>          break
>>      case "lastnotleast"
>>          doCommandlastnotleast
>>          break
>>    end switch
>> end mouseUp
>>
>> I've seen this in examples from Livecloud, Appli, the WebApp example
>> from Steven/Michael, and a few other places.
>>
>> I would generally have put this code in each button (or other control)
>> directly, and I'm wondering whether there are advantages or preferences
>> for one of those versus the other.
>>
>> Thanks for any opinions,
>>
>> Alex.
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
> --
> On the first day, God created the heavens and the Earth
> On the second day, God created the oceans.
> On the third day, God put the animals on hold for a few hours,
>   and did a little diving.
> And God said, "This is good."
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your 
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode






More information about the use-livecode mailing list