News for hackers. Stuff that matters.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by perfunctory on Sunday July 22, 2012 @03:43AM (#4276720)
The combined man-hours spent on producing various compilers targeting JS would be enough to:

  * Build the next generation browser that supports a proper programming language.
  * Write migration instructions.
  * Convince major web-app providers that they need to migrate.
  * Help with migration.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by jballanc on Sunday July 22, 2012 @03:47AM (#4276728)
Browsers don't need a programming language. Browsers need a standardized bytecode. The problem is, bytecode can have a significant impact on potential performance. So, as long as browsers are still competing on JS performance, they are actively disincentivized from pursuing standardization of a bytecode...
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by lerouxb on Sunday July 22, 2012 @05:38AM (#4276899)
Bytecode on the web is a shitty idea. The minifiers and obfuscators out there are already breaking "view source" and with that the spirit of the web.

Besides: I can't think of language-neutral bytecode projects that ever worked. Remember Parrot?

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by exDM69 on Sunday July 22, 2012 @06:55AM (#4277031)
> Bytecode on the web is a shitty idea.

In my book, some kind of byte code or other intermediate language is a lot better idea than distributing the source code of web apps. There are a lot of disadvantages to delivering programs (for immediate execution) as source code. Note: this is orthogonal to open source and licensing.

So what would be needed is an intermediate program representation that:

  - Is well defined
  - Is a good compilation target from various source languages
  - Is easy to validate for correctness and security
  - Is fast to interpret and compile
  - Distributed in fast to read binary format
  - Suits a dynamic language
In my opinion LLVM IR or CLR bytecode are the most technically suitable alternatives out of existing ones.

The web has quite a long legacy of Javascript and a tradition of supporting deprecated browsers so this kind of revolution is unlikely to happen any time soon.

> Besides: I can't think of language-neutral bytecode projects that ever worked. Remember Parrot?

JVM, CLR and LLVM are all popular compilation targets that are used with dozens of different source languages each. Bytecode and program representation was never the hard part, it's the frameworks of the OS/platform underneath.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by knowtheory on Sunday July 22, 2012 @08:03AM (#4277163)
I strenuously disagree that distributing the source for web apps is orthogonal to open source.

That the web is by default open presents the social dynamics that are quite different than in systems like java applets, which are by default closed.

Open source can exist regardless of whether the web is open or not, but you are kidding yourself if you think whether or not source is distributed with a web page doesn't effect the open source landscape.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by exDM69 on Sunday July 22, 2012 @08:19AM (#4277182)
Today, JavaScript is distributed in minified and/or obfuscated form. And the JavaScript code might have originally been generated by a compiler from a different source language. So calling the stuff your web browser downloads and executes the "source" is not really a valid argument.

Instead, JavaScript is used as a program representation with small size and immediate execution in mind, and it really sucks in that role.

Even if the code is distributed in source code form with white space, identifier names and comments intact (bandwidth isn't cheap, you know), licensing is still the factor that legally determines if it is free software or just open source by default.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by knowtheory on Sunday July 22, 2012 @10:40AM (#4277422)
The ability to figure out how a piece of code works is different than being able to take that code and reuse it elsewhere.

View source is important both for the sake of debugging in the case of 3rd party javascript, and also for the sake of being able to teach others.

Regardless of the minification issue, it's possible to use a code formatter to expand a minified file and at least identify where declarations are being made and what functional behavior is being specified. Minification makes viewing source inconvenient, but that's not equivalent with closed.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by moe on Sunday July 22, 2012 @04:03PM (#4278346)
it's possible to use a code formatter to expand a minified file

If you go to that length you can just as well use a decompiler, no difference.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by beagle3 on Sunday July 22, 2012 @06:03PM (#4278649)
Huge difference.

Minified files, more often than not, have the original identifiers, original code structure (e.g. you know a for from a while ). With a decompiler, you lose all of that.

Google closure is a compiler (and thus loses a lot of this data), but most minifiers are not semantically destructive.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by moe on Sunday July 22, 2012 @06:21PM (#4278701)
Many other minifiers also munge the symbols (e.g. YUI compressor). And why should this process retain anything anyways? If you want your source-code available for download then... put up a download link.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by beagle3 on Sunday July 22, 2012 @07:28PM (#4278850)
> And why should this process retain anything anyways?

Because javascript has some reflection, and also because of weird scoping rules (with, eval, etc.) you can never be sure where a symbol comes from unless you have access to the exact version of every other script on the page, e.g. jquery, etc)

> If you want your source-code available for download then... put up a download link.

I agree - but there is still a huge difference between deminified and decompiled source readbility - which is all I was saying.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by pka on Sunday July 22, 2012 @04:24PM (#4278395)
js minifiers not only remove whitespace, they reorder execution paths, eliminate useless declarations, identify unreachable code [1]. Reformatting a minified js file is not going to produce a much better result than disassembling a distributed binary file would.

[1] https://developers.google.com/closure

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by beagle3 on Sunday July 22, 2012 @06:05PM (#4278658)
Google's closure is a compiler, not a minifier (the distinction being: if it does semantic analysis it is a compiler; although I've never seen a minifier that does even real syntactic analysis -- they all do lexical)
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by masklinn on Sunday July 22, 2012 @07:39AM (#4277123)
LLVM's bitcode is an intermediate representation, not a bytecode (last time I looked at it, you couldn't even move it from one architecture to the next and be sure it worked), and developers of JVM-based language have almost as much work bridging the differences between their language's semantics and Java's (for which the JVM's bytecode exists first and foremost) as they'd need to create a new runtime.

> Bytecode and program representation was never the hard part

Bytecode is very much a hard part if you're trying to support more than a single language, many bytecode have both language and VM semantics leaking in, which essentially makes them even less useful than cross-language compilation.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by exDM69 on Sunday July 22, 2012 @08:14AM (#4277175)
> LLVM's bitcode is an intermediate representation, not a bytecode (last time I looked at it, you couldn't even move it from one architecture to the next and be sure it worked)

Most of LLVM IR is portable, but naturally there are target-specific parts. If LLVM IR was to be used in the web, these target specific parts would be defined for the "web" target. LLVM IR is used in a similar manner in NaCl and OpenCL where it is used as a portable binary format.

> Bytecode is very much a hard part if you're trying to support more than a single language

It's not easy but it's mostly a solved problem. JVM was designed with a single language in mind, yet it's used by dozens of languages today. Similarly LLVM and CLR are widely used.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by beagle3 on Sunday July 22, 2012 @06:25PM (#4278714)
> It's not easy but it's mostly a solved problem. JVM was designed with a single language in mind, yet it's used by dozens of languages today. Similarly LLVM and CLR are widely used.

How is this statement qualitatively different from "JavaScript was designed with human writers in mind, yet it's used by dozens of languages today"?

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by bradleyjg on Sunday July 22, 2012 @02:32PM (#4278093)
It's quite difficult to write a VM target that is fast for both dynamic and statically typed languages. The CLR probably comes the closest but is far from perfect.

Since we have to have legacy support for javascript approximately forever anyway, I'd say the best way forward is to embed a vm from the statically typed world as a target for static languages and leave js as a cross compilation target for dynamic languages.

To avoid nasty cross vm memory leaks you'd probably want to limit interoperability -- at least at first.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by masklinn on Monday July 23, 2012 @05:06AM (#4280167)
> It's quite difficult to write a VM target that is fast for both dynamic and statically typed languages.

It's also nigh-impossible to design a bytecode which does not significantly restrict (and dictate) the semantics of the VM running it. It mandates a bytecode-based VM, to start with (V8 does not use bytecode).

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by tomjen3 on Sunday July 22, 2012 @05:56AM (#4276924)
Only if you assume that view source was ever a good idea.

If the writer wants you to see the source, you can download it elsewere (githun, etc) if not, there is no difference between not getting the source to office 98 and not getting the source to google docs.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by coderdude on Sunday July 22, 2012 @06:16AM (#4276957)
It was certainly a good idea.

When the Web was young and there was no GitHub, viewing a page's source made it so that you could see by example how every page worked. It exposed you to a huge number of possibilities. The Web partially owes its success to this feature because without it far fewer people would have made it to the stage where they could produce their own pages. Every web developer/designer has used this to help them -- guaranteed.

Besides, the feature would have sprung up anyway whether the browser vendors wanted it included or not. Third parties would have stepped in. It's plain text transmitted over the wire. Unlike the source of Office 98 which is not retrievable from the Office 98 binary, a page's source is readily available to the machine that has to cobble it all together when viewing that page.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by JonnieCache on Sunday July 22, 2012 @05:07PM (#4278508)
The presence of the View Source item in the context menu of all web browsers is where many people first interacted with source code. Long may it remain there.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by im3w1l on Sunday July 22, 2012 @06:30PM (#4278728)
Never underestimate the power of sensible defaults.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by icebraining on Sunday July 22, 2012 @05:46AM (#4276912)
I think minifiers and obfuscators already destroyed any hope of learning from websites. But on the other hand, Github and the likes are a much better learning source than we ever had.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by bmj on Sunday July 22, 2012 @08:20AM (#4277186)
With the advent of pretty print in Chrome's web development console (and add-ons available for Firefox), minifiers are less of an issue for learning how a site works.

I suspect that minifier arguments are no-win situations: either someone doesn't like that they can't easily read the JavaScript, or someone complains it takes too long to load the scripts for a given page.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by nilved on Sunday July 22, 2012 @07:16PM (#4278833)
I like sites that have a predictable `.min.js` convention; if I want to see the source code for `main.min.js`, I visit `main.js`.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by batista on Sunday July 22, 2012 @10:53AM (#4277448)
>Besides: I can't think of language-neutral bytecode projects that ever worked. Remember Parrot?

Really? Remember the CLR and JVM?

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by lerouxb on Monday July 23, 2012 @05:53AM (#4280263)
You're right. I should have explicitly specified "aimed at dynamic languages". Compiling dynamic languages to CLR or JVM sortof works, but is less than ideal. And "ideal" (or more suitable, at least) language-neutral bytecode projects have never taken off.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by MatthewPhillips on Sunday July 22, 2012 @12:02PM (#4277599)
Where are the CLR or JVM implementations of JavaScript that run as fast as V8 or Chakra?
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by jfoutz on Sunday July 22, 2012 @01:04PM (#4277781)
I can't speak to the CLR, but the JVM isn't bad at all. http://shootout.alioth.debian.org/u32/javascript.php

But, microbenchmarks, blah blah blah.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by batista on Sunday July 22, 2012 @02:07PM (#4278010)
What that has to do with anything? The post I replied to said that "language neutral bytecode project neve worked" and brought up Parrot as an example. He was not specific to them not working for Javascript.

Now, besides off context, your comment is wrong in four ways:

1) we are not discussing about a bytecode to implement Javascript, but a bytecode to use in browsers for implementing all sorts of languages.

2) There are other lnguages that have been implemented in CLR/JVM that are faster than Javascript.

3) V8 has been optimized by a special team, for millions of dollars, with speed as the #1 target. When that amount of money and effort, a JS running on JVM/CLR can be fast too.

4) A bytecode does not preclude a JIT. In fact it would be trivial to have V8 run a bytecode instead of raw js, just as Python runs pyc.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by MatthewPhillips on Sunday July 22, 2012 @04:27PM (#4278401)
JavaScript is very relevant because there is tons of legacy code that has to run equally as fast in this new bytecode VM as it runs today under the various engines. The choice of VM comes down to how well it works with dynamic languages. JVM and CLR are both modeled after statically typed languages. Microsoft spent quite a bit of money trying to put JavaScript on top of .NET but finally gave up, and today it places it's IE platform on equal footing with .NET.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by double051 on Sunday July 22, 2012 @04:01AM (#4276753)
Bytecode for the web always fails. Remember Java applets and Flash? The great thing about javascript is that it can be hand-written and compiled-to.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by adrianN on Sunday July 22, 2012 @04:42AM (#4276821)
I think the problem with Java applets and Flash was not the bytecode but the slow startup (Java) and the closed source software (Flash) as well as the poor integration with HTML. There is no reason why browsers couldn't implement the same functionality we have now with Javascript using a bytecode based VM.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by jballanc on Sunday July 22, 2012 @04:46AM (#4276826)
Browsers do implement Javascript using a bytecode based VM - https://github.com/WebKit/webkit/tree/master/Source/JavaScri...

It just isn't standardized, or made available to website authors directly (there would likely need to be significant extra security audits before you could contemplate something like that...).

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by doublec on Sunday July 22, 2012 @06:34AM (#4276999)
Not all browsers do this. At least one compiles directly to native machine code. Chrome's V8 does this according to http://stackoverflow.com/a/8819921
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by tomjen3 on Sunday July 22, 2012 @06:01AM (#4276930)
Since you would need backwards compatability, just make an argument to script elementa that specify the byte code to use instead of the javascript. Then older browsers could continue to function and the rest of us don't have to wait.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by wingless on Monday July 23, 2012 @08:31AM (#4280588)
Flash was extremely successful, and it was a really great abstraction. What failed was Adobe's implementation, not the idea.

Same with Java. JVM had (and AFAIK still has) a horrible cold startup time which locked the entire browser up, causing the user to curse profanely.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by egillie on Sunday July 22, 2012 @05:05AM (#4276854)
Are you talking about something like Native Client? http://en.wikipedia.org/wiki/Google_Native_Client
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by jballanc on Sunday July 22, 2012 @05:35AM (#4276894)
NaCl is a side-long step in the right direction, but it gets almost as much wrong as it gets right:

* You have to know what platform you're targeting (ARM vs. x86), which eliminates the browser/JS advantage of architecture abstraction

* You have to recompile specifically for NaCl, which removes any potential benefit on binary reuse

As others have noted, NaCl is closer to ActiveX-reborn than it is to a generic web runtime architecture.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by mistercow on Sunday July 22, 2012 @10:54AM (#4277453)
I think you vastly underestimate the number of man-hours that some of those steps would take. I'm talking specifically about steps 1, 2, 3, and 4.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by perfunctory on Sunday July 22, 2012 @03:14PM (#4278212)
Rumour has it that JS was built in 10 days. How long does one need to do better.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by bzbarsky on Sunday July 22, 2012 @04:54PM (#4278477)
There's a lot more to the browser than JS.

And you don't need to do better than JS in 1995. You need to do better than JS _today_.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by sciolizer on Sunday July 22, 2012 @03:42PM (#4278297)
2, 3, and 4 weren't problems back then
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by gmac on Sunday July 22, 2012 @04:08AM (#4276761)
Nope.

* Lots of people are going to be on current and previous versions of IE for years to come, no matter how many hours you put in.

* People enjoy finding clever ways around constraints, and I'm not sure those same man-hours would be available for your alternative tasks.

* IMHO, JS really isn't so bad.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by mekwall on Sunday July 22, 2012 @04:26AM (#4276787)
Couldn't agree more. perfunctory is ignorant to believe that building a new programming language would solve the problem. Google is trying just that with Dart, and it will take years before it will be adopted by the other browser vendors, if ever.

These micro-languages (that compiles to JS) try to solve the same fundamental problems that exist in JavaScript, which mostly are syntactic or semantic in nature. But there are some solutions and implementations that will likely help further the development of ECMAScript, so the man-hours spent on creating them aren't all lost.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by jodrellblank on Sunday July 22, 2012 @09:19AM (#4277265)
And the combined person-hours spent on many non-essentials (from gardening to sun bathing to gaming) would be enough to solve world hunger, reduce human casualties in natural disaster zones to approximately nothing with notifications and infrastructure reinforcements, detect and stem disease outbreaks in days or hours, provide good public transports in all urban areas, and probably much much more.

Incentives matter.

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by perfunctory on Sunday July 22, 2012 @03:19PM (#4278234)
Great remark. So, what's wrong with our incentives?
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by comex on Sunday July 22, 2012 @04:13AM (#4276768)
Problem is that there is no proper programming language - you will never find one language that even comes close to suiting everyone. Even a VM would be hard to optimize for all the different kinds of languages people would want to run on it, or at least people seem to think so:

http://www.dartlang.org/articles/why-not-bytecode/

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by olavk on Sunday July 22, 2012 @08:46AM (#4277224)
Compilers targeting JS exist because it is possible and because people prefer various other languages. Replacing JS with another language would just mean people would write various compilers targeting this new language.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by VMG on Sunday July 22, 2012 @05:35AM (#4276896)
You can't convince people and companies with man-hours.
Re:Fay -- A proper subset of Haskell that compiles to Javasc... by bzbarsky on Sunday July 22, 2012 @04:53PM (#4278472)
The fact that you refer to "man-hours" makes me suspect you underestimate the magnitude of the problem.

The correct measuring unit for the things you're talking about is man-centuries (and not one, but several), as far as I can see, just for the first item in your list.

People have been making compilers targeting JS for several years now. Do you really think there are 200-300 people doing this full-time?

Re:Fay -- A proper subset of Haskell that compiles to Javasc... by it on Monday July 23, 2012 @11:33PM (#4284251)
Not everyone agrees on what it means for a programming language to be proper, and that's unlikely to change.