rentzsch.com: tales from the red shed

Type Inferencing Genie out of the Bottle

Notes

Looking past Microsoft's piteous Gadgets announcement (oh my gawd Microsoft, I just feel embarrassed for you) there's good news from PDC 2005: C# 3.0 will support type inferencing.

There has always been a tension between languages that force you to declare your variable types (for example, C, Java, C#) and those who don't (JavaScript, AppleScript, Python). The declaration-less are appealing in seeming simplicity, but you lose efficiency and compile-time safety.

Of course, you can have a hybrid systems like ObjC's id and Visual Basic's Variant/Object. You declare types everywhere, but you have the option of using a type that basically boils down to "I don't know this variable's type at compile time". The downside to the hybrids is that they're larger and more complicated than either system alone, and can (will) be abused.

Type inferencing means the language infers variable types based on how you use them. Consider the following mythical function:

addOne( someNumber ) {
  return someNumber + 1;
}

The compiler can look at this, see you're adding an integer to the parameter, and essentially write the type declarations for you:

int addOne( int someNumber ) {
  return someNumber + 1;
}

This is a very simple example, but there's a lot of ramifications from this one concept. Hit Mark Jason Dominus's "Strong Typing Doesn't Have to Suck" for a nice talk on the subject.

It used to be if you wanted to play with type inferencing, your choices were only nonmainstream languages like ML, Haskell and O'Caml. Kudos to Microsoft for bringing it to the (programming) masses. I just hope they get the implementation "right".

While I'm praising Microsoft, I'll also mention MSH (Monad) looks impressive, and I'm quite pleased it's included in the current Vista build. There was talk about it being dropped because it's (yet another) Windows exploitation vector, but I hope Microsoft ships it anyway. It's not like adding another vector will dramatically decrease Windows' already dreadful security, and it brings a good deal to the table. My sincere hope is that MSH or something like it buries the current barbaric *nix-style shells. But that's another post.

While Microsoft demonstrates a continuing incompetence regarding desktop and server software, they're showing promise regarding developer tools. We'll know they're serious when they ship a real, sane object relational framework. Maybe in Windows Spectacle 2019.

Wednesday, September 14, 2005
12:57 PM