<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Add Meaning To Key Value Strings</title>
	<atom:link href="http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/feed" rel="self" type="application/rss+xml" />
	<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings</link>
	<description>Mac &#38; Technology Writings by Daniel Jalkut</description>
	<lastBuildDate>Wed, 18 Jan 2012 18:10:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Jesper</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-106948</link>
		<dc:creator>Jesper</dc:creator>
		<pubDate>Sat, 02 Jun 2007 22:36:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-106948</guid>
		<description>A bit late to the party, but what&#039;s wrong with this?

#define KVC(X)     [NSString stringWithUTF8String: #X ]

KVC(foo.bar.quux) yields that as an NSString. Replace the stringWithUTF8String: selector with stringWithCString:encoding: and the appropriate encoding at your leisure. It&#039;s a shame you can&#039;t bolt @ and the stringified result together with ## (it bums out), and a shame you can&#039;t define it as @kvc(). Oh well.</description>
		<content:encoded><![CDATA[<p>A bit late to the party, but what&#8217;s wrong with this?</p>
<p>#define KVC(X)     [NSString stringWithUTF8String: #X ]</p>
<p>KVC(foo.bar.quux) yields that as an NSString. Replace the stringWithUTF8String: selector with stringWithCString:encoding: and the appropriate encoding at your leisure. It&#8217;s a shame you can&#8217;t bolt @ and the stringified result together with ## (it bums out), and a shame you can&#8217;t define it as @kvc(). Oh well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mmalc</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-102482</link>
		<dc:creator>mmalc</dc:creator>
		<pubDate>Wed, 23 May 2007 16:01:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-102482</guid>
		<description>The raison d&#039;être of KVC is precisely that it defers decisions until runtime.  The canonical example is perhaps the table view data source -- see http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/Tasks/UsingTableDataSource.html and in particular:

    theValue = [theRecord objectForKey:[aTableColumn identifier]];

Rather than using a dictionary as the model object, you could use KVC to access the properties of any instance:

    theValue = [theRecord valueForKey:[aTableColumn identifier]];

There&#039;s no way for the compiler to determine that the identifier will be a valid key.


Moreover:

Chuck wrote:
* Selectors have no analogue to @”fanController.arrangedObjects.favoriteBand.name”.

Indeed.  Key-value coding includes key *paths*, not just keys.  This offers considerable power, flexibility, and economy.


* I don’t really think KVC is analogous to selectors. There is a fixed, finite set of selectors,

This isn&#039;t really true.  You can create as many selectors as you want at runtime; there is no need for there to be a corresponding implementation (as so many people discover when they misspell a selector name...).


mmalc</description>
		<content:encoded><![CDATA[<p>The raison d&#8217;être of KVC is precisely that it defers decisions until runtime.  The canonical example is perhaps the table view data source &#8212; see <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/Tasks/UsingTableDataSource.html" rel="nofollow">http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/Tasks/UsingTableDataSource.html</a> and in particular:</p>
<p>    theValue = [theRecord objectForKey:[aTableColumn identifier]];</p>
<p>Rather than using a dictionary as the model object, you could use KVC to access the properties of any instance:</p>
<p>    theValue = [theRecord valueForKey:[aTableColumn identifier]];</p>
<p>There&#8217;s no way for the compiler to determine that the identifier will be a valid key.</p>
<p>Moreover:</p>
<p>Chuck wrote:<br />
* Selectors have no analogue to @”fanController.arrangedObjects.favoriteBand.name”.</p>
<p>Indeed.  Key-value coding includes key *paths*, not just keys.  This offers considerable power, flexibility, and economy.</p>
<p>* I don’t really think KVC is analogous to selectors. There is a fixed, finite set of selectors,</p>
<p>This isn&#8217;t really true.  You can create as many selectors as you want at runtime; there is no need for there to be a corresponding implementation (as so many people discover when they misspell a selector name&#8230;).</p>
<p>mmalc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-102468</link>
		<dc:creator>Chuck</dc:creator>
		<pubDate>Wed, 23 May 2007 15:27:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-102468</guid>
		<description>I don&#039;t really think KVC is analogous to selectors. There is a fixed, finite set of selectors, and they are simple. Your program keeps a table of them at all times. The idea of KVC strings, though, is that they are named attributes that might not exist until right before they are used. Selectors have no analogue to @&quot;fanController.arrangedObjects.favoriteBand.name&quot;. I&#039;d say they&#039;re more similar to NSDictionary&#039;s use to pass arbitrary options and attributes to methods.

You could create some NSKey type that is initialized with a string and functionally identical to a string, but I really don&#039;t see how that&#039;s so useful. I mean, in all honesty, have you ever lost track of the meaning of a KVC string in a way that a different but completely equivalent type would help? 

Maybe I&#039;m shortsighted or just not understanding, but it seems to me that this would just lead to slightly more code and make the type system slightly more complicated, neither of which I consider to be a very good thing.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t really think KVC is analogous to selectors. There is a fixed, finite set of selectors, and they are simple. Your program keeps a table of them at all times. The idea of KVC strings, though, is that they are named attributes that might not exist until right before they are used. Selectors have no analogue to @&#8221;fanController.arrangedObjects.favoriteBand.name&#8221;. I&#8217;d say they&#8217;re more similar to NSDictionary&#8217;s use to pass arbitrary options and attributes to methods.</p>
<p>You could create some NSKey type that is initialized with a string and functionally identical to a string, but I really don&#8217;t see how that&#8217;s so useful. I mean, in all honesty, have you ever lost track of the meaning of a KVC string in a way that a different but completely equivalent type would help? </p>
<p>Maybe I&#8217;m shortsighted or just not understanding, but it seems to me that this would just lead to slightly more code and make the type system slightly more complicated, neither of which I consider to be a very good thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mmalc</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-102464</link>
		<dc:creator>mmalc</dc:creator>
		<pubDate>Wed, 23 May 2007 15:15:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-102464</guid>
		<description>Pierre wrote:
* [...] it is very laborious to find/replace relevant instances of a string used as key.
* However, as far as I understood, this is a point that could be addressed in Objective-C 2.0, with the notion of “property”. 

Properties and KVC are orthogonal technologies.

Going by what&#039;s written at http://developer.apple.com/leopard/overview/tools.html, properties provide a means to declare explicitly the semantics of a &quot;member&quot; (I&#039;m avoiding simply rewriting &quot;property&quot; -- strictly it looks like a declared property need not be backed by an ivar), and (if you wish) to synthesise the corresponding accessor methods.

You could therefore use properties independently of KVC, or you could use KVC to access properties.

mmalc</description>
		<content:encoded><![CDATA[<p>Pierre wrote:<br />
* [...] it is very laborious to find/replace relevant instances of a string used as key.<br />
* However, as far as I understood, this is a point that could be addressed in Objective-C 2.0, with the notion of “property”. </p>
<p>Properties and KVC are orthogonal technologies.</p>
<p>Going by what&#8217;s written at <a href="http://developer.apple.com/leopard/overview/tools.html" rel="nofollow">http://developer.apple.com/leopard/overview/tools.html</a>, properties provide a means to declare explicitly the semantics of a &#8220;member&#8221; (I&#8217;m avoiding simply rewriting &#8220;property&#8221; &#8212; strictly it looks like a declared property need not be backed by an ivar), and (if you wish) to synthesise the corresponding accessor methods.</p>
<p>You could therefore use properties independently of KVC, or you could use KVC to access properties.</p>
<p>mmalc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mmalc</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-102458</link>
		<dc:creator>mmalc</dc:creator>
		<pubDate>Wed, 23 May 2007 14:59:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-102458</guid>
		<description>Kenneth Ballenegger wrote:
* the Selector thing wasn’t made up by Apple, wheras KVC was.

This is simply not true.  I don&#039;t remember exactly when KVC first appeared, but I think it was around 1994, perhaps with EOF.

* The selector thing came from Objective-C itself, and its basic framework of classes, when it still had Object as root class instead of the NSObject Apple gave us.

NSObject appeared in Foundation in about 1993...

* When Apple made Cocoa (well, actually when NeXTStep made Cocoa)

... the company &quot;NeXT&quot; developed OPENSTEP...

mmalc</description>
		<content:encoded><![CDATA[<p>Kenneth Ballenegger wrote:<br />
* the Selector thing wasn’t made up by Apple, wheras KVC was.</p>
<p>This is simply not true.  I don&#8217;t remember exactly when KVC first appeared, but I think it was around 1994, perhaps with EOF.</p>
<p>* The selector thing came from Objective-C itself, and its basic framework of classes, when it still had Object as root class instead of the NSObject Apple gave us.</p>
<p>NSObject appeared in Foundation in about 1993&#8230;</p>
<p>* When Apple made Cocoa (well, actually when NeXTStep made Cocoa)</p>
<p>&#8230; the company &#8220;NeXT&#8221; developed OPENSTEP&#8230;</p>
<p>mmalc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Stevenson</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-102309</link>
		<dc:creator>Scott Stevenson</dc:creator>
		<pubDate>Wed, 23 May 2007 08:18:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-102309</guid>
		<description>In the general sense, I see what you&#039;re getting at. In practice, I&#039;m not sure you&#039;d really gain much in the way of productivity by creating a new type. Some things to consider:

1. Conceptually, the way you use KVC is very similar to the way you use a dictionary. I don&#039;t know for sure if that&#039;s a coincidence but I doubt it.

2. There are a number of sitatuation where you&#039;d want to iterate through a list of keys that aren&#039;t literally typed in code. In those situations, the keycode bit falls apart somewhat.

In my opinion, one of the major benefits of Objective-C is the simplicity of the syntax. I don&#039;t know if the advantages justify the additional learning cost for those who are coming to the language for the first time. It strikes me as a bit too cryptic.</description>
		<content:encoded><![CDATA[<p>In the general sense, I see what you&#8217;re getting at. In practice, I&#8217;m not sure you&#8217;d really gain much in the way of productivity by creating a new type. Some things to consider:</p>
<p>1. Conceptually, the way you use KVC is very similar to the way you use a dictionary. I don&#8217;t know for sure if that&#8217;s a coincidence but I doubt it.</p>
<p>2. There are a number of sitatuation where you&#8217;d want to iterate through a list of keys that aren&#8217;t literally typed in code. In those situations, the keycode bit falls apart somewhat.</p>
<p>In my opinion, one of the major benefits of Objective-C is the simplicity of the syntax. I don&#8217;t know if the advantages justify the additional learning cost for those who are coming to the language for the first time. It strikes me as a bit too cryptic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Taybin</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-102201</link>
		<dc:creator>Taybin</dc:creator>
		<pubDate>Wed, 23 May 2007 04:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-102201</guid>
		<description>I think the problem people have with using strings isn&#039;t the &lt;em&gt;string&lt;/em&gt; part, but the runtime binding part.  And runtime binding is a big part of dynamic languages.


As for the lack of compile time checking, well, IMHO, that&#039;s why unit testing is so popular nowadays, as a replacement for static variables.</description>
		<content:encoded><![CDATA[<p>I think the problem people have with using strings isn&#8217;t the <em>string</em> part, but the runtime binding part.  And runtime binding is a big part of dynamic languages.</p>
<p>As for the lack of compile time checking, well, IMHO, that&#8217;s why unit testing is so popular nowadays, as a replacement for static variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul F</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-101980</link>
		<dc:creator>Paul F</dc:creator>
		<pubDate>Tue, 22 May 2007 16:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-101980</guid>
		<description>Hi-

I have a somewhat different opinion of this issue. I like it very much.

I love to be able to make use of this sort of thing in my code. It may stem from my experience as a Python developer where objects are explicitly dictionaries and can be accessed either by string (foo[&quot;x&quot;]) or as a property (foo.x). Being able to select object fields in this way at runtime brings huge expressive power and flexibilty. Look at the way that parameters are specified to Core Image filters for example. It would be much harder to interface with these without KVC.

Admitiedly, there is a cost to this. If you don&#039;t want to use it with your own objects why not just use foo = [myObject foo] and [myObject setFoo: foo] instead. It&#039;s cleaner syntax than something like @keycode() or kMySyntaxForKeySomething, at least in my opinion. The KVC methods call these setters anyway, do they not?

Cheers,
Paul</description>
		<content:encoded><![CDATA[<p>Hi-</p>
<p>I have a somewhat different opinion of this issue. I like it very much.</p>
<p>I love to be able to make use of this sort of thing in my code. It may stem from my experience as a Python developer where objects are explicitly dictionaries and can be accessed either by string (foo["x"]) or as a property (foo.x). Being able to select object fields in this way at runtime brings huge expressive power and flexibilty. Look at the way that parameters are specified to Core Image filters for example. It would be much harder to interface with these without KVC.</p>
<p>Admitiedly, there is a cost to this. If you don&#8217;t want to use it with your own objects why not just use foo = [myObject foo] and [myObject setFoo: foo] instead. It&#8217;s cleaner syntax than something like @keycode() or kMySyntaxForKeySomething, at least in my opinion. The KVC methods call these setters anyway, do they not?</p>
<p>Cheers,<br />
Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kenneth Ballenegger</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-101976</link>
		<dc:creator>Kenneth Ballenegger</dc:creator>
		<pubDate>Tue, 22 May 2007 16:41:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-101976</guid>
		<description>Hmmm, well the Selector thing wasn&#039;t made up by Apple, wheras KVC was. The selector thing came from Objective-C itself, and its basic framework of classes, when it still had Object as root class instead of the NSObject Apple gave us. When Apple made Cocoa (well, actually when NeXTStep made Cocoa) they rewrote the root class to suite their needs and that&#039;s where they added the KVC, but kept the SEL system that was already there.</description>
		<content:encoded><![CDATA[<p>Hmmm, well the Selector thing wasn&#8217;t made up by Apple, wheras KVC was. The selector thing came from Objective-C itself, and its basic framework of classes, when it still had Object as root class instead of the NSObject Apple gave us. When Apple made Cocoa (well, actually when NeXTStep made Cocoa) they rewrote the root class to suite their needs and that&#8217;s where they added the KVC, but kept the SEL system that was already there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre</title>
		<link>http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings/comment-page-1#comment-101967</link>
		<dc:creator>Pierre</dc:creator>
		<pubDate>Tue, 22 May 2007 16:07:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/337/add-meaning-to-key-value-strings#comment-101967</guid>
		<description>Hello,
I agree that string literals in code are a bad idea. The problem for me is refactoring : it is very laborious to find/replace relevant instances of a string used as key.
However, as far as I understood, this is a point that could be addressed in Objective-C 2.0, with the notion of &quot;property&quot;. Or at least, I hope so.

Regards,
Pierre</description>
		<content:encoded><![CDATA[<p>Hello,<br />
I agree that string literals in code are a bad idea. The problem for me is refactoring : it is very laborious to find/replace relevant instances of a string used as key.<br />
However, as far as I understood, this is a point that could be addressed in Objective-C 2.0, with the notion of &#8220;property&#8221;. Or at least, I hope so.</p>
<p>Regards,<br />
Pierre</p>
]]></content:encoded>
	</item>
</channel>
</rss>

