WindowsDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


AddThis Social Bookmark Button

C#: Yesterday, Today, and Tomorrow: An Interview with Anders Hejlsberg, Part 1
Pages: 1, 2, 3, 4, 5

What To Look for in 2.0

Osborn: What else besides generics and anonymous methods should people be paying attention to in 2.0?

Hejlsberg: Nullable types, I would say, is a pretty important advance, too. Because it's one of the steps on the way to bringing parity between the database world and the general-purpose programming world. You know, it's very hard to talk about meaningful mappings between the two worlds when one world, the database world, is entirely based on nullable types, and the other world doesn't have them at all.

Hejlsberg: And of course, you can fake your way out of it--

Osborn: Which you have to do--

Hejlsberg: --in the general programming world, which, you know, people often do by boxing, for example, or by allocating an object in which they store the value, and then using null if not. And that's effectively how Java does it. But it ends up being very expensive to do it that way. Because in order to represent an integer value that can possibly be null, typically the way it's done in Java is that you use the Integer wrapping class, and you allocate instances for each int value, and then you just use null as the null.

Hejlsberg: But you quadruple the memory consumption for each int, and you incur an indirection. So there's a lot of cost associated with that, where with nullable types in C#, we effectively give you the ability to make value types null, but we don't do it by allocating objects in the heap. We do it through a generic type that couples a T and a bool. It's called Nullable<t>, and it has two fields inside of it, a T and a bool.

But Nullable<T> is itself a value type. So it actually gets stack allocated or in-line allocated and ... it's much more efficient from a memory standpoint than other solutions that are out there. And over and above that, we have language syntax to support nullability. We have this question mark (?) type modifier.

So where int is an integer, int? is a nullable integer, and there are implicit conversions from int to nullable int, and explicit conversion the other way that will throw a null exception if the thing is ... like all the things that you would naturally expect of a language that deeply supports nullable types as a proper concept. So again, it's this thing about giving first-class treatment to a thing that people use every day.

And again, for me, as a language designer, I look at, "What are people doing out there? And what is it that we need to think about giving first-class treatment to?"

Osborn: So is C# one language to rule them all?

Hejlsberg: [Laughs] No, no. I think not, I don't really think it is. There are lots of things for which other languages are more suited. C#, at its core, is a strongly typed language. And for certain things, you know, dynamically typed languages are more appropriate if you're just going to write a few lines of code, and you don't want to first have to do a bunch of declaring upfront. You just want to sort of try it out.

But within the family of languages that it's in, sure, I aim to take it as far as I can.

Osborn: In relation to 2.0, are the changes that we're seeing in the Microsoft implementation also being proposed as standards?

Hejlsberg: In 2.0?

Osborn: In 2.0.

Hejlsberg: Yes. The standard will be called "third edition", but it's actually the one that we're calling 2.0.

Osborn: So there's no aspect to it that's Microsoft only in terms of the changes.

Hejlsberg: No, every language feature in C# 2.0 has been submitted to ECMA and is in the standardization process. And we expect fairly shortly for the community to vote, and it's really a matter of procedure at this point [Ed.: This has already happened. See "C# and CLI Become More Powerful."]

Osborn: So probably by the end of the year?

Hejlsberg: Yes.

This is part one of a two-part interview.

John Osborn is a senior editor with O'Reilly Media, Inc., responsible for Windows and .NET developer books, PDFs and other content.


Return to the ONDotnet.com.