Re: @try @catch
Re: @try @catch
- Subject: Re: @try @catch
- From: Devon Ferns <email@hidden>
- Date: Thu, 14 Aug 2008 07:53:14 -0400
On 14-Aug-08, at 7:21 AM, Graham Cox wrote:
On 14 Aug 2008, at 8:58 pm, Georg Seifert wrote:
is it recommended to use @try .. @catch blocks as flow control like
it is used in Python. They say explicitly to use it rather than do
a lot of test before just try if it works to look after it only if
it fails.
Hmmm, I'll be looking forward to the replies to this question!
My view is absolutely NOT to use try/catch for flow control. They
were invented to handle exceptional conditions, and that's what they
should be used for. They are not a substitute for proper conditional
clauses and properly structured code. I believe the Python advice
(which I take at face value, not being familiar with Python) is
misguided at best, though may suit that language better. Also, my
understanding is that while a try block is very cheap, the catch
block is not. Since they are only expected to be run once in a blue
moon, that's reasonable, but if they are used routinely, performance
is likely to suffer.
cheers, Graham
Many(probably all now) desktop CPUs are optimized for branch
prediction which would make if blocks more efficient. You can't
always say the same about embedded processors though.
My guess is you probably wouldn't notice much difference on a desktop
between the two without using some profiling to see the actual speed
difference. It'd likely be in the range of hundreds of milliseconds.
I think it's still a horrible way of flow control. I think for some
reason Python must be more optimized for that method of flow control
but since Objective-C is based on C, it's more likely that the basic
if/else if will be more efficient. Message dispatch is not really
that much overhead.
I believe @try, @catch is faster than it used to be though.
Devon.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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