C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Simple spec != simple implementation

Chapter 3: Parameterized typing with generics: 3.3.2

Created: 1/29/2008
Last updated: 1/29/2008

When discussing type inference, I mentioned that the rules in C# 2 are fairly simple. Eric pointed out that what may seem simple in a spec certainly needn't be simple in terms of a compiler implementation - especially when one considers the compiler to be part of an IDE which needs to provide Intellisense, work with incomplete code etc.

In a way, this is similar to writing an XML editor. If you start with an XML parser which correctly spits out errors on invalid XML documents, you've got an awful lot of work ahead of you. Much of the time spent in an XML editor is with an invalid document, as you're in the middle of changing it: the editor needs to understand that and respond accordingly.

Having said all this, the type inference rules in C# 2 really are fairly straightforward from the point of view of a C# developer. The same can't be said of the C# 3 rules! None of this takes away from the great job the C# team have done in terms of implementation.