JSX - a faster, safer, easier alternative to JavaScript
jsx.github.com
jsx.github.com
Box2D is a C++ library that has been ported to ActionScript and then, from ActionScript, converted to JavaScript - not by hand, but by a bunch of scripts[1]. The JS version of Box2D still carries around a lot of unnecessary weight from the original C++ and ActionScript versions and has much room for improvement.
A rewrite or "smart" conversion from C++ to JS, that endorses JS instead of trying to emulate C++ or ActionScript, should be able to improve performance a lot.
I don't know how Box2D was ported to JSX. Maybe it was a rewrite by a human? In any case, I'm not saying what they do isn't impressive, but calling Box2D an "optimized JavaScript library" is just plain wrong.
[1] There are several different JS ports of Box2D available, but, to my knowledge, none of which is a sensible rewrite by a human.
Probably the biggest inefficiency with all the ports is that they don't pool vectors. In the C++ version, vectors are often on the stack, which is way more efficient. In JS, it creates large numbers of temporary vectors that must be garbage collected.
For my iPad port of one of my Flash games (written in Haxe, so it was actually being translated back into C++), I spent quite a few days profiling the places that were vectors were being created the most, and modifying them to use a pool.
Then some verification code in debug mode checked that there was never a dead vector being written to or read from.
In pathological places with tons of collisions, that got the speed from 2 fps to 30.
Pass.
You can't simulate most imperative programs with functional ones because writing in a functional language eliminates a vast majority of bugs due to incomplete reasoning about memory barriers and other really hard to duplicate issues like race conditions.
CHESS is an amazing piece of software precisely because it CAN simulate race conditions and reproduce them, however, if these things didn't exist no one would ever bother trying to reproduce them.
I'm quite fine not being able simulate these issues.
I do think that prototypes have useful properties, but I'm not sure that a prototype isn't a form of an open class. I tend to think that the biggest problem with prototypes in js is the interface.
...but the OP seemed to indicate that prototypes were "primitive", and it sounds like you agree with him. Are you trying to say something that I'm missing?
@fleitz Whether prototypes are overly complex is neither here nor there. the question is whether they are primitive. More primitive than classes- something which is historically and demonstrably untrue, in my opinion.
Actually it's a rule of hacks, isn't it? If it can exist... https://www.youtube.com/watch?v=QsZrD622qf0
With classes / prototypes (sorry for wibbly wobbly explanation, my CS is not good enough to use the proper terms, which probably exist out there), you can pretend there's a "behaves like" relationship. To simulate a prototype using a class you have to build the freely accessible dictionary and initialisation/cloning semantics level inside of the class.
To simulate classes using a prototype... that depends on your definition of a class. Dynamic dispatch is already there, encapsulation too, subtypes just need a field specifying the name and cloning the right prototype, inheritance is on by default. Self-referencing is usually in there too.
So in my opinion classes can be substituted by prototypes in a large number of cases. Classes however need another layer on top to act like prototypes. So prototypes look like more primitive than classes and classes look like a special-cased version of prototypes. Then again, it's late here, so maybe I missed something obvious...
A prototypical inheritance model can express a larger range of constructs than a class based inheritance model can, and this is normally called expressiveness. Its actually difficult to say which one is more "primative" (by your definition of primative), because they are actually both on a similar layer.
However, speaking solely about the language Javascript, I think it's also fairly clear that in Javascript a prototype is a language primitive that you would use to build a Java-like class construct. Therefore in this context, according to the programming term primitive, prototypes are clearly "more primitive".
It doesn't matter what the Javascript interpreters are doing behind the scenes, because all we care about is Javascript as a language, and what building blocks are available there.
Your use of the word primitive does not seem to logically match the definition of the word provided in the Wikipedia article (admittedly not the best reference for programming concepts), which is why I believe the link was entirely warranted.
And just as a side note, it is entirely possible to be condescending without consciously intending to be.
If I really wanted to prove a point, I could make a string behave like an array. But that would take even more work because an array is a very flexible tool used for a variety of low level purposes.
Therefor, according to your argument, a string is a more primitive data type because it takes more work to make a string act like an array than it does to make an array act like a string. This goes in direct contradiction to the actual definition of a programming primitive.
Back to the original poster's quote, "JSX offers a solid class system much like the Java programming language, freeing the developers from working with the too-primitive prototype-based inheritance system provided by JavaScript."
He is quite clearly addressing a specific case here, which is programmers who want to use Java-like classes when developing in Javascript. A lot of extra work is required if you want to make a Javascript prototype behave like a Java class, with inheritance, etc. So in this context, it is obvious that Javascript prototypes are "too primitive" for the task at hand.
Similar to the way that strings are, in fact, arrays with lots of extra functions for frequently repeated, string-related tasks, JSX classes are JS prototypes with a lot of the oft-repeated boilerplate code done for you. I'm not sure how to make it more clear how the chain of "primitiveness" flows in this case.
A associative array might be considered a language primitive in PHP, but not in C. It is contextually dependent on the language being discussed.
Without speaking about a specific language, you cannot define something as a primitive or not in the strictly programming sense. Once you start talking about comparing two types of constructs in an abstract sense, the word primitive can only be interpreted using the English common usage, and then you are talking about an entirely different concept.
I took this phrase to mean that the prototype construct is "one step down on the composite type hierarchy" from what is needed to emulate as a Java-style class.
Rather, its a good building block but the necessary boilerplate code makes it "too basic" for that purpose. Therefor this developer has created a type further up the composite type hierarchy (or further away from the primitives) to accomplish his goal.
I don't think he's trying to suggest any deficiency in the expressiveness or capability of the prototype construct (he's obviously quite familiar with it to create this language). This is simply a tool for people who aren't familiar with (or don't make use of) that aspect of Javascript to be productive by utilising a more brief, or possibly more familiar (ie Java) syntax.
I presume similar is available in just about any language with decent reflection and/or generics.
This is just absurd. It is claiming it will run faster than JavaScript ... by compiling to JavaScript. If generated JavaScript code would run faster, it just mean the JavaScript code could have been written better in the first place. They probably have logic optimization behind the scene, but clamming it will run faster that JavaScript is just ridiculous.
"The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript."
This is not absurd at all, it has been a proposition made by many languages in the past regarding their target. In fact it's kind of the whole point of an optimizing compiler. Whether its C being turned into better ASM than you'd write by hand, or CoffeeScript being turned into better JavaScript than you'd write by hand, the basic idea is the same. Of course you could theoretically just write the better ASM/JavaScript/whatever yourself, but the point is that usually how to do so is not obvious or not worth your time. If the average programmer's output ends up more performant with your compiler, then the claim is fair.
the compiled JS source of the "hello world" example is only 0.5% of the code needed for the same task by dart. 91 lines vs 17259 lines code.
Besides taking something like "5 lines vs 8 lines for a hello world" and acting as if ALL code bases are automatically that much more bloated via a percentage like that is silly at worst, disingenuous at best.
main() {
print("hello world!");
}
and you know the "17259 lines" thing is FUD.EDIT: The above Dart code currently generates 445 lines of JS with comments and readable formatting. Obviously it's not quite where it needs to be but it's coming along quite well.
It's like the bike shed concept. Anyone can paint a bike shed, but it takes real skill and hard work to build a decent one. It's great to have a nice coat of paint, but the accomplishment wasn't picking the color. That's how I feel about ember.js's website, and the website for all these other client side things with fancy buttons, large web fonts and gratuitous use of space. It's probably a pretty coat of paint, but I doubt I can get efficiently achieve 200,000 datastore operations with speed.
Why, why do we need unnecessary tokens?! Get rid of the stupid :'s.
Maybe period-less sentences are the future Throughout history english has already had many typological changes From a DRY stand-point capitalization and periods contain the same information payload Eliminating one of them would thus be good software engineering Right?
The main problem I see here is figuring out whether a new sentence has been started when a Proper Noun or capitalized pronoun like "I" has been introduced I provide the current sentence as an example of that It's not so hard to figure out from context usually, but I'm sure there are easily constructed cases where the meaning changes based on the period Then again, much of the English language is like that
I'll admit that I did a triple-take when reading through your example. Let's keep periods. :)
Next language please.