• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting a handler to use a value from a different handler?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting a handler to use a value from a different handler?


  • Subject: Re: Getting a handler to use a value from a different handler?
  • From: Christopher Nebel <email@hidden>
  • Date: Tue, 18 Oct 2005 13:13:25 -0700

On Oct 18, 2005, at 12:33 PM, Michelle Steiner wrote:

Chris, I have a few questions about style, if I may.
On Oct 18, 2005, at 8:20 AM, Christopher Nebel wrote:

on AskTitle()
    set d to display dialog "Title:" default answer ""

Why bother with "set d" if the script doesn't use the variable "d"?

    set answer to text returned of the result
    return answer
end

For that matter, why not this:

return (text returned of (display dialog "Title:" default answer ""))

Oops. As you might have guessed, I originally wrote that function more or less as you finally suggested. However, I decided that since the OP seemed to understand variables but not function return values, it would be better to be a bit more long-winded about it. Unfortunately, I missed part of the transformation, hence the unused "d". It should have read


on AskTitle()
    set d to display dialog "Title:" default answer ""
    set answer to text returned of d
    return answer
end

on ReplaceText(replacement_text)
    (* magic goes here *)
end

on run
    set replacement_string to AskTitle()
    ReplaceText(replacement_string)
end


And why not this:

replaceText (askTitle())

Same reason. The original question was phrased in terms of the "replacement_string" variable, so I kept it around. Besides, he implied that he'd have to call several different functions with the return value of AskTitle(), in which case the variable is clearly necessary.


While some coding style has a real purpose, namely maintainability, some style is just, well, style. It doesn't do to slavishly imitate others' styles without understanding the reasons why it matters (or doesn't); otherwise, you get cargo cult programming.


--Chris Nebel AppleScript and Automator Engineering

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Getting a handler to use a value from a different handler?
      • From: Brett Conlon/HU/Music-AU/SONY <email@hidden>
    • Re: Getting a handler to use a value from a different handler?
      • From: Brett Conlon/HU/AU/SonyDADC <email@hidden>
    • Re: Getting a handler to use a value from a different handler?
      • From: email@hidden
    • Re: Getting a handler to use a value from a different handler?
      • From: "Gary (Lists)" <email@hidden>
References: 
 >Getting a handler to use a value from a different handler? (From: Brett Conlon/HU/Music-AU/SONY <email@hidden>)
 >Re: Getting a handler to use a value from a different handler? (From: Christopher Nebel <email@hidden>)
 >Re: Getting a handler to use a value from a different handler? (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Excel Scripting
  • Next by Date: Re: Excel Scripting
  • Previous by thread: Re: Getting a handler to use a value from a different handler?
  • Next by thread: Re: Getting a handler to use a value from a different handler?
  • Index(es):
    • Date
    • Thread