JavaScript's sweet spot
blog.mrale.ph
blog.mrale.ph
The goal was just to show that sometimes JS code generated by some tool sometimes can be faster than handwritten JS code just because it tries to emulate something foreign (like low-level memory semantics) and thus reducing certain overheads. So one should be very careful when extrapolating speed shown by some project into effectiveness of the whole language.
[also I tried to stress the fact that speed is not everything there is to performance. If you have a long lived webapp in your tab you suddenly might become concerned by memory usage. Which is rather difficult to predict partially because of the "hairy" nature of the heap, the fact that VM tries to adapt to your app but doesn't always get it right, and the cost of the VM itself (e.g. generated code and additional data structures)]
Something like AS3 (Harmony) syntax:
var foo:int = 3;
var bar:string = "A nice string";
var baz:Array = ["a", "polymorphous", 4, "array"];
var v:Array.<int> = [2,3,4];
function f(a:int, b:string):string {
return a + " " + b;
}
Sidenote: I really want someone to write a Coffeescript compiler that supports type annotations like the above. It can strip them out when it compiles the code; I just want it to yell at me if I violate one of my declared types.For example: how is v:Array.<int> enforced (and is it enforced at all)?
Type annotations can be a good to seed type inference analysis or adjust collected type feedback. But unless they guarantee stability of objects shapes (e.g. Array.<float> can contain only floating point numbers) they'll give little.
It's next to impossible to emit such code from language that is not statically typed.
Also it's not necessarily going to be faster than handwritten "human" JavaScript. There are a lot of factors in play. That's exactly what I am trying to stress in the blog post.
It's an interesting idea, and having little to no knowledge of compilers, I'd be interested in your take on it. Could emscripten already be used for something like this?
> And implementation complexity is the worst kind of complexity in the world: it leads to subtle bugs that occur on 0.000001% of programs, it leads to unpredictable and hard to analyze performance, it leads to volumes of rulebooks that specify how to appease the compiler
Implementation complexity is much better than interface complexity. It does not necessarily break down subtly. Unlike interface complexity, it is localized.
public View getDropDownView (int position, View convertView, ViewGroup parent)
convertView - the old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view.
The presence of the unintuitive 'convertView' object is caused by the underlying VM and the unpredictable GC nature. This demonstrates that implementation complexity can lead to a complex interface.
IMO the design of the interface is an implementation. A language that is complex to implement will lead to complex interfaces.
Umm... Instead of proceeding to rewrite the app and author this blog, the author could have realized that JavaScript (or Scala, Java, Python etc.) could realistically be faster than C and should have explained the same to his/her boss.
Also mr. C and his boss came into existence for a very particular purpose and that purpose is not "JavaScript vs. C" but rather "Normal JavaScript vs. inhuman JavaScript" comparison.
And I'd tend to agree, a single order of magnitude difference with C out of the box? That's pretty damn good (it helps that the code is highly numerical, JITs are good at that).
(I would not call the struct POINT though because it would feel like something from WinAPI :-))