10 ms·
I highly recommend reading this article. Although it does point out one reason that JS is a poor language to be the foundation for client-side web computing:
by kenjackson 16y ago
I highly recommend reading this article.
Although it does point out one reason that JS is a poor language to be the foundation for client-side web computing: It's extremely difficult to optimize a language this dynamic. I honestly think we could be leaving 50% perf improvement on the floor due to the dynamic nature of the language.
And this is on top of the fact that you already have to reduce the amount of time spent optimizing since you don't compile the code ahead of time (most optimistically using a JIT of some sort).
Can we please move away from JS and move to a nice IL?
- jbjohns 16y ago>Can we please move away from JS and move to a nice IL? A thousand times this. The web is playing a bigger and bigger role in computing but IMO it's hamstrung a bit by having it's "assembler" Javascript. I think a lot of developers are just going to use some other language that compiles to Javascript anyway, why not give us an "assembler" option.
- xiongchiamiov 16y agoWell, Silverlight claims to give me the ability to write client-side Ruby and Python, but the last time I tried Moonlight it consistently crashed Firefox...
- _stephan 16y agoSilverlight != Moonlight
- rbanffy 16y ago> I think a lot of developers are just going to use some other language that compiles to Javascript anyway That's a disgusting thought... What happens is usually developers who don't want to program in more than one language (or One True Language, as many of them may think) rely on such tools to generate an unreadable, sub-optimal and utterly messed up tangle of JavaScript code that kills a baby jesus every time it runs. And who then blame JavaScript for their problems. And downvotes anyone who disagrees with them ;-)
- dkersten 16y agoPeople using CoffeeScript aren't doing it to use a One True Language for everything. [People using node.js however.. ;-)]
- nickik 16y agoThats just stupid you can make good source to source compiler that compile to better make faster code then a normal dev would do.
- rbanffy 16y agoFine. Name one anything-to-JavaScript compiler that generates better, faster code than a "normal" developer would do. I assume we have different interpretations of what's normal.
- jsvaughan 16y agoGWT
- rbanffy 16y agoHave you ever read GWT-generated code? Have you ever debugged it?
- jsvaughan 16y agoyeah and i have been working with gwt for years. faster code is not maintainable code, which is precisely why a mechanical optimizer makes sense. You wouldn't try to work directly with your minified js would you? But you do minify it, because it is a better experience for your users.
- rbanffy 16y agoMinifying the code does not optimize it in any way. It just makes it more compact (and less readable). I am not sure we are talking about the same thing here. What we are talking here is you inputting Java (and the most readable Java code is not that readable to begin with) into utterly unreadable JavaScript that's also less efficient than what a human experienced in JavaScript would be able to write and larger than the minified version of whatever that experienced human would be able to write.
- nickik 16y agoYou don't get the problem that needs solving. JS is hard to optimize so even if you compile to it from a other language you going to end slow because of the bottelnack of JS. If we had a IL that is good to optimize language that compile to we could get to much faster speeds in the browser.
- _stephan 16y agoI think you didn't get the point of jbjohns post. You're just restating his message (more clearly, though). Did you maybe overlook the 'hamstrung' and the 'why not give us an "assembler" option' at the end?
- liuliu 16y agoI don't think that it is possible to replace JS with a nice IL in near future due to the momentum it gathered all these years. However, is it possible to suggest a strict subset of JS that is easier for interpreter to optimize on? If that can be done, I am happy to write code with less flexibility but can run thousands faster.
- evanrmurphy 16y agoNeat idea. Which subset of the language could be better optimized by interpreters?
- roel_v 16y agoSubset is hard to define I think, it seems that would have many repercussions. I like JoachimSchipper's suggestion above, that adds a construct in which the programmer promises not to do any funny stuff to certain variables so that the optimizer can go to town on the optimization on them.
- sid0 16y agoSo like ECMAScript 5 strict mode?
- roel_v 16y agoLooks something like it, I didn't know about it. I don't know if it will protect against the things that are mentioned in the article though, the descriptions that I've (admittedly only cursory) read don't say that the things that mentioned in the article aren't allowed anymore under strict mode (like the Object.prototype.valueOf = function() example given). Maybe it is, in which case this would be great it seems. Not that I have intimate knowledge of it, but still ;)
- JoachimSchipper 16y agoYou can get most of the benefits of not being ridiculously dynamic without switching to a new language. Take a look at http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html#Definition_of_declare http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html#Defini...: Gambit Scheme (a Lisp) has a (declare (block)) form to tell the compiler that all variables defined in the current file will not be overwritten outside the current file, and a (declare (standard-bindings)) form to tell the compiler that the standard Scheme functions are not overwritten. With proper use of these options, Gambit is quite fast. Javascript could have a "fixate foo bar qux" command that did something similar. Of course, for best results, it would need to fixate the current foo bar qux, as Javascript frameworks seem quite keen on overriding the standard functions. I'm sure it would be a pain to implement, but...
- rbanffy 16y ago> JS is a poor language to be the foundation for client-side web computing > I honestly think we could be leaving 50% perf improvement on the floor Unfortunately, humans have not got significantly faster (or smarter) in the last couple thousand years, as opposed to computers, that get twice as fast every 18 months or so. Dynamic languages, by placing the burden of optimization on the compiler/runtime are making the right bet. Static-typing is little more than a human doing the machine's work, often at the expense of introducing subtler bugs (the compiler catches the obvious mistakes and that may leave programmers with a false sensation of security). > Can we please move away from JS and move to a nice IL? As for moving to precompiled, possibly obfuscated scripts, I would much rather concede a little less dynamism on the language and move the compiler into the browser. You could, conceivably, declare the type of arguments and return values and rather easily, in that case, perform some optimization as the code is parsed. I have no love for JavaScript. It's a little tortured language that I am sure passed through a lot more marketing specialists than needed before taking its current form and bears the scars from that process. It has, however, some good parts that are very good.
- sid0 16y ago> Static-typing is little more than a human doing the machine's work Interesting. I look at (good: e.g. ML or Haskell) static typing as the machine doing the work that a human would have to do in a dynamic language. Especially type inference.
- rbanffy 16y agoThere are cases when it makes sense to use static typing or, at least, to stick to certain types for input and output. In my experience however, those cases are not many and doing it when you don't have to creates unneeded complexity.
- sid0 16y agoThere are cases when it makes sense to use dynamic typing (e.g. dealing with XML and friends). In my experience however, those cases are not many and doing it when you don't have to creates an unneeded burden on the programmer. (sorry -- this is probably not to HN's taste, but I just wanted to show how an entirely different perspective can also be valid)