On Feb 1, 2010, at 12:58 PM, Jean-Daniel Dupas wrote:

> 
> Le 1 févr. 2010 à 19:17, Michael Gardner a écrit :
> 
>> On Jan 29, 2010, at 6:44 PM, Chunk 1978 wrote:
>> 
>>> i'm almost 100% sure it's not possible to return a nil on basic data
>>> types, but just incase i'll post the question.
>>> 
>>> ------------------------------------------------------
>>> - (float)panForSoundWithName:(NSString *)soundName
>>>     {
>>>     OpenALSound *sound = [soundDictionary objectForKey:soundName];
>>>     if (!sound) return 0.0f;        
>>>     return sound.pan;
>>>     }
>>> ------------------------------------------------------
>>> 
>>> so above i'd like to write "if (!sound) return nil;".  my reasoning is
>>> because some attributes to a sound object (like pan) are created only
>>> when the sound is initialized.  if there is no sound object than there
>>> should also be no pan value to return.  unfortunately, the float
>>> default 0.0f is also the default value for pan (range from -1.0 to
>>> 1.0).
>> 
>> Another option besides those already mentioned is to use exceptions. Whether 
>> they're appropriate depends on whether calling -panForSoundWithName: on 
>> non-existent sounds is part of your normal control flow, I guess.
>> 
> 
> This solution is not suitable in Cocoa. Exceptions are slow and should be 
> used only when a critical error occurs. They should not be part of the normal 
> flow and should not be used in this kind of situation.

Did you miss the part where I said it depends on whether this is part of the 
program's normal control flow? I don't think we have enough information from 
Chunk's description to make a judgment on this one way or the other.

As to exceptions being slow: assuming that's true, so what? Unless one plans to 
use them in an inner loop, what does it matter? That advice stinks of premature 
optimization.

-Michael_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to