On 20/06/2022 00:19, Bob Sneidar via use-livecode wrote:
Well code shared commonly between multiple objects should generally be in an
object shared by those objects. That can be the card, stack, behavior or
front/back script. The script of a group as well.
Absolutely. And the converse - code that is not shared should be as low
in the hierarchy as possible.
In this case, there is really no shared code.
If it's button "first" you call one handler. If it's button "whatever I
called the second", you call a different handler. etc. Nothing shared
at all.
As to Brian's point about behaviours and Git, I can see that. I admit to
being slightly "slack" about what code needs to go into behaviour
scripts so it can be Gitted. If it's code that is very brief, and will
"never" change, I put that in the regular stack. So in this case, I'd
have the script of button "first" be
on mouseUp
doCommandFirst
end mouseUp
and I'm willing to bet that will ever change :-)
For example I have a behavior for all my datagrids. Each datagrid has a
property called gridconstants which is an array of all the things specific to
each datagrid. The behavior handlers will get this property so that I can use
generic terms in the behavior like cTableName and cPriKey etc. Now my behavior
handlers like selectionChanged and such become universal to all my datagrids.
Only one place to edit the handlers now.
Sounds cool. If I ever use a Datagrid, I'll do that.
Alex.
If I need to do anything specific with a datagrid, I keep those handlers in
each datagrid script.
Sent from my iPhone
On Jun 19, 2022, at 14:09, Brian Milby via use-livecode
<use-livecode@lists.runrev.com> wrote:
One reason would be if you were trying to use behaviors so you could manage
your code with a repository like Git. This would greatly reduce the number of
behavior scripts that you would create. One app that work on has the code in
the stack’s behavior script.
Sent from my iPhone
On Jun 19, 2022, at 4:33 PM, Alex Tweedly via use-livecode
<use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode