"send" vs "dispatch"

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

"send" vs "dispatch"

Knapp Martin via use-livecode
A word to the wise (mostly for IDE and extension developers): this will
successfully compile:

   send "test" to button 1 with "ha"

And then if the IDE is swallowing up your error messages (as it does for
extensions like Navigator) it will even deliver the message "test" to
button 1, just without any arguments, and then die silently.

Outside of "rev" stacks, it will deliver the message without arguments and
then throw an error saying there is no handler "with". I just checked, and
amazingly this will work:

on mouseUp
   send "test" to button 1 with "ha"
end mouseUp

on with
   answer "WTH?"
end with

But that's obviously unlikely. Far more likely if you're dealing with
code you wrote before you became aware of "dispatch" (or maybe before
"dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
decide to add an argument to a remote call and don't notice that it's a
"send" rather than a "dispatch", and then spend half an hour trying to
figure out why your arguments aren't passing through <grumble>.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
I've written over 30 000 lines of code in livecode.

used dispatch .... once. :)





On Fri, Oct 5, 2018 at 6:09 PM Geoff Canyon via use-livecode <
[hidden email]> wrote:

> A word to the wise (mostly for IDE and extension developers): this will
> successfully compile:
>
>    send "test" to button 1 with "ha"
>
> And then if the IDE is swallowing up your error messages (as it does for
> extensions like Navigator) it will even deliver the message "test" to
> button 1, just without any arguments, and then die silently.
>
> Outside of "rev" stacks, it will deliver the message without arguments and
> then throw an error saying there is no handler "with". I just checked, and
> amazingly this will work:
>
> on mouseUp
>    send "test" to button 1 with "ha"
> end mouseUp
>
> on with
>    answer "WTH?"
> end with
>
> But that's obviously unlikely. Far more likely if you're dealing with
> code you wrote before you became aware of "dispatch" (or maybe before
> "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
> decide to add an argument to a remote call and don't notice that it's a
> "send" rather than a "dispatch", and then spend half an hour trying to
> figure out why your arguments aren't passing through <grumble>.
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
I’m finding it’s best to do this when you “send” and have a parameter:

send “test ha” to button 1


Peter Bogdanoff
ArtsInteractive

> On Oct 5, 2018, at 3:08 PM, Geoff Canyon via use-livecode <[hidden email]> wrote:
>
> A word to the wise (mostly for IDE and extension developers): this will
> successfully compile:
>
>   send "test" to button 1 with "ha"
>
> And then if the IDE is swallowing up your error messages (as it does for
> extensions like Navigator) it will even deliver the message "test" to
> button 1, just without any arguments, and then die silently.
>
> Outside of "rev" stacks, it will deliver the message without arguments and
> then throw an error saying there is no handler "with". I just checked, and
> amazingly this will work:
>
> on mouseUp
>   send "test" to button 1 with "ha"
> end mouseUp
>
> on with
>   answer "WTH?"
> end with
>
> But that's obviously unlikely. Far more likely if you're dealing with
> code you wrote before you became aware of "dispatch" (or maybe before
> "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
> decide to add an argument to a remote call and don't notice that it's a
> "send" rather than a "dispatch", and then spend half an hour trying to
> figure out why your arguments aren't passing through <grumble>.
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
There is a PR to change this:
https://github.com/livecode/livecode/pull/6479

Will add args to send and call.

Thanks,
Brian
On Oct 5, 2018, 6:09 PM -0400, Geoff Canyon via use-livecode <[hidden email]>, wrote:

> A word to the wise (mostly for IDE and extension developers): this will
> successfully compile:
>
> send "test" to button 1 with "ha"
>
> And then if the IDE is swallowing up your error messages (as it does for
> extensions like Navigator) it will even deliver the message "test" to
> button 1, just without any arguments, and then die silently.
>
> Outside of "rev" stacks, it will deliver the message without arguments and
> then throw an error saying there is no handler "with". I just checked, and
> amazingly this will work:
>
> on mouseUp
> send "test" to button 1 with "ha"
> end mouseUp
>
> on with
> answer "WTH?"
> end with
>
> But that's obviously unlikely. Far more likely if you're dealing with
> code you wrote before you became aware of "dispatch" (or maybe before
> "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
> decide to add an argument to a remote call and don't notice that it's a
> "send" rather than a "dispatch", and then spend half an hour trying to
> figure out why your arguments aren't passing through <grumble>.
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
cooooooooool!!!! That is very useful indeed.

On Fri, Oct 5, 2018 at 6:16 PM Brian Milby via use-livecode <
[hidden email]> wrote:

> There is a PR to change this:
> https://github.com/livecode/livecode/pull/6479
>
> Will add args to send and call.
>
> Thanks,
> Brian
> On Oct 5, 2018, 6:09 PM -0400, Geoff Canyon via use-livecode <
> [hidden email]>, wrote:
> > A word to the wise (mostly for IDE and extension developers): this will
> > successfully compile:
> >
> > send "test" to button 1 with "ha"
> >
> > And then if the IDE is swallowing up your error messages (as it does for
> > extensions like Navigator) it will even deliver the message "test" to
> > button 1, just without any arguments, and then die silently.
> >
> > Outside of "rev" stacks, it will deliver the message without arguments
> and
> > then throw an error saying there is no handler "with". I just checked,
> and
> > amazingly this will work:
> >
> > on mouseUp
> > send "test" to button 1 with "ha"
> > end mouseUp
> >
> > on with
> > answer "WTH?"
> > end with
> >
> > But that's obviously unlikely. Far more likely if you're dealing with
> > code you wrote before you became aware of "dispatch" (or maybe before
> > "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
> > decide to add an argument to a remote call and don't notice that it's a
> > "send" rather than a "dispatch", and then spend half an hour trying to
> > figure out why your arguments aren't passing through <grumble>.
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
On 10/05/2018 03:15 PM, Tom Glod via use-livecode wrote:
> I've written over 30 000 lines of code in livecode.
>
> used dispatch .... once. :)

Dispatch is awesome. The only time I use 'send' any more is when I need
the 'in time' form.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
On 10/05/2018 03:08 PM, Geoff Canyon via use-livecode wrote:

> on with
>     answer "WTH?"
> end with

I find that quite disturbing.
But I quite agree with the answer <g>

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
Ha -- there are about 7,000 lines of code in Navigator -- I think that
means I've written about...70,000 lines of code? :-)

But in any case, there are 80 instances of Dispatch and 63 instances of
Send in Navigator.

My next step I think is to learn more about how Sublime Text handles find
and replace across multiple files, because every instance of Send that
doesn't involve a time delay is going to become a dispatch.

On Fri, Oct 5, 2018 at 3:15 PM Tom Glod via use-livecode <
[hidden email]> wrote:

> I've written over 30 000 lines of code in livecode.
>
> used dispatch .... once. :)
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
If you have multiple parameters, dispatch is easier, cleaner, and safer. So
even if I don't have parameters, unless I need a time delay I use dispatch.
Also, you can use dispatch function to call functions.

gc

On Fri, Oct 5, 2018 at 3:16 PM Peter Bogdanoff via use-livecode <
[hidden email]> wrote:

> I’m finding it’s best to do this when you “send” and have a parameter:
>
> send “test ha” to button 1
>
>
> Peter Bogdanoff
> ArtsInteractive
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
Is there a benefit to adding parameters to send? Or does this just bring it
into parity/redundancy with dispatch?

On Fri, Oct 5, 2018 at 3:16 PM Brian Milby via use-livecode <
[hidden email]> wrote:

> There is a PR to change this:
> https://github.com/livecode/livecode/pull/6479
>
> Will add args to send and call.
>
> Thanks,
> Brian
> On Oct 5, 2018, 6:09 PM -0400, Geoff Canyon via use-livecode <
> [hidden email]>, wrote:
> > A word to the wise (mostly for IDE and extension developers): this will
> > successfully compile:
> >
> > send "test" to button 1 with "ha"
> >
> > And then if the IDE is swallowing up your error messages (as it does for
> > extensions like Navigator) it will even deliver the message "test" to
> > button 1, just without any arguments, and then die silently.
> >
> > Outside of "rev" stacks, it will deliver the message without arguments
> and
> > then throw an error saying there is no handler "with". I just checked,
> and
> > amazingly this will work:
> >
> > on mouseUp
> > send "test" to button 1 with "ha"
> > end mouseUp
> >
> > on with
> > answer "WTH?"
> > end with
> >
> > But that's obviously unlikely. Far more likely if you're dealing with
> > code you wrote before you became aware of "dispatch" (or maybe before
> > "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
> > decide to add an argument to a remote call and don't notice that it's a
> > "send" rather than a "dispatch", and then spend half an hour trying to
> > figure out why your arguments aren't passing through <grumble>.
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
Probably the “in time” variant along with parity.

The PR also opens up sending to widget handlers which is what I’m waiting for.

Thanks,
Brian
On Oct 5, 2018, 9:36 PM -0400, Geoff Canyon via use-livecode <[hidden email]>, wrote:

> Is there a benefit to adding parameters to send? Or does this just bring it
> into parity/redundancy with dispatch?
>
> On Fri, Oct 5, 2018 at 3:16 PM Brian Milby via use-livecode <
> [hidden email]> wrote:
>
> > There is a PR to change this:
> > https://github.com/livecode/livecode/pull/6479
> >
> > Will add args to send and call.
> >
> > Thanks,
> > Brian
> > On Oct 5, 2018, 6:09 PM -0400, Geoff Canyon via use-livecode <
> > [hidden email]>, wrote:
> > > A word to the wise (mostly for IDE and extension developers): this will
> > > successfully compile:
> > >
> > > send "test" to button 1 with "ha"
> > >
> > > And then if the IDE is swallowing up your error messages (as it does for
> > > extensions like Navigator) it will even deliver the message "test" to
> > > button 1, just without any arguments, and then die silently.
> > >
> > > Outside of "rev" stacks, it will deliver the message without arguments
> > and
> > > then throw an error saying there is no handler "with". I just checked,
> > and
> > > amazingly this will work:
> > >
> > > on mouseUp
> > > send "test" to button 1 with "ha"
> > > end mouseUp
> > >
> > > on with
> > > answer "WTH?"
> > > end with
> > >
> > > But that's obviously unlikely. Far more likely if you're dealing with
> > > code you wrote before you became aware of "dispatch" (or maybe before
> > > "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
> > > decide to add an argument to a remote call and don't notice that it's a
> > > "send" rather than a "dispatch", and then spend half an hour trying to
> > > figure out why your arguments aren't passing through <grumble>.
> > > _______________________________________________
> > > use-livecode mailing list
> > > [hidden email]
> > > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > > http://lists.runrev.com/mailman/listinfo/use-livecode
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> >
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
I like the dispatch form, separating parameters out from the command. The reason is given stepping into this code,

send "test ha" to button 1

I cannot point to the variable "ha" and see the value it contains. But if,

dispatch "test" to button 1 with ha

I can. I only use send anymore when I need to send in time, otherwise everything is dispatch. Another nice feature of dispatch is that if the handler does not exist in the target, it will silently and gracefully fail, continuing to execute code after the call. This means I can use dispatch in a behavior, and then have the handler only in the targets that need it, without having to check for the existence of the handler, or wrapping the code in a try catch statement. Send will throw an error if the handler does not exist.

Bob S


> On Oct 5, 2018, at 15:15 , Tom Glod via use-livecode <[hidden email]> wrote:
>
> I've written over 30 000 lines of code in livecode.
>
> used dispatch .... once. :)
>
>
>
>
>
> On Fri, Oct 5, 2018 at 6:09 PM Geoff Canyon via use-livecode <
> [hidden email]> wrote:
>
>> A word to the wise (mostly for IDE and extension developers): this will
>> successfully compile:
>>
>>   send "test" to button 1 with "ha"
>>
>> And then if the IDE is swallowing up your error messages (as it does for
>> extensions like Navigator) it will even deliver the message "test" to
>> button 1, just without any arguments, and then die silently.
>>
>> Outside of "rev" stacks, it will deliver the message without arguments and
>> then throw an error saying there is no handler "with". I just checked, and
>> amazingly this will work:
>>
>> on mouseUp
>>   send "test" to button 1 with "ha"
>> end mouseUp
>>
>> on with
>>   answer "WTH?"
>> end with
>>
>> But that's obviously unlikely. Far more likely if you're dealing with
>> code you wrote before you became aware of "dispatch" (or maybe before
>> "dispatch" was a thing -- I think Navigator predates LC 3.5) is that you
>> decide to add an argument to a remote call and don't notice that it's a
>> "send" rather than a "dispatch", and then spend half an hour trying to
>> figure out why your arguments aren't passing through <grumble>.
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
On 10/08/2018 04:41 PM, Bob Sneidar via use-livecode wrote:

Another nice feature of dispatch is that if the handler does not exist
in the target, it will silently and gracefully fail, continuing to
execute code after the call.

Yeah, that's a double-edged doohickey, though. I *do* use it that way
sometimes as well, but note that if you don't check the result then you
won't know if the dispatch succeeded when you want it to.

Sometimes silently failing is good, sometimes not so much. YMMV.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
ever since I learned that you can pass a whole array using the send command
the dispatch doesn't seem that much more convenient at all..i do alot of in
time commands so this is very convenient to my needs / style

send "mymessage myarray" to this stack

for years I thought using this form 'myarray' is sent as a string, but it
is actually the whole array and all its data) ..no need to concatenate the
variables.




On Mon, Oct 8, 2018 at 8:54 PM Mark Wieder via use-livecode <
[hidden email]> wrote:

> On 10/08/2018 04:41 PM, Bob Sneidar via use-livecode wrote:
>
> Another nice feature of dispatch is that if the handler does not exist
> in the target, it will silently and gracefully fail, continuing to
> execute code after the call.
>
> Yeah, that's a double-edged doohickey, though. I *do* use it that way
> sometimes as well, but note that if you don't check the result then you
> won't know if the dispatch succeeded when you want it to.
>
> Sometimes silently failing is good, sometimes not so much. YMMV.
>
> --
>   Mark Wieder
>   [hidden email]
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
One of the main reasons I implemented send and call with params in the PR that has been mentioned is because it allows for referenced parameters. The following is an error:

on mouseUp
   local tBar
   send “foo tBar” to me
   answer tBar
end mouseUp

on foo @rBar
   put “Howdy" into rBar
end foo

While this works:

on mouseUp
   local tBar
   send “foo” to me with tBar
   answer tBar // answers “Howdy"
end mouseUp

Of course you can’t use referenced params like this using send in time form.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
In reply to this post by Knapp Martin via use-livecode
Yup. I groked that. So I always return empty for success and false if not.

> On Oct 8, 2018, at 17:53 , Mark Wieder via use-livecode <[hidden email]> wrote:
>
> Another nice feature of dispatch is that if the handler does not exist in the target, it will silently and gracefully fail, continuing to execute code after the call.
>
> Yeah, that's a double-edged doohickey, though. I *do* use it that way sometimes as well, but note that if you don't check the result then you won't know if the dispatch succeeded when you want it to.
>
> Sometimes silently failing is good, sometimes not so much. YMMV.
>
> --
> Mark Wieder


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: "send" vs "dispatch"

Knapp Martin via use-livecode
On 10/09/2018 07:33 AM, Bob Sneidar via use-livecode wrote:
> Yup. I groked that. So I always return empty for success and false if not.

Nice.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode