Skip navigation.
 
mlRe: ADC Core Data article
FROM : Marcel Weiher
DATE : Thu Apr 07 16:55:51 2005

On 7 Apr 2005, at 14:11, Charlton Wilbur wrote:

>
> On Apr 7, 2005, at 5:59 AM, Marcel Weiher wrote:
>
>

>> Sure does!
>>
>>    result = [employee valueForKey:@"name"];
>> vs.
>>    result = [employee name];
>>
>> The second is:
>>
>> 1.    Expressed directly in the target language (Occam's Razor, 
>> anyone?)
>> 2.    More compact
>> 3.    Easier to read
>> 4.    About an order of magnitude faster ( about 8 times, to be a 
>> bit more precise )
>>
>> An order of magnitude here, an order of magnitude there, and soon 
>> enough you're talking about real performance pigs...
>>

>
> If you wrote everything in C instead of Objective-C, you'd lose all 
> the overhead of method dispatch.


Not really.  In fact, if I wrote this in C, it would look like this:

    objc_msgSend( employee, sel_getUid( "name" ) );

It would be just as fast/slow as using Objective-C message send 
syntax (a bit slower, because the selector has to be looked up).

Do you see the similarity with "valueForKey:"?  In both cases, what 
you actually want to do (send the message "name") is not expressed 
using the original programming language, but as a string argument. 
One of the issues with this approach is that your programming 
language doesn't get to check what you wrote at all, and significant 
amounts of computation have to be shifted to runtime, even for bits 
where everything is known at compile time.

Taking that approach (of embedding strings that carry your semantics) 
to extremes, you end up with:  [employee 
interpret:programInNewProgrammingLanguage].  In fact, KVC *is* a 
language, although a very impoverished one.

>  How much longer does it take to dispatch a method call instead of 
> just calling a function?  If you wrote the whole thing in one long 
> continuous stream of PowerPC assembly, it would be still faster, 
> because you could hand-optimize the assembly and get it to run 
> REALLY quickly!


Hmm...you did notice that performance was only 1 of the 4 points I 
mentioned?  My main point is about expressing intent clearly.

> Of course, this is not a sign that either is better -- programmers 
> get significant benefits from using C instead of assembly, and from 
> using Objective-C instead of C, and from using bindings instead of 
> straight method calls.


While I agree that KVC and bindings can provide benefits, I am not 
convinced that embedding a string-based mini-language is the best way 
to obtain those benefits.  It certainly has significant drawbacks.

> In the case of bindings (as well as in the two examples I gave), 
> bindings are not a pure *replacement* for method calls,


Could you please use "message send"?  Thanks!

> they're an *alternative* to it that makes some things a lot easier 
> at the cost of performance.  They're not meant to be a replacement 
> for routine accessor functions (though you can certainly use them 
> for that!)


Who said "name" was an accessor?  Or a function?  It is a message, 
and objects provide their services via the messages they respond to. 
They are not datastores that provide keyed access to the data 
contained therein.  One of the problems with KVC is that it 
encourages the latter view, with dumb data-bearing objects 
manipulated by external controllers etc.  Good bye object-oriented 
programming!

> but as a way of doing a particular sort of introspection that 
> happens to be very useful for writing generic UI classes.


Well, why not use message-based introspection instead?

> The cases you'd use bindings in are *not* the cases where a simple 
> accessor would be appropriate; they're the cases where using 
> bindings instead of simple accessors allows one to eliminate 10 
> lines of code here, 10 lines of code there.


My response was to "it doesn't get much easier than [valueForKey:/
setValueForKey:]".  I said it does, not that there is *never* a use 
for valueForKey:/setValueForKey:.  Calm down.

Anyway, while I am one of the biggest fans of convenience (and saving 
code) there is, it isn't always a good idea if what we intend to do 
becomes obscured.  See Richard Gabriel's comments on programming as 
compression, and the dangers of compression.


Cheers,

Marcel

