<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx</link><description>I have been working with the C# and VB teams on design guidelines for LINQ. We started to talk about the so called Query Pattern , which describes what you need to do if you want a custom type to support the new query operators (select, where, group by,</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3941982</link><pubDate>Wed, 18 Jul 2007 22:43:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3941982</guid><dc:creator>Tom Kirby-Green</dc:creator><description>&lt;p&gt;I am super interested in these LINQ design patterns. Is there any chance you can publish them as a work-in-progress document to the community? I'm sure I can't be alone in wanting to read these - and am more than prepaired to be flexable and accept they're like to mutate a lot in the short term! :-)&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3942972</link><pubDate>Wed, 18 Jul 2007 23:30:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3942972</guid><dc:creator>mharder</dc:creator><description>&lt;p&gt;What's the need for supporting duck typing at all? &amp;nbsp;Why isn't static typing sufficient?&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3943114</link><pubDate>Wed, 18 Jul 2007 23:39:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3943114</guid><dc:creator>tomasp</dc:creator><description>&lt;p&gt;You might want to look at Haskell type classes (&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Type_class"&gt;http://en.wikipedia.org/wiki/Type_class&lt;/a&gt;). As far as I understand it, they are used to solve this kind of problems, but I'm not sure if it helps with finding good way for writing &amp;quot;easy to parse description&amp;quot;.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3943499</link><pubDate>Wed, 18 Jul 2007 23:55:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3943499</guid><dc:creator>kcwalina</dc:creator><description>&lt;p&gt;Tom, yes, I would be more than willing to publish something that is not formally reviewed/approved yet, but we don't even have that. We are still in the stage of exploring what we want to have in the guidelines. For example, we do know that extension methods can be abused and we willo have some guidelines recommending where the boundary between good and bad usage of the extension methods is, but we don't yet know how to describe the boundary.&lt;/p&gt;
&lt;p&gt;We need duck typing cause static types are not expressive enough in some cases. For example, there is no way to say that a parameter can be either an Expression or a delegate.&lt;/p&gt;
&lt;p&gt;Tomas, thanks for the pointer to Haskell. I will take a look.&lt;/p&gt;
</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3944355</link><pubDate>Thu, 19 Jul 2007 01:22:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3944355</guid><dc:creator>Orion Edwards</dc:creator><description>&lt;p&gt;Here's an idea for C# 4 or 3.5 or whatever which would solve this problem, and make millions of developers the world over jump for joy. I'd hazard a guess and say it wouldn't be too hard with the type inferencing stuff that's already there:&lt;/p&gt;
&lt;p&gt;Define an alternative to an interface called 'requirement'&lt;/p&gt;
&lt;p&gt;It would work and behave exactly the same as an interface EXCEPT that it would use duck typing instead of static typing: For example:&lt;/p&gt;
&lt;p&gt;public requirement Closeable {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; void Close();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public void TestMethod( Closeable c ) {&lt;/p&gt;
&lt;p&gt; c.Close();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;TestMethod( new System.Windows.Forms.Form() );&lt;/p&gt;
&lt;p&gt;A windows form has a public void Close() method so this should work. The typechecking is still just as good and can be done entirely by the compiler so there should be no speed or safety hit. 'requirement' may not be the best word, but the world would rejoice if C# had this&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3944438</link><pubDate>Thu, 19 Jul 2007 01:28:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3944438</guid><dc:creator>Daniel Slaney</dc:creator><description>&lt;p&gt;It looks like you want structural subtyping instead of nominal subtyping. Also what's the scope of the [ItemType] mentioned in the [Enumerator] example? Is it assumed to be defined elsewhere?&lt;/p&gt;
&lt;p&gt;OCaml has row polymorphism on objects and concepts in the latest C++ draft are all related to this kind of thing. The template constraints idiom in C++ might be a good place to look for ideas as well.&lt;/p&gt;
&lt;p&gt;The Expression or delegate example could be handled with sum types if you're willing to take the type tag over head.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3944746</link><pubDate>Thu, 19 Jul 2007 02:16:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3944746</guid><dc:creator>rryan</dc:creator><description>&lt;p&gt;mharder : &lt;/p&gt;
&lt;p&gt; &amp;nbsp; Duck typing is used to allow objects that do not implement IEnumerable to be used with foreach. If it walks like a duck (implements GetEnumerator), then it is a duck!&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3946197</link><pubDate>Thu, 19 Jul 2007 04:17:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3946197</guid><dc:creator>Simon Buchan</dc:creator><description>&lt;p&gt;kcwalina: Couldn't overloading handle the Expression/delegate case?&lt;/p&gt;
&lt;p&gt;rryan: or at least a good decoy :)&lt;/p&gt;
&lt;p&gt;Duck typing makes the OO purist in me squirm, Just because it has the same signature, its ok to call the methods, even though the semantics might be completely different?&lt;/p&gt;
&lt;p&gt;There's an example in &amp;quot;The C++ Programming Language&amp;quot; that is very approximately:&lt;/p&gt;
&lt;p&gt;class Sprite { void draw(int x, int y) {...} ... };&lt;/p&gt;
&lt;p&gt;class Cowboy { void draw(int speed, int accuracy) {...} ... };&lt;/p&gt;
&lt;p&gt;Of course, the template stuff in C++ uses this all the time, so it can't be all bad :). As far as I am aware, the only way to specify duck typing is to give a code snippet that uses the type in every way you want to require, at least in as screwed up a language as C++ (Just try listing all the ways to implement 'a &amp;lt; b') - This is how the concepts stuff in C++0x looks to be going.&lt;/p&gt;
&lt;p&gt;Haskell's type classes are awesome, but totally incompatible with regular OO.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3951357</link><pubDate>Thu, 19 Jul 2007 10:58:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3951357</guid><dc:creator>Daniel Fortunov</dc:creator><description>&lt;p&gt;Just out of interest, I can see that the added flexibility of duck typing might be necessary for the query operators, but what does it buy you in the case of foreach?&lt;/p&gt;
&lt;p&gt;IEnumerable and IEnumerator are trivial interfaces and it's surely more readable if you implement those interfaces, rather than just having a floating GetEnumerator() method on your object?&lt;/p&gt;
&lt;p&gt;What is the usecase for ducktyping on foreach?&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3956729</link><pubDate>Thu, 19 Jul 2007 18:17:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3956729</guid><dc:creator>sdether</dc:creator><description>&lt;p&gt;I'll grant that interfaces are not always expressive enough, but I am confused why foreach doesn't just require IEnumerable? I mean the pattern is quite specific, where you are not likely to run into an object that has these members but doesn't implement IEnumerable and if you are creating your own type, implementing IEnumerable doesn't seem like an onerous requirement.&lt;/p&gt;
&lt;p&gt;But I could see the benefit of being able to do something like Orion suggested. Maybe it could be something similar to extension methods, i.e. the ability to decorate some object with an Interface. This way if you have several objects that have similar use patterns but no common interface, you could create one and decorate the classes with that interface. You could already achieve something similar with Attributes, but that does move the checking to runtime.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3960792</link><pubDate>Thu, 19 Jul 2007 21:38:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3960792</guid><dc:creator>Keith J. Farmer</dc:creator><description>&lt;p&gt;mharder: &amp;nbsp;The point that people are making is that sometimes a type -- for whatever reason -- doesn't implement an interface. &amp;nbsp;Perhaps it has all the methods but doesn't declare itself (eg, it's an older type that predates an interface), or it only partially implements an interface (eg, the interface may encompass too much).&lt;/p&gt;
&lt;p&gt;It also makes it easier when you're crossing service boundaries. &amp;nbsp;You (the client) can specify some interfaces that partition fields into interesting bits. &amp;nbsp;IId { string Id { get; set; }}, for example, and get access to things without having to explicity reflect over the type.&lt;/p&gt;
&lt;p&gt;That reflection is already commonly used for this sort of thing is a strong motivation, for me at least, to push for duck typing.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3960935</link><pubDate>Thu, 19 Jul 2007 21:48:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3960935</guid><dc:creator>Keith J. Farmer</dc:creator><description>&lt;p&gt;Krzysztof:&lt;/p&gt;
&lt;p&gt;I like the idea.. a lot. &amp;nbsp;In C#'s case I wouldn't use square brackets, because of the ambiguity that would cause with attributes. &amp;nbsp;I'd suggest parentheses instead (which has conceptual baggage in the casting department, itself related to the idea of duck typing).&lt;/p&gt;
&lt;p&gt;After all, maybe we'd like to extend attributes to other parts of the syntax at some point.&lt;/p&gt;
&lt;p&gt;Would this be limited to public APIs (like interfaces are today)?&lt;/p&gt;
&lt;p&gt;Also, your [ItemType] .. why not just use generics there?&lt;/p&gt;
&lt;p&gt;(Foreachable&amp;lt;T&amp;gt;) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public (Enumerator&amp;lt;T&amp;gt;) GetEnumerator();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;(Enumerator&amp;lt;T&amp;gt;) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public bool MoveMext();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public T Current { get; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Orion's idea also has strong merits, and could be easier on the syntax. &amp;nbsp;But in the end, this is all dependant on the language it's being fit into.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3963487</link><pubDate>Fri, 20 Jul 2007 01:33:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3963487</guid><dc:creator>Pete</dc:creator><description>&lt;p&gt;Hi Krzysztof,&lt;/p&gt;
&lt;p&gt;Thank goodness you're getting involved with design guidelines for language-integrated query. There's a lot of work to be done in this area.&lt;/p&gt;
&lt;p&gt;The first thing you must surely do is get the awful decision to use the acronym &amp;quot;Linq&amp;quot; everywhere instead of the word &amp;quot;Query&amp;quot; reversed. This decision change goes against pretty much everything that the wonderful FDG book stood for.&lt;/p&gt;
&lt;p&gt;There's still time.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1573951&amp;amp;SiteID=1"&gt;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1573951&amp;amp;SiteID=1&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Thanks, Pete.&lt;/p&gt;</description></item><item><title>Dynamic nature of C# I bet you don't know :)</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3964384</link><pubDate>Fri, 20 Jul 2007 03:01:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3964384</guid><dc:creator>Pawel Pabich's blog</dc:creator><description>&lt;p&gt;Dynamic nature of C# I bet you don't know :)&lt;/p&gt;
</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3968612</link><pubDate>Fri, 20 Jul 2007 06:27:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3968612</guid><dc:creator>Jonas</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;What's wrong with the interface description? It's well known, no need to come up with some new &amp;quot;syntax&amp;quot;.&lt;/p&gt;
&lt;p&gt;The &amp;quot;duck&amp;quot; type doesn't have to &amp;quot;implement&amp;quot; the interface it just used to describe the contract.&lt;/p&gt;
&lt;p&gt;But seriously... what will happen if it doesn't implement all of the contract ;)&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;/Jonas&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3972580</link><pubDate>Fri, 20 Jul 2007 12:25:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3972580</guid><dc:creator>Pawel Pabich</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you provide more examples like the IEnumerable one?&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3975315</link><pubDate>Fri, 20 Jul 2007 16:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3975315</guid><dc:creator>Sven</dc:creator><description>&lt;p&gt;I think that that notation could be usable, however [ItemType] should be replaced with [Foreachable], or else something like this&lt;/p&gt;
&lt;p&gt;[ItemType : Foreachable]&lt;/p&gt;
&lt;p&gt;{ ...&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;[Enumerator]&lt;/p&gt;
&lt;p&gt;{ [ItemType]&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Now, it's not clear that ItemType is actually the &amp;quot;foreachable&amp;quot; type.&lt;/p&gt;</description></item><item><title>Dynamic nature of C# I bet you don't know :)</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3981331</link><pubDate>Sat, 21 Jul 2007 01:19:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3981331</guid><dc:creator>Blog</dc:creator><description>&lt;p&gt;Dynamic nature of C# I bet you don't know :)&lt;/p&gt;
</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#3987184</link><pubDate>Sat, 21 Jul 2007 12:54:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3987184</guid><dc:creator>Raja R Harinath</dc:creator><description>&lt;p&gt;This seems similar to the all the discussions of &amp;quot;concept&amp;quot;s in C++ generic libraries.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#4009843</link><pubDate>Mon, 23 Jul 2007 15:57:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4009843</guid><dc:creator>Ian Horwill</dc:creator><description>&lt;p&gt;How about adding an [implicit] attribute to an interface definition?&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#4031952</link><pubDate>Tue, 24 Jul 2007 20:36:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4031952</guid><dc:creator>kcwalina</dc:creator><description>&lt;p&gt;Sorry for a late reply. I was on short vacation.&lt;/p&gt;
&lt;p&gt;Just to clarify, this is not about features in the compiler. This is just a paper notatio so it's easier to describe such patterns.&lt;/p&gt;
&lt;p&gt;And of course, thanks for all the pointers and comments!&lt;/p&gt;
</description></item><item><title>Why Duck Typing Matters To C# Developers</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#4473596</link><pubDate>Mon, 20 Aug 2007 07:45:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4473596</guid><dc:creator>you've been HAACKED</dc:creator><description>&lt;p&gt;Why Duck Typing Matters To C# Developers&lt;/p&gt;
</description></item><item><title>Supporting "foreach" without implementing IEnumerable</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#4930311</link><pubDate>Sat, 15 Sep 2007 19:21:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4930311</guid><dc:creator>Dotmad</dc:creator><description>&lt;p&gt;Krzysztof Cwalina wrote a post detailing how have your class support the &amp;quot;foreach&amp;quot; loop without implementing&lt;/p&gt;
</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#5514810</link><pubDate>Fri, 19 Oct 2007 02:00:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5514810</guid><dc:creator>Wayne</dc:creator><description>&lt;p&gt;You are wrong :-)&lt;/p&gt;
&lt;p&gt;I have just sat and passed 70-536, there was a question on foreach and the &amp;quot;correct&amp;quot; answer was &amp;quot;IEnumerable&amp;quot;.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#5695368</link><pubDate>Fri, 26 Oct 2007 22:58:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5695368</guid><dc:creator>kcwalina</dc:creator><description>&lt;p&gt;Wayne, what was the question?&lt;/p&gt;
</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#5849476</link><pubDate>Sat, 03 Nov 2007 05:24:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5849476</guid><dc:creator>Ricardo Lacerda Castelo Branco</dc:creator><description>&lt;p&gt;I really like Ian Horwill suggestion. The only problem is that to really duck typing we are not forced to &amp;quot;implement&amp;quot; all members of the interface. We have to implement only the ones used in a given method. &lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#5998967</link><pubDate>Fri, 09 Nov 2007 02:00:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5998967</guid><dc:creator>Wayne</dc:creator><description>&lt;p&gt;There was a question in the exam about what functionality must be implemented by a class so that it can support foreach, the answer being &amp;quot;implement the IEnurable interface&amp;quot;.&lt;/p&gt;
&lt;p&gt;From reading your post the the correct answer implement MoveNext and Current was not available as an option.&lt;/p&gt;
&lt;p&gt;It is this type of inaccuracy/simplification in the exams that lessens the value of certification.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#6340195</link><pubDate>Sat, 17 Nov 2007 20:12:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6340195</guid><dc:creator>Ulf L</dc:creator><description>&lt;p&gt;Dear Krzysztof Cwalina,&lt;/p&gt;
&lt;p&gt;There is some confusion about C#, duck notation and foreach on Wikipedia. Please see:'&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Talk:Duck_typing#C.23"&gt;http://en.wikipedia.org/wiki/Talk:Duck_typing#C.23&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Sincerly&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Ulf L&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#6341298</link><pubDate>Sat, 17 Nov 2007 21:27:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6341298</guid><dc:creator>Paddy3118</dc:creator><description>&lt;p&gt;If you take into account this comparison of Duck-Typing with Structural-Typing:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Duck_typing#Comparison_with_Structural_type_systems"&gt;http://en.wikipedia.org/wiki/Duck_typing#Comparison_with_Structural_type_systems&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don't think you give enough information for me to determine which you intend to implement. COuld you say which?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#6764058</link><pubDate>Thu, 13 Dec 2007 22:00:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6764058</guid><dc:creator>David</dc:creator><description>&lt;p&gt;I'm sorry, but who decided that duck typing in C# was a good idea? The foreach decision is still incomprehensible, but since almost no one knows about it, and since its mostly irrelevant since everyone implements IEnumerable anyway, I can let that slide. But now you are pushing duck typing to the forefront in what has been (and should be!) a statically typed language. Not that dynamic language features can't be useful, but shoehorning them into a language that clearly wasn't designed for them is just asking for trouble. If the C# language team continues on this course, I am confident that C# as a language will be mostly unusable just one or two versions from now. Please, THINK about what you are doing, and get community feedback, before you throw yourself off a cliff. Compromising the integrity of a language for the sake of a &amp;quot;cool&amp;quot; feature is a recipe for disaster, especially when there are other ways to accomplish the same goal that could also be useful in other areas and would not compromise the language.&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#7102829</link><pubDate>Mon, 14 Jan 2008 01:15:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7102829</guid><dc:creator>David Banister</dc:creator><description>&lt;p&gt;I have run into this situation in various occasions:&lt;/p&gt;
&lt;p&gt;1. Sometimes a common pattern is implemented without a formal interface.&lt;/p&gt;
&lt;p&gt;2. Looking for static methods which cannot be defined in an interface.&lt;/p&gt;
&lt;p&gt;I had never heard of &amp;quot;duck typing&amp;quot;, but I used a similar notation with the concept of a &amp;quot;shadow&amp;quot; (with similar logic &amp;quot;If it casts the shadow of a signature, it has that signature.&amp;quot;). I defined interfaces that contained the signatures for which I was looking. This process would be much easier if it was handled by the compiler.&lt;/p&gt;
&lt;p&gt;The syntax that would be awesome would be very similar to interfaces, but would allow all the generally possible modifiers. For the foreach example:&lt;/p&gt;
&lt;p&gt;shadow SForeachable&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public SEnumerator GetEnumerator( );&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;shadow SEnumerator&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public object Current{ get; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public bool MoveNext( );&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;No object could actually &amp;quot;implement&amp;quot; the shadow, it would simply match it or not, but this syntax would be easy to use with type casting constructs. For example:&lt;/p&gt;
&lt;p&gt;foreach(MyObject obj in myEnumerable)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; // do something in the loop&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;would be converted into:&lt;/p&gt;
&lt;p&gt;SForeachable foreachable = (SForeachable)myEnumerable;&lt;/p&gt;
&lt;p&gt;while(foreachable.MoveNext( ))&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; MyOjbect obj = foreachable.Current;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; // do something in the loop&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;From my experience, the most useful aspect would be to have some way of dealing with static methods that are commonly implemented:&lt;/p&gt;
&lt;p&gt;shadow SParsable&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public static shadow Parse( string text );&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;In this syntax I used the shadow keyword in place of the concrete type that is defined. The problem comes with merging instance syntax with static syntax. Something like the following might do:&lt;/p&gt;
&lt;p&gt;Type x = ...// some time gathered by reflection&lt;/p&gt;
&lt;p&gt;Decimal instance = SParsable(x).Parse( text );&lt;/p&gt;
&lt;p&gt;I agree that this violates OO principles, but it drastically simplifies various tasks. At a minimum the &amp;quot;shadow&amp;quot; syntax could provide a representation at least in documentation for &amp;quot;duck typing&amp;quot;.&lt;/p&gt;</description></item><item><title>C# vNext Revisited</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#7355995</link><pubDate>Thu, 31 Jan 2008 22:18:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7355995</guid><dc:creator>Matthew Podwysocki's Blog</dc:creator><description>&lt;p&gt;I often rethink or have additions to my posts. This topic of what's coming in C# vNext is definitely&lt;/p&gt;
</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#7854100</link><pubDate>Sat, 23 Feb 2008 07:35:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7854100</guid><dc:creator>Mats Helander</dc:creator><description>&lt;p&gt;Yes, your example compiles. The following, however, does not. Does this make you agree that the duck typing choice for foreach was a bad one? If not, why not?&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;class Program&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;static void Main(string[] args)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// the following does not complile!&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// all thanks to foreach duck typing &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// rather than properly using interfaces...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;YearCollection f = new YearCollection();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foreach (object o in f)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(&amp;quot;Hi!&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.ReadLine();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;class YearCollection&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public Year GetEnumerator() { return new Year(); }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public struct Year : IEnumerator&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public object Current&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;get { return new DateTime(DateTime.Today.Year, 1, 1); }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private int cursor;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bool IEnumerator.MoveNext()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (cursor &amp;gt;= DateTime.Today.Year)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return false;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cursor++;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return true;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;object IEnumerator.Current&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;get { return new DateTime(cursor, 1, 1); }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;void IEnumerator.Reset()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cursor = 0;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;</description></item><item><title>re: Duck Notation</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#8149264</link><pubDate>Tue, 11 Mar 2008 13:42:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8149264</guid><dc:creator>Andrew</dc:creator><description>&lt;p&gt;Hi, I guess in this particular case (foreach), duck typing is used so that CLR woudn't need to cast an enumerator to IEnumerator interface. Hence, we can use structs as enumerators (thus decreasing the pressure on GC). Generic List and Dictionary enumerators are implemented in that way.&lt;/p&gt;
&lt;p&gt;But the drawback is that we need to make such enumerator structs public nested (not private nested) - otherwise boxing occures anyway.&lt;/p&gt;</description></item><item><title>Foreach is Duck Typed!</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#8764434</link><pubDate>Tue, 22 Jul 2008 20:04:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8764434</guid><dc:creator>This Blog Can Also Be A Hat</dc:creator><description>&lt;p&gt;I thought I know how the foreach construct worked under the covers. I figured the runtime/compiler would&lt;/p&gt;
</description></item><item><title>今天看到的好文，很不错，特别是那漫画。</title><link>http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx#8771895</link><pubDate>Fri, 25 Jul 2008 14:01:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8771895</guid><dc:creator>真见</dc:creator><description>&lt;p&gt;感谢Gray Zhang 的再次帮助，C#4.0的四个新特性由他大致翻译。&lt;/p&gt;
</description></item></channel></rss>