|
|
|
|
|
by p3ll0n
5837 days ago
|
|
Lisp is certainly great, and Clojure looks like a reasonable lisp. I wonder why the JVM attracts untyped languages while .NET attracts typed ones. Could it be that the Java language has damaged people’s ideas of what types are for? |
|
Generics in .NET are said to be reified ... meaning that when instantiating a generic type, you get that type at runtime. It also handles it smartly ... meaning that you don't get performance penalties. And for stack-allocated objects (structs in .NET or primitive types like int/double) it does code-specialization (generates a new class) which means you can avoid boxing/unboxing overhead.
This actually makes a difference, as reified generics are the only sane way to have sane parametric polymorphism in a language that does runtime single-dispatch (like C# / Java).
Reified generics are hard to implement though, especially if you want covariance/contravariance. That's why .NET only has limited support for such rules (available only on interfaces and delegates).
With type-erasure, as in Java or in Scala ... generics are only a way to avoid explicit type-casts (Java), or to enable local type-inference (Scala). And I have found no paper on implementing reified generics on top of the JVM, without modifying the JVM (a possible task, no doubt, but it's probably not worth the overhead).
Java also has another problem (which is also a problem for dynamic languages) ... no way to have custom stack-allocated objects. This is a problem since number types (int/float/double) don't map 1:1 with the types in other languages, often having different behavior / different sizes, and this is a PITA since you want to avoid the boxing/unboxing overhead.
Of course, the CLR is not without its problems ... like, if you want lazy integers (as in Haskell) ... you would need an Union of an integer + a method reference, and it should be a union to avoid the memory penalty (and you could make the distinction by holding 1 bit of that integer as the tag). On the CLR, you can't do it this way since there are no union types, and the security model doesn't allow you to store method references inside integers.
The JVM on the other hand is preferred for dynamic languages because ... it is a better target (it does runtime optimizations that the CLR doesn't) and because people wanting dynamic languages also prefer more open ecosystems.
.NET's DLR is an interesting piece of work, but you don't gain much performance by using it and to me it seems like another mouse trap (no really ... building DLR ASTs seems like a good idea, but what happens when your language is nowhere close to Ruby/Python or Javascript, which have similar base types and dispatching rules?).
It's pretty cool though that by using it you gain instant interoperability with other .NET languages. See this piece from IronJS's author: http://ugh.cc/ironjs-function-call-overhead-benchmark/