• 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: Good idea/bad idea?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good idea/bad idea?


  • Subject: Re: Good idea/bad idea?
  • From: Andy Lee <email@hidden>
  • Date: Thu, 24 Apr 2014 11:39:30 -0400

On Apr 24, 2014, at 11:14 AM, Alex Zavatone <email@hidden> wrote:

>
> On Apr 24, 2014, at 11:12 AM, Luther Baker wrote:
>
>> Not native and I've no idea when or if this is a good idea ... nor am I sure how much typing you want to do ... but you _could_ create a class convenience method for this
>>
>>   x = [Thing defaultIfNil:x];
>>
>> With shorter or longer names as you see fit ... down to possibly:
>>
>>   x = [Thing :x]
>>
>> I've really no idea if that syntax would work but it stands out and might be easy to use and identify in the code!
>>
>> -Luther
>
> Heey, that's awesome.
>
> The efficiency monger (aka lazy programmer) who posed me the question in the first place will like that.

It's even lazier :) *and* more efficient (in the CPU sense) to use the binary ?:, aka the "otherwise" operator:

<https://jeremywsherman.com/blog/2013/01/21/the-otherwise-operator/>

On a side note, although ":" is legal as a component of a method name -- you could have a method called ":::::" if you wanted -- I would strongly recommend against using it.  The purpose of Objective-C's distinctive method syntax is so that you can describe each argument with a bit of wording that is right next to the argument.

Apple has a few API methods with naked colons, e.g. functionWithControlPoints::::.  IMO that was a mistake.

--Andy

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Good idea/bad idea? (From: Alex Zavatone <email@hidden>)
 >Re: Good idea/bad idea? (From: Luther Baker <email@hidden>)
 >Re: Good idea/bad idea? (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Good idea/bad idea?
  • Next by Date: Re: Good idea/bad idea?
  • Previous by thread: Re: Good idea/bad idea?
  • Next by thread: Re: Good idea/bad idea?
  • Index(es):
    • Date
    • Thread