4 ms·
What about side effects though? Consider this: obj1 = new SomeClass() obj2 = null obj2.do(obj1.doWithSideEffects()) So obj2.do being a no-op should mean
by fauigerzigerk 17y ago
What about side effects though? Consider this:
obj1 = new SomeClass()
obj2 = null
obj2.do(obj1.doWithSideEffects())
So obj2.do being a no-op should mean that obj1.doWithSideEffects is never called. Or should it?
- hboon 17y agoIt's called. The do() isn't.
- masklinn 17y agoIt should. [obj1 doWithSideEffects] will be evaluated before [obj2 do] because Obj-C is eager, so the runtime doesn't know (or care) about obj2 when it considers the evaluation of the inner expression. To get the behavior you want, you need to use blocks (which incidentally were introduced in 10.6) and write something along the lines of: [obj2 do: ^{ [obj1 doWithSideEffects] }] In this case, if obj2 do: doesn't explicitly evaluate the block, obj1 doWithSideEffects won't be evaluated.