Live data from Hacker News

Beautiful JavaScript – Functional JavaScript

feederio.com

11–20 of 59 posts

Re: Beautiful JavaScript – Functional JavaScript

#11
post #2

"Given that JavaScript’s author was recruited to do “Scheme in the browser,”" Didn't he disclaim that multiple times?

Just to be clear the prototypal inheritance came from Scheme, but the funcational aspects of JavaScript came from Lisp. Scheme's influence on JavaScript was, at the time, indeed an open question. On the other hand they absolutely told Eich not to do anything that resembled Lisp. JavaScript was to be Java's little brother and it had to look like and mostly act like its big brother. Eich made it work like Lisp anyways thinking they wouldn't notice given the incredibly short development window and the fact that as long as there was an inheritance concept it would satisfy the "feel enough like Java bit".

Of course nobody noticed JavaScript had influences from Lisp. It was buggy when it initially rolled out and it took a couple of revisions before nested functions were supported. This is backed up by David Flanagan's book "JavaScript: The Definitive Guide", which doesn't mention nested functions and closures until its third edition in 1998, because JavaScript didn't have closures until then. Whether it was a missing feature or due to a defect is something you would have to ask Eich directly.

Re: Beautiful JavaScript – Functional JavaScript

#12
My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10.

Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the matter is that JS doesn't support 99% of the modern tools that actually make functional programming useful and not just a parlor trick. JS is missing everything from ADTs (possibly the single best thing to come out of early functional languages) to a type system. There are a few bolt-on structural type systems available (like Typescript), but they still don't get you even close to the full power of modern functional languages.

Re: Beautiful JavaScript – Functional JavaScript

#13
post #12

My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10. Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the m…

Sure statically typed functional languages are enjoying a lot of success right now, but there are still plenty of LISPs in the playing field like Clojure that can't be discounted as parlor tricks. You might disagree with them philosophically, but it doesn't change the fact they're being used in production.

What bothers me more about JS as a functional language is the lack of tail call optimization. While it's in the ES6 spec, last I heard there was some question of whether it would actually be implemented for web browsers.

Re: Beautiful JavaScript – Functional JavaScript

#14
post #2

"Given that JavaScript’s author was recruited to do “Scheme in the browser,”" Didn't he disclaim that multiple times?

Just to be clear the prototypal inheritance came from Scheme, but the funcational aspects of JavaScript came from Lisp. Scheme's influence on JavaScript was, at the time, indeed an open question. On the other hand they absolutely told Eich not to do anything that resembled Lisp. JavaScript was to be Java's little brother and it had to look like and mostly act like its big brother. Eich made it work like Lisp anyways…

Scheme is a lisp, so this is a rather confusing statement.

In fact as lisp dialects go, Scheme is typically more functional than Common Lisp.

Re: Beautiful JavaScript – Functional JavaScript

#15
post #12

My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10. Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the m…

OK, so "Haskell > Scheme", or some such. Any specifics beyond "ADTs", which I assume means Abstract Data Types - interfaces/polymorphism.

If IDEs ever get good enough to do near complete type inference, including reading through partial function application, and perhaps an "extract/move function" refactoring that converts closures to parameters, most of the class/type bondage and discipline may look a bit like a waste in retrospect.

Having worked in both static and dynamic type systems since the 80s, I've developed a bit of a "cringe" mechanism at the repetitive code that usually comes out of "strongly" typed languages. "This time it's different", but it never seems to be :-(

Re: Beautiful JavaScript – Functional JavaScript

#16
post #12

My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10. Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the m…

Just exposing people to a few basic patterns from functional programming will 1) encourage them to learn a real functional programming and 2) help them write better code.

Learning Haskell or Clojure or something is a big task, especially if you're doing it just because you're curious what all this functional programming is about. Everyone understand JavaScript, so being exposed to functional programming there is not a big deal.

And I love writing JavaScript with a bit of a functional lean to it. I think it makes it much easier to reason about the code. Of course it's not purely functional, but it's still better than if I wrote it the way many people do.

Re: Beautiful JavaScript – Functional JavaScript

#17
post #12

My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10. Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the m…

Just exposing people to a few basic patterns from functional programming will 1) encourage them to learn a real functional programming and 2) help them write better code. Learning Haskell or Clojure or something is a big task, especially if you're doing it just because you're curious what all this functional programming is about. Everyone understand JavaScript, so being exposed to functional programming there is not…

Or, alternatively, they just say "Hmm, this functional programming stuff doesn't seem very interesting or useful at all. Totally overhyped. Well, back to working with Blub."

"Functional" JavaScript is better than regular JavaScript in the same way that bloodletting is better than homeopathy; not much. Perhaps you've fallen into the same trap I'm talking about; do you think you're reaping any significant benefit from functional programming when you apply these sorts of practices to your JavaScript code?

Re: Beautiful JavaScript – Functional JavaScript

#18
post #12

My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10. Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the m…

OK, so "Haskell > Scheme", or some such. Any specifics beyond "ADTs", which I assume means Abstract Data Types - interfaces/polymorphism. If IDEs ever get good enough to do near complete type inference, including reading through partial function application, and perhaps an "extract/move function" refactoring that converts closures to parameters, most of the class/type bondage and discipline may look a bit like a wast…

> Any specifics beyond "ADTs", which I assume means Abstract Data Types

No, I meant algebraic data types, although interfaces/typeclasses are great as well.

> If IDEs ever get good enough to do near complete type inference, including reading through partial function application,

I don't use any IDEs, but Haskell does this. I imagine various Haskell plugins do as well.

> and perhaps an "extract/move function" refactoring that converts closures to parameters,

I'm not sure why you want this so much, but it does exist. I've done this exact thing with Idris's interactive UI.

> I've developed a bit of a "cringe" mechanism at the repetitive code that usually comes out of "strongly" typed languages.

If there is one phrase that I would use to describe Haskell, it's "zealously anti-repetitive". If the Haskell community sees you writing the same line of code twice, they'll swoop down and beat you over the head with a well-designed typeclass until you stop repeating yourself.

Re: Beautiful JavaScript – Functional JavaScript

#19
post #13
post #12

My concern with all these "functional javascript" posts is that people might (understandably) leave with the false impression that this is what functional programming looks like in general. It's like if you tried to get someone into cars by having them drive a Hyundai i10. Regardless of whether you think JavaScript qualifies as a "functional language" just because it supports higher-order functions, the fact of the m…

Sure statically typed functional languages are enjoying a lot of success right now, but there are still plenty of LISPs in the playing field like Clojure that can't be discounted as parlor tricks. You might disagree with them philosophically, but it doesn't change the fact they're being used in production. What bothers me more about JS as a functional language is the lack of tail call optimization. While it's in the…

It will be, and has been implemented in some browsers. The only hiccups were regarding the behavior of stack traces with TCO.
Post reply on HN