"send" vs "dispatch"

Bob Sneidar bobsneidar at iotecdigital.com
Mon Oct 8 19:41:26 EDT 2018


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 <use-livecode at lists.runrev.com> 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 <
> use-livecode at lists.runrev.com> 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
>> 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
>> 
> _______________________________________________
> 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