In the beginning there was the object...
Generics: A Bedtime Story
In the beginning there was the
object, and it was given unto the
Programmers that they might have dominion
over the Code. The Programmers loved
and nurtured the object, putting it
to good use, and they created many,
many objects. But the objects had no
way of being collected together and
the Programmers had difficulty finding
effective ways to use all the
objects that they had accumulated. Seeing
the tribulations of the Programmers and
his creations, our Lord in Redmond,
Anders be his name, created
System.Collections, and all the objects
happily gathered together in groups. The
Programmers discovered they could iterate
over the collections and enumerate through
the objects, and they were pleased.
But as time wore on the Programmers
found the objects restrictive and derived
new objects from them, and soon
countless new types of objects had
evolved that could do all manner of
wondrous things. The Programmers found
that certain types of objects only
gambolled happily in the Runtime when
gathered together with their own kind,
for only in this way could they
be useful. They also discovered that
when an object of the wrong type
accidentally found its way into a
collection it didn’t belong in, the
Runtime would choke and die the
Death Of A Thousand Exceptions. The
Programmers wailed and pulled their hair
and gnashed their teeth. They were
forced to derive new strongly typed
collections from the CollectionBase for
each new object they created in
order to maintain order in the Code,
and from this arose the evil of
Carpal Tunnel Syndrome. Some Programmers
created collections which enforced order
through the dark sorcery of Reflection,
but this made the Runtime constipated
and slow and hungry for the Sacred
RAM, which raised the ire of the
Users who coveted the RAM. The Great
Anders took pity on the Programmers
when he saw their despair and gave
unto them the gift of Generics to
enforce type safety without bringing a
pox upon the Runtime. The Programmers
and the Users were happy and the
Code was fast and clean and glorious
to look upon. Anders looked down
upon his work and saw that it
was good.
That was the introduction to a presentation that a good friend and
colleague of mine* penned for his talk on C# generics. He thinks it is “lame”, I
strongly disagree.
* He drops gems like this on a regular basis, if someone out there has
connections with a publisher they should get in contact with him – the results
would be a best seller!