Skip navigation.
 
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?)
FROM : Jens Alfke
DATE : Sat May 10 20:40:54 2008

On 9 May '08, at 7:41 PM, Chris Hanson wrote:

> (6) Leverage Cocoa framework features in your own code.  For 
> example, you don't need to have setter methods that invoke -
> setDirty:.  You can just write a method like this
>    - (NSSet *)keyPathsForValuesAffectingDirty {
>        return [NSSet setWithObject:@"UUID"];
>    }
> and then anything that cares about whether a particular object is 
> dirty can observe its "dirty" property.


But you still need to implement the "dirty" property, with a getter 
that returns the corresponding ivar; and the other setters like -
setUUID: need to set the ivar to true.

So what you're describing comes down to just (a) removing -setDirty:, 
and (b) replacing the internal calls to it with "dirty=YES". Is this 
any simpler or cleaner? It's the same number of lines of code, and now 
if you add a new property to the class you have to remember to add its 
name to the set in keyPathsForValuesAffectingDirty. Plus, I'll bet the 
internal general-purpose dependency tracking is less efficient than 
the hardcoded call to -setDirty.

In addition,

* keyPathsForValuesAffectingDirty should be a class method, not an 
instance one

* You didn't point out that this only works on 10.5. On 10.4 it will 
compile without warnings but will be ignored at runtime, causing hard-
to-debug wrong behavior when your property dependencies fail to work.

—Jens

Related mailsAuthorDate
mlDid I reinvent the wheel? Western Botanicals May 9, 20:10
mlRe: Did I reinvent the wheel? Jens Alfke May 9, 21:42
mlRe: Did I reinvent the wheel? Sherm Pendley May 9, 21:58
mlRe: Did I reinvent the wheel? Western Botanicals May 9, 22:34
mlRe: Did I reinvent the wheel? Stéphane Sudre May 10, 00:14
mlCocoa coding style (was Re: Did I reinvent the wheel?) Chris Hanson May 10, 04:41
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) I. Savant May 10, 05:25
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Michael Watson May 10, 05:32
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Andrew Merenbach May 10, 05:47
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Michael Watson May 10, 06:49
mlRe: Did I reinvent the wheel? Kyle Sluder May 10, 07:27
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Chris Hanson May 10, 07:43
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Clark Cox May 10, 09:30
mlRe: Did I reinvent the wheel? Uli Kusterer May 10, 11:19
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Jens Alfke May 10, 20:40
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Chris Hanson May 11, 03:53
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Jim Correia May 11, 04:14
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Western Botanicals May 11, 04:29
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Michael Ash May 11, 05:12
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Adam R. Maxwell May 11, 05:42
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Ilan Volow May 11, 06:19
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Jens Alfke May 11, 06:41
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Jens Alfke May 11, 06:47
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Ilan Volow May 11, 07:19
mlRe: Cocoa coding style (was Re: Did I reinvent the wheel?) Scott Ribe May 14, 02:56
mlRe: Did I reinvent the wheel? Colin Cornaby Jul 21, 22:12