[OT] Finding longest documents
Benji Smith
dlanguage at benjismith.net
Tue Oct 14 19:07:48 PDT 2008
Andrei Alexandrescu wrote:
> Benji Smith wrote:
>> Andrei Alexandrescu wrote:
>>> Christopher Wright wrote:
>>>> Containers as value types is such an idiotic idea for precisely this
>>>> reason.
>>>
>>> I'd say this statement reflects a lack of understanding of value
>>> types, rather than value containers are an idiotic idea.
>>
>> I'll bite.
>>
>> Why is it a good idea that containers are implements as structs?
>
> As the Mexican would say: why not?
Well... here are a few reasons why not:
Structs can't implement interfaces, and a collection API is the
poster-child of good interface usage.
Structs can't inherit from abstract classes. A good deal of
functionality in a collection class can be implemented once in an
abstract base class, making it simpler for subclass authors to implement
the API without duplicating a bunch of boilerplate.
Conceptually -- and there's no hard and fast rule about this -- structs
usually either represent small logically-atomic values (DateTime), or
some fixed-size collection of logically-atomic values (Vector3). Using a
struct as an arbitrarily-sized container seems, on the face of it, to
break those conventions.
--benji
More information about the Digitalmars-d
mailing list