18

This might be a broad question but this is something I am not really clear and very curious.

Often times for certain problems I hear the reasoning that it was because Generics was not available in .NET 1.0. That makes me think either of these 2 things:

  1. Generics was not thought of before, so the developers came up with it after .NET 1.0 which could drastically affect design of C# and .NET but couldn't because of decisions already made (backwards compatibility).

  2. Generics was always planned since the beginning, so the only problem that arise from not releasing it with .NET 1.0 was not being able to use it till 2.0. But other than this, no redundant features were introduced or wrong, irreversible decisions were committed.

I mostly assume #1, but is #2 is the actual case?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
  • 10
    This looks like a job for Skeet-man. – Mike Hofer Feb 23 '11 at 23:01
  • 10
    Or Eric Lippert. – Joan Venge Feb 23 '11 at 23:02
  • 2
    1.0 did not have generics or templates. 1.1 came out because they found through user testing that 1.0 was horrible to use. 2.0 was a rewrite and is the base of what we use today. – Dustin Davis Feb 23 '11 at 23:03
  • 1
    Given how long C++ had templates before C#, I'm pretty sure 1 is not the answer. And probably Eric Lippert will chime in – kenny Feb 23 '11 at 23:03
  • @kenny: But are C++ templates and C# generics exactly the same? – Joan Venge Feb 23 '11 at 23:05
  • I didn't know 2.0 was a rewrite. – Joan Venge Feb 23 '11 at 23:06
  • 1
    @Joan: No, they're very different. C++ templates can take in non-type parameters, and they're a compile-time feature. C# generics can only take type arguments, and they're a run-time feature. Superficially they're similar, but they're actually very different -- just look at [C++ generics](http://msdn.microsoft.com/en-us/library/8z2kbc1y.aspx) to see the difference. – user541686 Feb 23 '11 at 23:11
  • @Mehrdad: Thanks. Can you give an example to using a non-type on C++ templates? I just can't think of anything other than types as I only used generics. – Joan Venge Feb 23 '11 at 23:12
  • @Mehrdad, from a high level point of view, they solve the same problem IMO. So, it would be hard to call that 'very different'. – kenny Feb 23 '11 at 23:13
  • 1
    @Joan: See [here](http://www.cplusplus.com/doc/tutorial/templates/) for an example. (Search for `int N=10`.) – user541686 Feb 23 '11 at 23:14
  • 1
    @Kenny: Not really -- you can't do reflection with templates, but you can with generics. Templates bloat up the executable size; generics happen at runtime. Templates can sometimes be substituted for generics, but definitely not the other way around -- template metaprogramming is impossible with generics. – user541686 Feb 23 '11 at 23:15
  • @Mehrdad Maybe I'm mistaken, but generics are a compile-time concern, and this is what makes the difference when comparing Java generics' implementation, which is just syntactic sugar. – Matías Fidemraizer May 07 '16 at 08:16
  • @MatíasFidemraizer: In my comment, "happen" meant "are instantiated"... generics are instantiated at run time. – user541686 May 07 '16 at 08:26

4 Answers4

12

Generics have been around a long time and can be loosely compared to C++ templates, although the concept (and probably implementation in other languages) predates even that.

.Net 1.0 is the first cut of a platform so the plan was to ship something that works reasonably. Generics would have to have been on the "planned future" if any decent architect was on the team, but is something that could be added later. In fact, the paper on implementing generics for .NET came out a year before .Net Framework 1.0 RTM eventuated.

Timeline: (http://en.wikipedia.org/wiki/List_of_.NET_Framework_versions)

2002-03-05 .Net Framework version: 1.0.3705.0 released
~May, 2001 Don Syme's paper on "Design and implementation of generics for .NET"

Microsoft could have taken 10 years to build .Net Framework 4.0 (as version 1.0), but with so much code and so many features out at once, it would take 5 years to find all the bugs and usability issues if the project can even succeed.

So the answer to your question would be #2.

Don Syme primarily designed and implementated generics into C# and .Net.

Resources

Anders Hejlsberg is my hero - from Wikipedia - original author of Turbo Pascal, the chief architect of Delphi, later lead architect of C#

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
  • So Anders wasn't on the team for 1.0? – Joan Venge Feb 23 '11 at 23:11
  • 1
    @Joan - he was. But you cannot revolutionize by holing up and taking 10 years to build something. Let _something_ out (that at least works reasonably) and evolve it. – RichardTheKiwi Feb 23 '11 at 23:14
  • Anders should be on SO as well. – Joan Venge Feb 23 '11 at 23:16
  • 2
    @Richard You forgot the $50 TurboPascal! – David Heffernan Feb 23 '11 at 23:23
  • @Richard TP seems pretty lame when you look at it from 2011, but I think it was truly groundbreaking, on the PC at least. – David Heffernan Feb 23 '11 at 23:30
  • Sorry I posted the wrong link. Here is the correct one. So resposting: The answer isn't #2 it seems, because Eric Lippert here mentioned "things would have been a lot different if we'd had generics in CLR v1." http://stackoverflow.com/questions/5110877/why-cant-i-use-the-enumerator-of-an-array-instead-of-implementing-it-myself/5110960#5110960 – Joan Venge Feb 25 '11 at 02:03
  • @Joan context of quote is that "arrays can be done differently if generics were in v1". But it doesn't negate #2. The question isn't whether it is in v1 - because it is a fact that it isn't – RichardTheKiwi Feb 25 '11 at 02:48
  • @Richard, I see what you mean, but I thought it meant more than just arrays. Also even if it was just arrays, I am sure it's just one of these things. Also as you can see, the way arrays are implemented could have been better in code and behaviour, but instead we have some special code that makes the same effect, and potentially confuses people. – Joan Venge Feb 25 '11 at 13:15
6

I'm almost sure that generics were envisioned from the start. Full well realizing that the job was going to be considerable. The project was headed by Don Syme (of F# fame), his first publication about the design was dated January 2001. The CLR is presented as a given, the paper documents additions to the MSIL, although at the time .NET 1.0 had not shipped yet. That took another year. All and all, it's probably fair to conclude that it took them close to 4 years to hammer this together into concrete shipping software.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
2

if you're interested in the history of c# if check out channel9 and this video in particular

they have done a number of interviews with Anders Hejlsberg about this kind of stuff

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
aL3891
  • 6,205
  • 3
  • 33
  • 37
2

Don Syme, the designer of F#, was partially responsible for .NET generics.

eulerfx
  • 36,769
  • 7
  • 61
  • 83