Related mailsAuthorDate
mlADC Core Data article mmalcolm crawford Apr 5, 17:33
mlRe: ADC Core Data article Philip Mötteli Apr 5, 23:49
mlRe: ADC Core Data article Guy English Apr 6, 00:29
mlRe: ADC Core Data article Scott Stevenson Apr 6, 01:14
mlRe: ADC Core Data article Dustin Voss Apr 6, 02:18
mlRe: ADC Core Data article James Duncan David… Apr 6, 02:27
mlRe: ADC Core Data article Jake Macmullin Apr 6, 02:31
mlRe: ADC Core Data article John C. Randolph Apr 6, 02:55
mlRe: ADC Core Data article James Duncan David… Apr 6, 03:01
mlRe: ADC Core Data article Ondra Cada Apr 6, 04:04
mlRe: ADC Core Data article Will Mason Apr 6, 04:48
mlRe: ADC Core Data article Rogelio M.Serrano… Apr 6, 06:05
mlRe: ADC Core Data article Rogelio M.Serrano… Apr 6, 06:06
mlRe: ADC Core Data article mmalcolm crawford Apr 6, 07:46
mlRe: ADC Core Data article Paul Szego Apr 6, 08:22
mlRe: ADC Core Data article mmalcolm crawford Apr 6, 09:52
mlRe: ADC Core Data article ?????Andre? Apr 6, 09:55
mlRe: ADC Core Data article Ondra Cada Apr 6, 12:21
mlRe: ADC Core Data article oplus Apr 6, 12:32
mlRe: ADC Core Data article Mont Rothstein Apr 6, 12:36
mlRe: ADC Core Data article Philip Mötteli Apr 6, 14:47
mlRe: ADC Core Data article Scott Stevenson Apr 6, 18:00
mlRe: ADC Core Data article mmalcolm crawford Apr 6, 18:39
mlRe: ADC Core Data article Nat! Apr 6, 22:35
mlRe: ADC Core Data article mmalcolm crawford Apr 6, 23:47
mlRe: ADC Core Data article Timothy Reaves Apr 7, 00:25
mlRe: ADC Core Data article mmalcolm crawford Apr 7, 00:50
mlRe: ADC Core Data article Shawn Erickson Apr 7, 01:05
mlRe: ADC Core Data article James Duncan David… Apr 7, 01:28
mlRe: ADC Core Data article Todd Blanchard Apr 7, 06:37
mlRe: ADC Core Data article Todd Blanchard Apr 7, 06:41
mlRe: ADC Core Data article Scott Stevenson Apr 7, 06:59
mlRe: ADC Core Data article Philip Mötteli Apr 7, 08:32
mlRe: ADC Core Data article Marcel Weiher Apr 7, 11:59
mlRe: ADC Core Data article Charlton Wilbur Apr 7, 15:11
mlRe: ADC Core Data article Mike Ferris Apr 7, 16:53
mlRe: ADC Core Data article Marcel Weiher Apr 7, 16:55
mlRe: ADC Core Data article Marco Scheurer Apr 7, 17:55
mlRe: ADC Core Data article Marcel Weiher Apr 7, 19:13
mlRe: ADC Core Data article Scott Stevenson Apr 7, 19:55
mlRe: ADC Core Data article Marcel Weiher Apr 7, 21:03
mlRe: ADC Core Data article Mike R. Manzano Apr 7, 21:21
mlRe: ADC Core Data article Timothy Reaves Apr 7, 22:03
mlRe: ADC Core Data article Evan DiBiase Apr 7, 22:28
mlconstraint satisfaction (was: ADC Core Data article) Marcel Weiher Apr 7, 22:35
mlRe: ADC Core Data article mmalcolm crawford Apr 7, 23:05
mlRe: Re: ADC Core Data article ttempel Apr 8, 01:50
mlRe: ADC Core Data article Paul Szego Apr 8, 11:50
mlRe: ADC Core Data article Johnny Deadman Apr 8, 14:10
mlRe: ADC Core Data article Philippe Mougin Apr 8, 16:52
mlRe: ADC Core Data article Shawn Erickson Apr 8, 17:07
mlRe: ADC Core Data article Shawn Erickson Apr 8, 17:17
mlRe: ADC Core Data article Ralph Scheuer Apr 8, 17:28
mlRe: ADC Core Data article Ralph Scheuer Apr 8, 17:32
mlRe: ADC Core Data article John Brownlow Apr 8, 17:47
mlRe: ADC Core Data article Charlton Wilbur Apr 8, 18:34
mlRe: ADC Core Data article Scott Stevenson Apr 8, 18:43
mlRe: ADC Core Data article Ralph Scheuer Apr 8, 19:03
mlRe: ADC Core Data article Philippe Mougin Apr 8, 20:37
mlRe: ADC Core Data article Scott Ellsworth Apr 8, 21:46
mlRe: ADC Core Data article Scott Ellsworth Apr 8, 21:48
mlRe: ADC Core Data article Evan DiBiase Apr 8, 22:16
mlRe: ADC Core Data article mmalcolm crawford Apr 8, 22:30
mlRe: ADC Core Data article mmalcolm crawford Apr 8, 23:13
mlRe: ADC Core Data article Marcel Weiher Apr 9, 02:20
mlRe: ADC Core Data article Marcel Weiher Apr 9, 02:46
mlRe: ADC Core Data article Scott Ellsworth Apr 9, 09:39
mlRe: ADC Core Data article Marcel Weiher Apr 9, 09:44
mlRe: ADC Core Data article Byron Ellis Apr 9, 10:37
mlRe: ADC Core Data article Marcel Weiher Apr 9, 14:03
mlRe: ADC Core Data article Charlton Wilbur Apr 9, 16:01
mlRe: ADC Core Data article ?????Andre? Apr 9, 18:08
mlRe: ADC Core Data article Scott Stevenson Apr 9, 18:24
mlRe: ADC Core Data article Scott Stevenson Apr 9, 18:27
mlRe: ADC Core Data article Marcel Weiher Apr 10, 00:06
mlRe: ADC Core Data article Marcel Weiher Apr 10, 00:16
mlRe: ADC Core Data article Marcel Weiher Apr 10, 00:38
mlRe: ADC Core Data article ?????Andre? Apr 10, 01:03
mlRe: ADC Core Data article Charlton Wilbur Apr 10, 01:13
mlRe: ADC Core Data article mmalcolm crawford Apr 10, 01:53
mlRe: ADC Core Data article Scott Stevenson Apr 10, 01:58
mlRe: ADC Core Data article Todd Blanchard Apr 10, 08:32
mlRe: ADC Core Data article mmalcolm crawford Apr 10, 08:52
mlModerator: EOT Re: ADC Core Data article mmalcolm crawford Apr 10, 09:25
mlRe: ADC Core Data article PA Apr 10, 12:08
mlRe: ADC Core Data article mmalcolm crawford Apr 30, 10:18