﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Mike Brown commented on Explain this code</title><description>Just noticed you're showing the original posted date now. You have a 2 month backlog of posts. I want to be like you when I grow up LOL.
</description><link>http://ayende.com/154881/explain-this-code#comment24</link><guid>http://ayende.com/154881/explain-this-code#comment24</guid><pubDate>Fri, 13 Apr 2012 04:55:18 GMT</pubDate></item><item><title>Martin Odhelius commented on Explain this code</title><description>Since it is a struct it is probably, as Daniel Grunwald already mentioned,probably to avoid NullReferenceExceptions. But since the reason is so vague and can result in both dangerous behavior and dangerous conclusions it should probably not have been created in the first place ;)

pet: if you try to get around that warning by just implement your custom implementation of List you probably do not understand why you get the warning in the first place. If you expose the interface rather than the concrete type you can still extend it without doing any custom implementation and still get it extendable. But publicly expose mutable lists are in most situations not a good idea anyway so if you shall expose some sort of collection to the public it would probably be better to expose an IEnumerable&lt;T&gt;</description><link>http://ayende.com/154881/explain-this-code#comment23</link><guid>http://ayende.com/154881/explain-this-code#comment23</guid><pubDate>Fri, 13 Apr 2012 00:56:52 GMT</pubDate></item><item><title>Ayende Rahien commented on Explain this code</title><description>What you are seeing is caching differences, the front page is cached for a few minutes, so it is not surprising that you can see this discrepency.</description><link>http://ayende.com/154881/explain-this-code#comment21</link><guid>http://ayende.com/154881/explain-this-code#comment21</guid><pubDate>Thu, 12 Apr 2012 23:51:30 GMT</pubDate></item><item><title>Google commented on Explain this code</title><description>Here's my answer: http://ayende.com/blog/154882/explain-this-code-answers?key=941b81a7-8086-4c45-9406-2ef041ffa711. I'm sure it's ok :)

Oren your posts are gooooogled before they are pusblished on your blog...</description><link>http://ayende.com/154881/explain-this-code#comment20</link><guid>http://ayende.com/154881/explain-this-code#comment20</guid><pubDate>Thu, 12 Apr 2012 23:39:46 GMT</pubDate></item><item><title>João P. Bragança commented on Explain this code</title><description>http://stackoverflow.com/questions/945664/can-structs-contain-references-to-reference-types-in-c-sharp/945708#945708

Structs holding references kinda makes them pointless.</description><link>http://ayende.com/154881/explain-this-code#comment17</link><guid>http://ayende.com/154881/explain-this-code#comment17</guid><pubDate>Thu, 12 Apr 2012 19:55:18 GMT</pubDate></item><item><title>pet commented on Explain this code</title><description>http://msdn.microsoft.com/en-us/library/ms182142.aspx</description><link>http://ayende.com/154881/explain-this-code#comment16</link><guid>http://ayende.com/154881/explain-this-code#comment16</guid><pubDate>Thu, 12 Apr 2012 17:46:16 GMT</pubDate></item><item><title>Martin Doms commented on Explain this code</title><description>Of course exposing the inner list negates any advantage the decorator pattern gives, but like I said it's a non-optimal solution to a real problem</description><link>http://ayende.com/154881/explain-this-code#comment19</link><guid>http://ayende.com/154881/explain-this-code#comment19</guid><pubDate>Thu, 12 Apr 2012 16:52:54 GMT</pubDate></item><item><title>Martin Doms commented on Explain this code</title><description>It's essentially a List decorator that gives optional, changeable ReadOnly behaviour. Not the way I would have implemented it, but I can see the motivation.</description><link>http://ayende.com/154881/explain-this-code#comment18</link><guid>http://ayende.com/154881/explain-this-code#comment18</guid><pubDate>Thu, 12 Apr 2012 16:49:12 GMT</pubDate></item><item><title>Omer Mor commented on Explain this code</title><description>+1 for Daniel Grunwald explanation (structs are non-nullable, can skip null checks)</description><link>http://ayende.com/154881/explain-this-code#comment15</link><guid>http://ayende.com/154881/explain-this-code#comment15</guid><pubDate>Thu, 12 Apr 2012 16:24:21 GMT</pubDate></item><item><title>Winston commented on Explain this code</title><description>To create a Proxy if you're not using an ORM or a DynamicProxy. It's a lot of work but, if the guy want to learn from the basics, looks like a good idea.</description><link>http://ayende.com/154881/explain-this-code#comment14</link><guid>http://ayende.com/154881/explain-this-code#comment14</guid><pubDate>Thu, 12 Apr 2012 15:34:57 GMT</pubDate></item><item><title>Indranil commented on Explain this code</title><description>However making it a struct rules out inheritance</description><link>http://ayende.com/154881/explain-this-code#comment13</link><guid>http://ayende.com/154881/explain-this-code#comment13</guid><pubDate>Thu, 12 Apr 2012 14:43:54 GMT</pubDate></item><item><title>Matt Davey commented on Explain this code</title><description>@Wayne M creating first class collections which inherit from generic collection types is not stupid at all. From Object Calisthenics:

