<?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: C# 3.0 Categories Followup</title>
	<atom:link href="http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/</link>
	<description>...so google can index my head.</description>
	<lastBuildDate>Wed, 08 Feb 2012 15:29:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jonathan Leonard</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-189013</link>
		<dc:creator>Jonathan Leonard</dc:creator>
		<pubDate>Tue, 30 Sep 2008 23:35:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-189013</guid>
		<description>Regarding dynamic invocation (or late-time binding):  MS is getting ready to make a friendlier syntax for this than those already mentioned in this thread:

See:
http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx</description>
		<content:encoded><![CDATA[<p>Regarding dynamic invocation (or late-time binding):  MS is getting ready to make a friendlier syntax for this than those already mentioned in this thread:</p>
<p>See:<br />
<a href="http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx" >http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: leeg</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-69081</link>
		<dc:creator>leeg</dc:creator>
		<pubDate>Fri, 09 Feb 2007 09:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-69081</guid>
		<description>@Tim: according to &lt;a href=&quot;http://www.informit.com/articles/article.asp?p=665128&amp;seqNum=3&amp;rl=1&quot; rel=&quot;nofollow&quot;&gt;this article&lt;/a&gt; (a.k.a. I knew about this but am covering my butt), &quot;ObjC 2&quot;[*] has optional methods in protocols.  Now if NSObject were to implement a method &lt;code&gt;-(BOOL)conformsEntirelyToProtocol:(Protocol *)p&lt;/code&gt; then you could eschew the checks at method-call-time by just checking that you could do everything upfront.  Such a method could be added by, um, a category on NSObject ;-).

[*]I dislike that marketecture phrase...wasn&#039;t adding categories, or protocols, or language-level exceptions, a reversion of Objective-C?</description>
		<content:encoded><![CDATA[<p>@Tim: according to <a href="http://www.informit.com/articles/article.asp?p=665128&amp;seqNum=3&amp;rl=1" >this article</a> (a.k.a. I knew about this but am covering my butt), &quot;ObjC 2&quot;[*] has optional methods in protocols.  Now if NSObject were to implement a method <code>-(BOOL)conformsEntirelyToProtocol:(Protocol *)p</code> then you could eschew the checks at method-call-time by just checking that you could do everything upfront.  Such a method could be added by, um, a category on NSObject <img src='http://www.friday.com/bbum/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>[*]I dislike that marketecture phrase&#8230;wasn&#8217;t adding categories, or protocols, or language-level exceptions, a reversion of Objective-C?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Wood</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-66193</link>
		<dc:creator>Tim Wood</dc:creator>
		<pubDate>Sat, 03 Feb 2007 03:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-66193</guid>
		<description>I&#039;ve have to 2nd Mont Rothstein&#039;s comment about fixing bugs in busted frameworks.  This has saved us tons of time, though we&#039;ve gotten to the point that we don&#039;t do this so much with categories anymore but with runtime method replacement (OBReplaceMethod*), possibly with a check for an AppKit/Foundation version number to avoid the replacement in newer OS versions.

Also, I really think categories/extensions in the System namespace are *good*, especially if you get link-time conflict checking.

We frequently define default implementations of functionality on NSObject and then specialize where necessary.  I really dislike code like this:

	if ([object respondsToSelector:@selector(foo)])
		[object foo];
	else {
		... default logic ...
	}

It&#039;s slower, more verbose, more fragile and worst, ugly!  Instead of this, I&#039;ll put the default logic on NSObject, skip the respondsToSelector: and just call -foo straight up.

If someone has a better pattern, I&#039;m open to suggestions, but this has served us well and with link time conflict checking it&#039;d be even better (actually, I have a little command line tool that uses our OmniMachO framework to check for method override conflicts at runtime, but that requires me to actually invoke it... :)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve have to 2nd Mont Rothstein&#8217;s comment about fixing bugs in busted frameworks.  This has saved us tons of time, though we&#8217;ve gotten to the point that we don&#8217;t do this so much with categories anymore but with runtime method replacement (OBReplaceMethod*), possibly with a check for an AppKit/Foundation version number to avoid the replacement in newer OS versions.</p>
<p>Also, I really think categories/extensions in the System namespace are *good*, especially if you get link-time conflict checking.</p>
<p>We frequently define default implementations of functionality on NSObject and then specialize where necessary.  I really dislike code like this:</p>
<p>	if ([object respondsToSelector:@selector(foo)])<br />
		[object foo];<br />
	else {<br />
		&#8230; default logic &#8230;<br />
	}</p>
<p>It&#8217;s slower, more verbose, more fragile and worst, ugly!  Instead of this, I&#8217;ll put the default logic on NSObject, skip the respondsToSelector: and just call -foo straight up.</p>
<p>If someone has a better pattern, I&#8217;m open to suggestions, but this has served us well and with link time conflict checking it&#8217;d be even better (actually, I have a little command line tool that uses our OmniMachO framework to check for method override conflicts at runtime, but that requires me to actually invoke it&#8230; <img src='http://www.friday.com/bbum/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay Tuley</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-66116</link>
		<dc:creator>Jay Tuley</dc:creator>
		<pubDate>Sat, 03 Feb 2007 00:56:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-66116</guid>
		<description>&lt;blockquote&gt;
What happens with dynamically loaded code? 
&lt;/blockquote&gt;

The extension method is definitely getting resolved at compile time, it&#039;s not going to make a difference with dynamically loading code adding new extension methods (Unless maybe if you have the same method extension in two different assemblies with the same namespace like System in static classes with the same names :-P, which would cause a runtime error on load because of the class with the same name and namespace)

&lt;blockquote&gt;
OK — more basic question that demonstrates my ignorance — what dynamic loading features does C# even support? 
&lt;/blockquote&gt;

Libraries, modules, and you can emit new classes programatically too.

&lt;blockquote&gt;
Hell, what level of support does C# have for dynamic resolution and/or binding of methods?
&lt;/blockquote&gt;

Most of the time you are not dynamically resolving methods, there is some runtime resolving for methods obviously for virtual methods and protocols (err... interfaces) only what you would need for polymorphism. Also while it&#039;s not a language feature, .net does have the ability to dynamically query methods via the reflection api and then invoke them, it&#039;s big and ugly, but it does allow one to write classes that use dynamic bindings. The api query can be much more explicit than cocoa&#039;s, but of course there&#039;s a lot more meta data in c# than objective-c to query by too. 

C# is statically and strongly typed, but they do make it possible to do things you expect in dynamic languages, they can even do distributed objects with proxies, the only catch is that you have to have  a protocol (err...interface) for that object, but you just feed it to an api and it&#039;s emits a proxy class that inherits the protocol on the fly and it will talk on the other end to an object that invokes methods dynamically by reflection off your remote object.</description>
		<content:encoded><![CDATA[<blockquote><p>
What happens with dynamically loaded code?
</p></blockquote>
<p>The extension method is definitely getting resolved at compile time, it&#8217;s not going to make a difference with dynamically loading code adding new extension methods (Unless maybe if you have the same method extension in two different assemblies with the same namespace like System in static classes with the same names <img src='http://www.friday.com/bbum/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> , which would cause a runtime error on load because of the class with the same name and namespace)</p>
<blockquote><p>
OK — more basic question that demonstrates my ignorance — what dynamic loading features does C# even support?
</p></blockquote>
<p>Libraries, modules, and you can emit new classes programatically too.</p>
<blockquote><p>
Hell, what level of support does C# have for dynamic resolution and/or binding of methods?
</p></blockquote>
<p>Most of the time you are not dynamically resolving methods, there is some runtime resolving for methods obviously for virtual methods and protocols (err&#8230; interfaces) only what you would need for polymorphism. Also while it&#8217;s not a language feature, .net does have the ability to dynamically query methods via the reflection api and then invoke them, it&#8217;s big and ugly, but it does allow one to write classes that use dynamic bindings. The api query can be much more explicit than cocoa&#8217;s, but of course there&#8217;s a lot more meta data in c# than objective-c to query by too. </p>
<p>C# is statically and strongly typed, but they do make it possible to do things you expect in dynamic languages, they can even do distributed objects with proxies, the only catch is that you have to have  a protocol (err&#8230;interface) for that object, but you just feed it to an api and it&#8217;s emits a proxy class that inherits the protocol on the fly and it will talk on the other end to an object that invokes methods dynamically by reflection off your remote object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay Tuley</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-65947</link>
		<dc:creator>Jay Tuley</dc:creator>
		<pubDate>Fri, 02 Feb 2007 20:39:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-65947</guid>
		<description>OMG, Duh, Ben you are so right. C# 3.0 uses the .net 2.0 runtime, there are no runtime changes, this is all done at compile time, which would negate any problems with dynamically loaded code changing what methods run after the compiling. The spec was worded that this was done during the &quot;processing of the invocation&quot; however reading again more closely it meant &quot;processing of the invocation [syntax]&quot;.</description>
		<content:encoded><![CDATA[<p>OMG, Duh, Ben you are so right. C# 3.0 uses the .net 2.0 runtime, there are no runtime changes, this is all done at compile time, which would negate any problems with dynamically loaded code changing what methods run after the compiling. The spec was worded that this was done during the &#8220;processing of the invocation&#8221; however reading again more closely it meant &#8220;processing of the invocation [syntax]&#8220;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mont Rothstein</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-65945</link>
		<dc:creator>Mont Rothstein</dc:creator>
		<pubDate>Fri, 02 Feb 2007 20:39:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-65945</guid>
		<description>OK, I can&#039;t take it anymore.  You keep harshing on the ability for categories to override existing methods.

I agree that this can cause problems (obviously) but the power to fix bugs in frameworks provided by someone else (cough apple cough) should not be trivialized.  The amount time time I have saved because I could fix a bug by using categories is significantly greater than the time I have spent hunting down category related bugs.

That said, it would be nice if you had to explicitly say when you wanted to override an existing method.  You could prefix the method with something like override_stupid_borken_method_so_things_work_like_they_should, or even just override.  Without the keyword it would go boom, or simply not load the category.

C# has an override keyword, unfortunately the original method has to be declared virtual which is not the default and therefore doesn&#039;t get used much.

On a different note I find it sad that it took LINQ to get MS to see the use of categories, and then only begrudgingly.

-Mont</description>
		<content:encoded><![CDATA[<p>OK, I can&#8217;t take it anymore.  You keep harshing on the ability for categories to override existing methods.</p>
<p>I agree that this can cause problems (obviously) but the power to fix bugs in frameworks provided by someone else (cough apple cough) should not be trivialized.  The amount time time I have saved because I could fix a bug by using categories is significantly greater than the time I have spent hunting down category related bugs.</p>
<p>That said, it would be nice if you had to explicitly say when you wanted to override an existing method.  You could prefix the method with something like override_stupid_borken_method_so_things_work_like_they_should, or even just override.  Without the keyword it would go boom, or simply not load the category.</p>
<p>C# has an override keyword, unfortunately the original method has to be declared virtual which is not the default and therefore doesn&#8217;t get used much.</p>
<p>On a different note I find it sad that it took LINQ to get MS to see the use of categories, and then only begrudgingly.</p>
<p>-Mont</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Lings</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-65926</link>
		<dc:creator>Ben Lings</dc:creator>
		<pubDate>Fri, 02 Feb 2007 19:27:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-65926</guid>
		<description>My impression (and this is only from reading the descriptions in various places on the web—I haven&#039;t compiled anything and then looked at the IL to verify it) is that the extension methods are resolved only at compile-time.  They are also resolved based only on the declared type of the variable.

Using your example:

&lt;code&gt;
object obj = new object();
obj.MagicDoStuff();
&lt;/code&gt;

gets compiled to

&lt;code&gt;
object obj = new object();
MagicDoStuff(obj);
&lt;/code&gt;

It&#039;s syntactic sugar which I guess was put in mainly to support LINQ.  Without it, the syntax for LINQ would be horrible. (Given that all the System.Query methods couldn&#039;t be added to the IEnumerable&lt;T&gt; interface without some serious breakage...)</description>
		<content:encoded><![CDATA[<p>My impression (and this is only from reading the descriptions in various places on the web—I haven&#8217;t compiled anything and then looked at the IL to verify it) is that the extension methods are resolved only at compile-time.  They are also resolved based only on the declared type of the variable.</p>
<p>Using your example:</p>
<p><code><br />
object obj = new object();<br />
obj.MagicDoStuff();<br />
</code></p>
<p>gets compiled to</p>
<p><code><br />
object obj = new object();<br />
MagicDoStuff(obj);<br />
</code></p>
<p>It&#8217;s syntactic sugar which I guess was put in mainly to support LINQ.  Without it, the syntax for LINQ would be horrible. (Given that all the System.Query methods couldn&#8217;t be added to the IEnumerable&lt;T&gt; interface without some serious breakage&#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-65836</link>
		<dc:creator>Jim</dc:creator>
		<pubDate>Fri, 02 Feb 2007 13:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-65836</guid>
		<description>Does the current documentation offer any particular advice about the use/abuse of categories on system provided classes?</description>
		<content:encoded><![CDATA[<p>Does the current documentation offer any particular advice about the use/abuse of categories on system provided classes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bbum&#8217;s weblog-o-mat &#187; Blog Archive &#187; C# 3.0: Now with Categories!</title>
		<link>http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/comment-page-1/#comment-65731</link>
		<dc:creator>bbum&#8217;s weblog-o-mat &#187; Blog Archive &#187; C# 3.0: Now with Categories!</dc:creator>
		<pubDate>Fri, 02 Feb 2007 06:38:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/2007/02/02/c-30-categories-followup/#comment-65731</guid>
		<description>[...] Update: Go read this followup that specifically responds and expands upon the comments left on this post. [...]</description>
		<content:encoded><![CDATA[<p>[...] Update: Go read this followup that specifically responds and expands upon the comments left on this post. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

