Has anyone noticed the same trend I have? We’re in this weird area of language evolution in which those of us who have been trained to think statically are beginning to envy some of the niceties provided by dynamic languages (such as implicit types) while at the same time those of us who have been trained to think dynamically are beginning to envy some of the niceties provided by static languages (such as explicit types.)

Weird.

Take, for example, C# 3.0 implicitly typed local variables,

In an implicitly typed local variable declaration, the type of the local variable being declared is inferred from the expression used to initialize the variable. When a local variable declaration specifies var as the type and no type named var is in scope, the declaration is an implicitly typed local variable declaration. For example:


var i = 5;
var s = "Hello";
var d = 1.0;
var numbers = new int[] {1, 2, 3};
var orders = new Dictionary();

Okay, now take a look at the following: The first from Charles Nutter(which is about providing the performance of statically compiled code while maintaining implicitly typed variables), and the second from Ola Bini, both of JRuby fame (which is about adding the ability to sprinkle static type declarations in your Ruby code to gain performance advantages from the compiler),

Duby: A Type-Inferred Ruby-Like JVM Language

We’ve long wanted to have a “Ruby-like” language, probably a subset of Ruby syntax, that we could compile to solid, fast, idiomatic JVM bytecode. Not a compiler for Ruby, with all the bells and whistles that make Ruby both difficult to support and inefficient to use for implementing itself. A real subset language that produces clean, tight JVM bytecode on par with what you’d get from compiled Java. But better, because it still looks and feels mostly like Ruby.

So I wrote one! And I used my bytecode library too!

Should Ruby have optional typing and compiler directives?

I want this in Ruby, or something equivalent to it. Not necessarily the exactly same thing, but something which in a standard way can add type declarations and also other things that can be interesting to know from a compiler perspective.

Of course in addition to C# on the .NET side, you have languages such as Boo, Nemerle, and F# that are attempting to bridge the gap between static and dynamic languages, each doing so in ways that feel natural to each projects target audience. And on the Java side you have languages such as Scala (no doubt there are *TONS* more. I just don’t spend much time in the Java world, so am not as up as I probably should be on all the various Java bytecode language/compiler projects out there) attempting to do the same. All of which I believe is absolutely wonderful for one very important reason (though there are plenty more),

Instead of making attempt to promote the “One True Language” approach, everyone seems to finding ways to embrace wrist friendly coding techniques while at the same time accepting the fact static typing provides performance benefits that you just can’t gain any other way. Of course, as Dare Obasanjo recently pointed out, the C# language specification makes the following remark, one in which I most certainly agree with and stand behind,

Remarks: Overuse of var can make source code less readable for others. It is recommended to use var only when it is necessary, that is, when the variable will be used to store an anonymous type or a collection of anonymous types.

Which brings things back to my original point: We’re in a weird area of language evolution at the moment.

Exciting!

But weird.