Rule 4: First class collections
Application of this rule is simple: any class that contains a collection should contain no other member variables.   Each collection gets wrapped in its own class, so now behaviors related to the collection have a home.  You may find that filters become a part of this new class.   Also, your new class can handle activities like joining two groups together or applying a rule to each element of the group.   </description><link>http://ayende.com/154881/explain-this-code#comment12</link><guid>http://ayende.com/154881/explain-this-code#comment12</guid><pubDate>Thu, 12 Apr 2012 14:23:34 GMT</pubDate></item><item><title>Matt Davey commented on Explain this code</title><description>One case for a struct like this would be for immutable collections, but the IList interface isn't designed for that...</description><link>http://ayende.com/154881/explain-this-code#comment11</link><guid>http://ayende.com/154881/explain-this-code#comment11</guid><pubDate>Thu, 12 Apr 2012 14:17:13 GMT</pubDate></item><item><title>Matt Davey commented on Explain this code</title><description>By making a struct you could potentially create an array of these lists and loop over them using pointer arithmetic, giving you fast jagged array behaviour with the extra functionality of IList... in any case I can't think of a legitimate reason for doing this that isn't solved in other, much nicer ways.</description><link>http://ayende.com/154881/explain-this-code#comment10</link><guid>http://ayende.com/154881/explain-this-code#comment10</guid><pubDate>Thu, 12 Apr 2012 13:19:42 GMT</pubDate></item><item><title>Indranil commented on Explain this code</title><description>It is a much more minimal class than System.Collections.Generic.List.
Only implements the IList members. None of the Sort, Search, Reverse methods.
Certainly will be easier to test than the full blown List. Possibly a faster implementation can be built? not sure why its a struct though.</description><link>http://ayende.com/154881/explain-this-code#comment9</link><guid>http://ayende.com/154881/explain-this-code#comment9</guid><pubDate>Thu, 12 Apr 2012 12:21:05 GMT</pubDate></item><item><title>Wayne M commented on Explain this code</title><description>To allow stupid people to make their own CustomerCollection type classes that inherit, rather than use an IList or ICollection?  Not quite sure but it seems to be a NIH thing; I've commonly seen places that will create wrappers for their own collection classes instead of just making it use a built-in type.</description><link>http://ayende.com/154881/explain-this-code#comment8</link><guid>http://ayende.com/154881/explain-this-code#comment8</guid><pubDate>Thu, 12 Apr 2012 12:12:36 GMT</pubDate></item><item><title>Falhar commented on Explain this code</title><description>I/List&lt;T&gt; should be used for intermediate collections inside your code. It is supposed to be fast and non-extensible.
I/Collection&lt;T&gt; should be used as class member, when you need to expose collection of items as property. It is also intended for extension, so you have specific behaviour for collection of specific items.

The fact, that it has InnerList is implementation detail and should be ignored.</description><link>http://ayende.com/154881/explain-this-code#comment7</link><guid>http://ayende.com/154881/explain-this-code#comment7</guid><pubDate>Thu, 12 Apr 2012 10:58:30 GMT</pubDate></item><item><title>João Angelo commented on Explain this code</title><description>Ignore my previous comment, I assumed that this was referring to the .NET Framework class and not a custom struct. It seems, that at least for me, a picture is not worth a thousand words....</description><link>http://ayende.com/154881/explain-this-code#comment6</link><guid>http://ayende.com/154881/explain-this-code#comment6</guid><pubDate>Thu, 12 Apr 2012 10:46:04 GMT</pubDate></item><item><title>giammin commented on Explain this code</title><description>because he heard that structs have better performance ;)</description><link>http://ayende.com/154881/explain-this-code#comment5</link><guid>http://ayende.com/154881/explain-this-code#comment5</guid><pubDate>Thu, 12 Apr 2012 10:44:38 GMT</pubDate></item><item><title>Daniel Grunwald commented on Explain this code</title><description>To avoid NullReferenceExceptions - it becomes impossible to pass around null collections (which is rarely useful).
`default(Collection&lt;T&gt;)` probably acts as a read-only empty list.

`default(Collection&lt;T&gt;)` is also usable as a default value for optional parameters, a static field pointing to a read-only list instance isn't. Without such a struct, you need to handle null as a special case whenever you use a list in an optional parameter.</description><link>http://ayende.com/154881/explain-this-code#comment4</link><guid>http://ayende.com/154881/explain-this-code#comment4</guid><pubDate>Thu, 12 Apr 2012 10:40:07 GMT</pubDate></item><item><title>João Angelo commented on Explain this code</title><description>Assuming you're questioning why create Collection&lt;T&gt; if we already have List&lt;T&gt; then I would say the main reason is the one stated in MSDN:

"The Collection(T) class provides protected methods that can be used to customize its behavior when adding and removing items, clearing the collection, or setting the value of an existing item."

Which allows a custom collection that derives from Collection&lt;T&gt; to have extension points available while a custom collection that derives from List&lt;T&gt; does not.</description><link>http://ayende.com/154881/explain-this-code#comment3</link><guid>http://ayende.com/154881/explain-this-code#comment3</guid><pubDate>Thu, 12 Apr 2012 10:39:28 GMT</pubDate></item><item><title>Justin Lovell commented on Explain this code</title><description>Probably to simplify if the two collections are equivalent? Ie: the items in both instances are existing in the two lists?

If so, then it begs the question why another comparability method was not manufactured?</description><link>http://ayende.com/154881/explain-this-code#comment2</link><guid>http://ayende.com/154881/explain-this-code#comment2</guid><pubDate>Thu, 12 Apr 2012 10:33:55 GMT</pubDate></item><item><title>Justin Lovell commented on Explain this code</title><description>Probably to simplify if the two collections are equivalent? Ie: the items in both instances are existing in the two lists?

If so, then it begs the question why another comparability method was not manufactured?</description><link>http://ayende.com/154881/explain-this-code#comment1</link><guid>http://ayende.com/154881/explain-this-code#comment1</guid><pubDate>Thu, 12 Apr 2012 10:33:36 GMT</pubDate></item></channel></rss>