Re: Good idea/bad idea?
Re: Good idea/bad idea?
- Subject: Re: Good idea/bad idea?
- From: Sean McBride <email@hidden>
- Date: Thu, 24 Apr 2014 13:02:10 -0400
- Organization: Rogue Research Inc.
On Thu, 24 Apr 2014 09:44:42 -0700, Jens Alfke said:
>> NSString x;
>> x = (x) ?: @"yo";
>
>It’s not a terrible idea; I use this pattern a lot.
>
>The ternary operator doesn’t just work on integers. It’s like “if”, it
>takes any expression that can be interpreted as a boolean. For a pointer
>the test is implicitly the same as “x != nil”. The example you gave is
>exactly equivalent to
> if (x)
> x = x;
> else
> x = @“yo”;
Exactly equivalent if 'x' is a simple thing like a pointer/integer, as being discussed.
But as discussed here:
<http://en.wikipedia.org/wiki/?:#C>
beware the case of x being an expression and whether it gets evaluated once or more times.
Also, the "a = x ? : y;" form is not C, it is a GNU extension.
Cheers,
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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