Re: ^Block statement considered harmful for callbacks?
Re: ^Block statement considered harmful for callbacks?
- Subject: Re: ^Block statement considered harmful for callbacks?
- From: Oleg Krupnov <email@hidden>
- Date: Thu, 25 Apr 2013 23:05:10 +0300
> I understand the problem you're describing (and yes, I've had a couple of memory leaks resulting from it) but I don't understand how you think it's breaking encapsulation.
The encapsulation is broken by the fact that you can't place whatever code you need in the callback block and have to always remember about internal implementation of blocks, and its possible implications and side effects, even for the simplest cases. It's definitely not something you'd want to focus on, given that blocks were called to make life easier, not harder. Implicit side-effects are always harder to track and debug.
>
> In my code, most of the places I use a block as an onXXX property value it's going to be called exactly once. What I do then is, in the caller, set the corresponding _onXXX ivar to nil after calling through it, to break cycles.
>
I made it clear in the subject that I was talking about callbacks. There are perhaps a number of cases (iterators, threading) where blocks are not copied and seem to be perfectly fine.
_______________________________________________
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