News for hackers. Stuff that matters.
Re:Opa: A new language aiming to make web programming transp... by hbbio on Thursday August 25, 2011 @06:54PM (#2926716)
Partial answers/tidbits:

The JS code is not as optimized as what you can write manually, although a lot of work was put in making it work "fast enough" (thanks Mathieu). However, we have many ideas on how to reach native performance. Look for instance at how Java got sometimes even faster than C!

There are hints @server and @client to specify a side for running a bit of your code. Since, as you say, there are things you know and the machine doesn't.

Opa being a compiler, updated projects have to be recompiled. You gain a lot in quality, consistency with this (especially associated to the very advanced type system of Opa). And as we know that compilers are annoying, we made our best to make the compile time short. You probably won't have to take a coffee, sorry.

The chat example does not rely on predefined libraries -- that's the difference. You can also look at bigger chat applications like https://github.com/hbbio/OpaChat and compare with https://github.com/ry/node_chat.

Opa requires Java for building from source - if the package does, that's something you can report at https://github.com/mlstate/opalang/issues?sort=created&d...

Re:Opa: A new language aiming to make web programming transp... by Groxx on Friday August 26, 2011 @12:33AM (#2927398)
>Look for instance at how Java got sometimes even faster than C!

I don't think browsers are going to let you build a hot-spot compiler in Javascript. Nor do I think that an online, optimizing interpreter in javascript stands much of a chance of improving performance.

Re:Opa: A new language aiming to make web programming transp... by Yoric on Friday August 26, 2011 @05:46AM (#2927940)
Certainly. However, in many cases, the high-level information that Opa has can be used to produce highly-efficient JavaScript code and/or highly-efficient distribution layout, that would be quite hard, time-consuming and error-prone to replicate by hand. On the JavaScript side, this is already the case e.g. for our implementation of pattern-matching or tail-recursive functions. We have numerous additional such ideas that we have not found time to implement.

And then, if NaCl/NativeClient becomes mainstream, that's yet another avenue worth exploring.

Re:Opa: A new language aiming to make web programming transp... by dgreensp on Friday August 26, 2011 @01:30PM (#2929172)
There are ways this story fails in practice, like the "language mismatch" I mentioned.

For example, in Google Web Toolkit, which compiles Java to JavaScript, theoretically the static type information should be a huge boon to optimization. And indeed, the compiler does some fancy stuff, including static inlining, and segmenting the code so that chunk 2 is only downloaded when a method call crosses the boundary of chunk 1.

However, consider something like a HashMap. A JavaScript programmer might use a single JS object as a hash, whereas the GWT programmer has the luxury of using a java.util.HashMap, which is theoretically compiled down to something efficient, maybe just as efficient. In practice, this is hard or impossible for the compiler, and HashMaps are compiled to a system of objects that's much more complex. There are great reasons for this -- primarily, HashMaps can have any object as a key, not just a string; also the nature of the HashMap API and behavior under subclassing -- but the result is if you want something fast, you need to use a FastStringMap or some such class, backed by a "native" JS object. But in general, when you're not worrying about performance, you might find yourself using many HashMaps, even parsing JSON into nested HashMaps! So now each JS object is represented by a bunch of JS objects needed to make the mechanics of the HashMap abstraction work.

I worry that not having arrays leads to a similar problem. In magic happy land, a call like List.pop that removes the last element of a list would be implemented as a tail-recursive operation on heads and tails, which the compile would then recognize and turn back into a call to Array.pop! In practice, this kind of thing is unlikely. As with HashMaps, the programmer is forced (or told) to use heavyweight data structures to simulate lightweight ones, with the hope that the compiler will recognize that this is a case where the lightweight structure applies and transform it back!

As for "online" compilation, I guess this is easier on the JVM. Clojure, Rhino, Scala, and Java are all compiled and can be set up to recompile on the fly after every change to the program. Node.js too. Having developed this way, I don't think I could go back to having to do anything after changing the code besides reloading the page.

Re:Opa: A new language aiming to make web programming transp... by Yoric on Saturday August 27, 2011 @06:27AM (#2931239)
> I worry that not having arrays leads to a similar problem.

Good point. We have actually been working on this specific problem of lists vs. arrays. The results have not been put on code yet, but we hope that the problem can be solved in many cases.

> Having developed this way, I don't think I could go back to having to do anything after changing the code besides reloading the page.

We have also been working on that. Future versions of Opa might offer something along these lines.