Stylistic question.

Mike Kerner MikeKerner at roadrunner.com
Wed Jun 22 09:46:54 EDT 2022


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."


More information about the use-livecode mailing list