Re: ADC Core Data article (was: Re: Cocoa-dev Digest, Vol 2, Issue 490)
Re: ADC Core Data article (was: Re: Cocoa-dev Digest, Vol 2, Issue 490)
- Subject: Re: ADC Core Data article (was: Re: Cocoa-dev Digest, Vol 2, Issue 490)
- From: Scott Ellsworth <email@hidden>
- Date: Sat, 9 Apr 2005 00:33:21 -0700
On Apr 8, 2005, at 4:25 PM, Jack wrote:
If foo has no "blob" accessor, then [foo blob] throws a warning at
compile time, while [foo valueForKey:@"blob"] does not, instead
erroring at runtime.
I don't really understand what all the complaining is about. What
is the
problem with runtime?
An error caught at compile time is one that cannot escape to runtime,
regardless of how thorough your testing is.
This is what "(id)valueForUndefinedKey:(NSString
*)key" is all about. You can print out an error and the key letting
you know
exactly where the problem is and return NIL, it's good practice to
check for
NIL and act appropriately. You can even tell the bindings what to
do with NIL
Fair enough. I have not been providing implementations of
valueForUndefinedKey for most of my classes thus far; perhaps I shall
start. This stops the program from halting, though, but does not
prevent a bug from escaping into the wild.
One good thorough run of your program will quickly show any errors as
well. I don't know about you but I run and test every
implementation of
something right after I code it, so it doesn't even involve an
extra step
for me.
While I do test code code, and usually step through complicated code
with a debugger before considering it done, i worry about bitrot. I
may have had one set of assumptions in my head when I coded up
something, then changed those assumptions without noticing code that
depended on them. Strict type checking will catch many classes of
such errors as soon as I make such a mistake. Letting it slip to
runtime means that I have to test areas of code whose relationship is
not obvious.
Clearly, unit testing and the like do help, but if there is an error
that I can catch without even needing to run a test, that is a win to
me.
Balance is needed, of course. I have one bit of code where both a
Sector and Subsector have a name method. In java, I would need them
both to implement the "Named" interface to call getName reliably,
while in ObjC, I can define a protocol if I like, or just send the
name message, or kvc @"name" and have it work. Which makes sense
depends on the statement I am making.
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden