From: Vidar Hokstad Date: 2006-09-04T18:40:14+09:00 Subject: Re: Joel Spolsky on languages for web programming Devin Mullins wrote: > David Vallner wrote: > > Speaking purely theorethically, Ruby can not be made as performant as > > Java or C# could be made if they had ideally performing implementations. > > Latent typing makes it almost impossible to do certain optimizations as > > static typing does. That's pure fact. > Irrelevant. In many cases, the fact that Ruby has latent typing is an > *implementation detail*. Ruby has *no type declarations*, but in many > cases static type inference can be applied to get the same optimizations > of which Java and C# implementations avail themselves. (Disclaimer: > that's about as much as I know about this subject.) You're absolutely right. Look to Haskell for a good example a _statically typed_ language almost free of type annotation of any kind - type information is almost exclusively added by the compiler (though you can add type annotations). While Ruby has features that make it impossible for an implementation to use strict static typing everywhere, a lot of a typical Ruby application could be statically typed by an implementation using type inference fairly easily by doing some relatively simple flow analysis combined with marking up the parse tree. Doing it for a pure interpreter would be easy, but the advantages would be relatively limited. Doing it for a JIT compiler would also be quite straightforwards and does have the potential of very significant speedups. For a full fledged compiler it would be tricky without some restrictions - the main problem is Ruby's introspective features and various eval mechanisms, which means the type inference valid at compile time might not hold at runtime. Add a few restrictions on the use of load/require etc. and the use of eval's and/or some way of adding some basic type annotation to guide the compiler for "extension points" (classes/methods that will be affected by runtime changes) and it would be doable without significant changes. Vidar