Live data from Hacker News

Functional Programming using JavaScript

scott.sauyet.com

41–50 of 88 posts

Re: Functional Programming using JavaScript

#41

Intrestingly it seems that the functional version he proposed is much faster than the OO version. http://jsperf.com/oop-vs-ramda

(Author of that talk (and co-author of Ramda) here. Your perf test only times the parsing of the function -- not exactly fair.

Hey man. Great work.

Re: Functional Programming using JavaScript

#43
post #12

For those you want to learn the functional programming I'd suggest to immedeately commence looking at Ocaml/Haskell instead to see the real big picture. Because it's of course adorable that you can write map and compose in JS (it's 2014, it can do it everywhere), but FP = many more serious things.

While I am currently trying to teach myself Haskell for exactly this reason (understand the "real big picture" in FP), I don't know if there is much harm in starting the journey by exploring some FP concepts in languages one is already familiar with, despite how lacking the language is in that regard. This presentation does point out many features that JavaScript lacks from "true FP" languages.

I, for one, don't know if I would have ever tried to start learning Haskell if I didn't discover some of the benefits of FP first hand through a familiar language.

Re: Functional Programming using JavaScript

#44

Bravo for promoting functional programming and showing how it can be done in JavaScript. One issue concerns me, though: using strings to reference attributes. This makes static checking tools much less useful and can lead to difficult to find errors due to refactoring and typos.

That, I think, is working with the grain in Javascript. It's extremely difficult to do static checking in the language in any case, because in the language `foo.bar` is just syntactic sugar for `foo['bar']`. A FP approach in JS is by its very nature going to be different from one in something more strongly typed like Haskell; this is actually one of the easier differences to swallow.

Re: Functional Programming using JavaScript

#46
post #17

Earlier quoted context omitted.

To be honest, using replaceState for this doesn't seem to make sense to me. A user would probably want to go backward and forward through this using browser history navigation (for instance using the navigation buttons on their mouse). If you're launching a link from a page you expected to come back to, surely opening the link in a new tab would be the way to accomplish this?

Yelp does this with its photo gallery, and it's really annoying. When the user is in a linear sequence such as a slide deck, photo gallery or similar, the "previous"/"next" buttons don't map to the browser's back/forward buttons, they navigate the sequence . Littering the history with the navigation history of this sequence does not make sense. However, it'd be nice if browsers could perhaps record the history (perha…

There's no real distinction. If the slides were implemented as separate pages you would get a new entry in your history as you navigate through each of them. Back doesn't mean to go back to the previous domain; it means the previous page. You don't think the slides should be separate pages, but that would mean you couldn't link to them.

Re: Functional Programming using JavaScript

#47
post #36
post #12

For those you want to learn the functional programming I'd suggest to immedeately commence looking at Ocaml/Haskell instead to see the real big picture. Because it's of course adorable that you can write map and compose in JS (it's 2014, it can do it everywhere), but FP = many more serious things.

Strong agreement. "Adorable" is exactly how I describe it. Even if it's already producing practical advantage in Javascript, it's mostly a cute toy given how it stacks up against "normal" usage. Learn Haskell/OCaml and you'll see how to really take this kind of reasoning many, many orders of magnitude upward. Learn Coq/Agda to see yet another meteoric jump.

While I'm not upset that this has been posted here and has been garnering some attention, this talk wasn't designed for this kind of consumption. I have given this talk to two kinds of audiences:

* In a large corporate office with heterogeneous skill-sets among developers, but where almost all had some experience with Javascript.

* Javascript Users Groups

In each case, the idea was to make the case that FP could offer them practical advantages. The goal was definitely not to teach them FP or to suggest the best FP tool.

There are definitely better languages in which to do FP. But if for whatever reasons you're working in Javascript, I would suggest that a functional style could be useful.

Re: Functional Programming using JavaScript

#48
post #12

For those you want to learn the functional programming I'd suggest to immedeately commence looking at Ocaml/Haskell instead to see the real big picture. Because it's of course adorable that you can write map and compose in JS (it's 2014, it can do it everywhere), but FP = many more serious things.

I've been wondering lately, if we skip performance as a consideration (for example lazy evaluation), what is the difference between functional programming and imperative programming without globals, pointers, mutable variables or shared memory? In other words, would an imperative language without side effects (that could do static code analysis) be any different in practice than FP?

I'm very serious about this, because as far as I can tell, the next best aspect of FP might be first class functions, but those are starting to be used more in mainstream languages (at least the technique of applying transformations on generic data rather than writing special classes everywhere or using templates).

I'm beginning to feel that the real advantages of FP are being obfuscated by unusual syntax. There should be no reason why we can't go from some of the FP notations to the plain old algebra style (x=y) of C-style languages like Javascript. With better references and immutable variables, we should be able to split calculations up over several lines and have the compiler figure out how to optimize it into basically FP code.

P.S. I do know lisp, so I'm asking for a rather more enlightened answer than just to research it further.

Re: Functional Programming using JavaScript

#49
post #46

Earlier quoted context omitted.

Yelp does this with its photo gallery, and it's really annoying. When the user is in a linear sequence such as a slide deck, photo gallery or similar, the "previous"/"next" buttons don't map to the browser's back/forward buttons, they navigate the sequence . Littering the history with the navigation history of this sequence does not make sense. However, it'd be nice if browsers could perhaps record the history (perha…

There's no real distinction. If the slides were implemented as separate pages you would get a new entry in your history as you navigate through each of them. Back doesn't mean to go back to the previous domain; it means the previous page. You don't think the slides should be separate pages, but that would mean you couldn't link to them.

And that's bad. A lot of people pine for the simplicity of the early days of the web, but single-page pagination was arguably even more horribly broken then.

Re: Functional Programming using JavaScript

#50

These slides are very difficult to read on a touch device.

I apologize. I really posted it on my site only as a convenience for myself, not to be published. I never really considered anything but projection at the time. Although I can view it on my fairly large phone, the experience is not great.
Post reply on HN