0

Would it be possible to design a statically typed JIT'ed language to build a web framework like Ruby on Rails, an attempt to gain the speed of a statically typed language?

Embedded Ruby (eRuby) in html is a feature of Ruby on Rails that I don't see an obvious way to implement in a statically typed JIT'ed or compiled language.

I am not familiar with the internals of the implementation of Ruby on Rails, but more generally are there other features of Ruby on Rails that would be very difficult to implement in a statically typed JIT'ed or compiled language?

user782220
  • 10,677
  • 21
  • 72
  • 135

1 Answers1

0

Sure. It wouldn't necessarily achieve what you want (dynamic typing is just one of many things which make optimizations harder, the "fast" languages you know make many tradeoffs beside static typing to achieve that performance), but it's perfectly possible. In fact, it's being done. ASP.NET MVC has had the Razor view engine for quite a while now, which features a statically typed template language. The few restrictions compared to C#/VB.NET (e.g. I don't think you can declare classes) are design decisions, not technical issues. Basically, all you need to do it parse the template, separate (e.g.) HTML from code, and generate code which outputs the strings that should be output according to the template.

Now, Ruby on Rails specifically is heavily using the dynamic features of Ruby. While many "statically typed" languages do feature reflection which may achieve something similar (though much more verbose), and other metaprogramming constructs can be typed just fine, I doubt you could simply port RoR to a run of the mill statically typed language, especially if you want the end result to be anywhere as convenient. It's probably better to create a new framework, inspired by existing ones. And that has already been done. A thousand times. Per language.

  • How does this Razor view engine for ASP.NET MVC execute code embedded in html for a compiled language? It can't just simply insert code into the already compiled binary. – user782220 Dec 08 '12 at 02:02
  • I'm fuzzy on the actual implementation, but two options are: (1) Output C# (or whatever) early in the build, and compile it like any other source file. (2) Generate a separate assembly (possibly then merging it with the "real" one, or loading it dynamically at runtime when the template is requested). –  Dec 08 '12 at 12:24