• 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: Objective-C default arguments??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C default arguments??


  • Subject: Re: Objective-C default arguments??
  • From: "Alastair J.Houghton" <email@hidden>
  • Date: Sat, 1 Nov 2003 11:32:11 +0000

On Saturday, November 1, 2003, at 07:54 am, Wade Tregaskis wrote:

I'd argue that it's better to only have the one method, and simply make sure your method handles nil arguments appropriately. There are a few reasons for this:

a) It saves coding
b) It keeps your class small and simple
c) It makes users of your class think about all the arguments, rather than jumping for the bare minimum
d) It makes default values for non-objects (e.g. boolean values) explicit to the class user, rather than hiding them
e) It's the only way to handle methods with more than a couple of arguments, at which point trying to handle every possible combination often becomes ridiculous

IMHO it's still sometimes worth having a simplified version of the method that does what the caller is most often going to want, especially if the method is going to be used a lot. (For example, I may have a method that accepts five parameters, but if I call it a lot and 90% of the time use the same final four arguments, then it does make sense to make another method that only accepts a single parameter.)

Also, such methods sometimes permit optimisations... for example, if the method is comparing or searching a string, you could actually have special versions of it rather than calling the routine with complex arguments. If you're doing that, however, you'd have to state it explicitly in the documentation (e.g. "method A is equivalent to calling method B with <these arguments> but isn't necessarily implemented that way... i.e. you need to override both if you intend to customise the behaviour of this class"). Either that, or explicitly check whether you've been subclassed and disable the optimisation if you have.

Kind regards,

Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Detecting login/logout?
  • Next by Date: Re: Detecting login/logout?
  • Previous by thread: Re: Objective-C default arguments??
  • Next by thread: Property list invalid for format
  • Index(es):
    • Date
    • Thread