Live data from Hacker News

The JavaScript Problem

haskell.org

111–120 of 183 posts

Re: The JavaScript Problem

#111
I wrote (the start of) this page. Please bear in mind this is the Haskell community. We like our static types. This page is also kind of old news (2 years old) for us, the discussion is over, really. But I'll describe the history of it for those interested.

So I wrote this paragraph (http://www.haskell.org/haskellwiki/The_JavaScript_Problem#Ot...) in 2012 in a reply to a reddit comment. Around that time the Haskell community was growing in its web dev circles, and we as a community were cultivating a sense that writing our web apps was not fun in 50% of the task, which was the front-end.

There were actually a bunch of alternative attacks.

* Using so-called widgets which are compiled by Haskell and contain very minimal pieces of JavaScript that the user of the library never sees. This is okay. But if you're developing something more complex, you start to wish you were back in Haskell.

* Some were also thinking, perhaps it's just the framework that makes this work awful, we just need to pick the right reactive-MVC kind of framework.

* Use HJscript, an EDSL of JavaScript embeded in Haskell. This is not bad, I used this in hpaste and it's still running today: https://github.com/chrisdone/lpaste/blob/master/src/Hpaste/V... However, you're still left with the semantics of JavaScript, it doesn't really improve upon it. Although, if you're interested in this approach, definitely checkout Sunroof https://github.com/ku-fpg/sunroof-compiler which is like a new and improved version which has continuations out of the box.

* Some thought maybe CoffeeScript was enough, but it quickly becomes obvious that the problem is nowhere near syntax-deep.

In the end, I think everyone pretty much agreed just using Haskell would be better. But there were no viable transpilers, so we were continuing with JavaScript feeling that things could be better.

After that I decided to start trying out the bitrotted crop of compilers. I tried GHCJS first, and reported my findings: http://chrisdone.com/posts/ghcjs The first couple paragraphs are now on the wiki. I thought this community "feeling" should be documented, and copying “The Expression Problem”, thought it would be catchy to make a “The JavaScript Problem” post that is concise, opinionated and comprehensive. Ask any random Haskeller and they will pretty much agree with both paragraphs. It's easy to point someone to a wiki article to have a common understanding of the problem.

I'm not one to simply whinge about things, however. I wrote down alternatives and tried a few out myself. I experimented with GHCJS (above) and UHC (here http://chrisdone.com/posts/uhc-javascript) and HJScript. Eventually, unsatisfied, I wrote the Fay compiler: https://github.com/faylang/fay/wiki which was inspired by the simplicity and small output of Roy and the FFI in UHC, and was a success (to some degree) because it was super easy to setup and its output was understandable. We're using Fay at FP Complete for the IDE, we have about 16k lines of code in Fay.

In parallel, the GHCJS codebase got a new set of very active maintainers, the Haste compiler appeared http://haste-lang.org/ and generally the community started to feel “hey, not only is compiling to JavaScript practical, but we're starting to feel this should become standard web dev in Haskell.” If you look at the crop of Haskell web frameworks (big three are Yesod, Snap, Happstack) they all support compiling via Fay and I'd expect haste, too.

I see some comments in this submission that the Haskell community is "snobbish" and "complaining". We're apparently among the people who “wish JavaScript was something else” and we shouldn't be one of those people, that we just don't really “get” JavaScript and how to write it properly. We want a car because we don't appreciate how to ride a horse properly. I'd say the opposite. Here we saw the problem (as we saw it), and started working on practical solutions and now people are getting paid to write Haskell that runs in the browser. If that's not putting money where your mouth is, I don't know what is.

Also look at the OCaml community with http://ocsigen.org/js_of_ocaml/ (also an inspiration for my endeavors) and the Clojure community with https://github.com/clojure/clojurescript They identified the same problem and got to work. :-)

Since I added that wiki article, a bunch of new compilers and languages have been added to the page (or invented). For the chorus of people asking "why isn't X listed?", it's simply because users contribute to the article, it was much smaller. So if you've heard of another approach, and, importantly, if you've tried it and can report practicality, please go ahead and add it. I think I'll add Opa to the list, it's like Ur in that you write front-end and backend code in the same language.

Re: The JavaScript Problem

#112

I take issue with the paragraph about how Javascript sucks: * Javascript is actually untyped, not weakly typed (untyped means no type declarations, not that it has no types) and I don't see that as a problem. * Being an entirely interpreted language, JS cannot have static type checking. This has not been an issue in my experience. * I think the syntax argument is laughably ridiculous. Programming languages that live…

On the `this` feature: This is mostly a "problem" with the DOM-interface, which is not part of the language. But there is even a solutions for this in JS: Object.handleEvent() -- Why is everyone complaining on the lack of a feature that is in fact already built in? Just start using it ... Also, since functions and objects are first class entities, you may just store references and make use of them as you like. (But, please, don't use "var self = this;", since `self` is already a predefined variable pointing to the global object.)

Re: The JavaScript Problem

#113
post #97

I'm surprised that lack of module system is the first thing brought up. Is that really such a big deal? It's very much just a nice to have for me and has plenty of third-party implementations if you want it.

It's just another annoying thing on the list of warts with Javascript that make maintain a large codebase a pain in the arse. Plenty of third party implementations is half the problem. Want to import a module by somebody using a different module format? More pain in the arse!

It's similar in the Scheme community. It's easy to write your own module system. So every compiler and every second Schemer has their own module system with its own quirks and assumptions.

Re: The JavaScript Problem

#115
post #26

I'm surprised that Haxe isn't in the list of alternatives. It's been around for quite a long time and it's very mature: http://haxe.org/doc/features

Oh, interesting. What's it like to use? Please add it to the article. I'm adding Opa now.

Re: The JavaScript Problem

#116
post #21

I take issue with the paragraph about how Javascript sucks: * Javascript is actually untyped, not weakly typed (untyped means no type declarations, not that it has no types) and I don't see that as a problem. * Being an entirely interpreted language, JS cannot have static type checking. This has not been an issue in my experience. * I think the syntax argument is laughably ridiculous. Programming languages that live…

Could you clarify on `this`? I find how it works very obvious and natural to me, therefore not quite sure why everyone consider it broken and not 'different'?

The problem appears to be, some tend to get confused, who is the caller and who is the callee. For this, please just consider that the DOM-interface is not part of the language, but just -- as the name suggests -- an interface to a separate environment. From the point of view of the DOM, the element is the callee, which applies itself to a callback function (the event-handler). Makes quite some sense.

In case you've issues with this, you may just use `Object.handleEvent()`, and the this-object will be your object (or function). Why is everyone complaining about this behavior, but no one is using the built-in feature that would be the perfect solution to the problem?

Re: The JavaScript Problem

#117
post #5
post #3

Earlier quoted context omitted.

It's a wiki. You are free to add this information. =]

Did you not read my last sentence? I'm actually not free to add the information. There's a special registration process that requires human intervention. If the Haskell Wiki didn't require me to e-mail somebody personally and ask for permission to register, I'd be much more inclined to provide a one-of edit. By the time this person gets back to me (he's probably in Europe), I'll have neither the time nor inclination…

Good point, it was full of spam and registration was closed. I forgot about that. It was because we had a really old MediaWiki version so it was actually unsafe to allow anyone untrusted to post on it due to exploits possible at the time. I say “we”, I don't have access to manage haskell.org. I'mma ping the mailing list to see about fixing this.

Re: The JavaScript Problem

#118
post #79

Earlier quoted context omitted.

The issue is that the "compile to" thing shouldn't be another programming language at all. It should be something like Java bytecode. Except not actually Java bytecode, because Java bytecode was made specifically for Java. You want something designed to be an intermediary representation between code in any arbitrary language and native instructions for any arbitrary architecture. In theory you could use Javascript as…

If you think about it, bytecode you wish just doesn't exist, whereas JavaScript does and it works: http://mozakai.blogspot.co.at/2013/05/the-elusive-universal-...

The point is that we have something that sucks, not that we don't have anything at all.

Re: The JavaScript Problem

#119
post #5
post #3

Earlier quoted context omitted.

It's a wiki. You are free to add this information. =]

Did you not read my last sentence? I'm actually not free to add the information. There's a special registration process that requires human intervention. If the Haskell Wiki didn't require me to e-mail somebody personally and ask for permission to register, I'd be much more inclined to provide a one-of edit. By the time this person gets back to me (he's probably in Europe), I'll have neither the time nor inclination…

I think spam was exactly the problem.

It's a shame and seems to really hurt. There's a lot of outdated information in the wiki and I suspect the obstacle to making fixes is a big contributor.

Re: The JavaScript Problem

#120

> lack of module system ES6 fixes this with, well, a module system. > weak-typing, Yup, this is a problem. > verbose function syntax, ES6 fixes this with arrow functions. > late binding Does this just mean dynamic typing? Well, yes, JavaScript is dynamically typed, but I wouldn't call that a language flaw. Static vs. dynamic typing is a tradeoff. > which has led to the creation of various static analysis tools to all…

> Again, I wouldn't say it "sucks" for this reason, just that it's dynamically typed. That's a tradeoff. This is the Haskell wiki. I would expect most participants to view having a single global implicit union type to be a flaw , not a trade-off .

Best languages allow both type systems with dynamic being opt-in.
Post reply on HN