Live data from Hacker News

Functional programming in JavaScript is an antipattern

hackernoon.com

21–30 of 92 posts

Re: Functional programming in JavaScript is an antipattern

#21

I like Javascript. As a language. It's fun, enjoyable, and I'm productive in it. There I said it. I don't mind exploring interesting avenues like immutability, jsx, typescript, declarative or functional styles. I like that JS has enough flexibility to make all of these possible. I get the fatigue about the endless stream of new frameworks, libraries, approaches, and "new hotness". But I became much more relaxed about…

When you say you like JS as a language what do you mean ? ES5 or ES6 or ES7 or transpiling ?

They're the same language. It's incremental additions without breaking backward compatibility.

This isn't Python we're talking about here ;)

Re: Functional programming in JavaScript is an antipattern

#22

I like Javascript. As a language. It's fun, enjoyable, and I'm productive in it. There I said it. I don't mind exploring interesting avenues like immutability, jsx, typescript, declarative or functional styles. I like that JS has enough flexibility to make all of these possible. I get the fatigue about the endless stream of new frameworks, libraries, approaches, and "new hotness". But I became much more relaxed about…

LISP isn't the ultimate programming language because you can write all others in it. You can write any Turing-complete language in any other.

True, you can write a language parser in any other language.

That's not what I meant. I may have not been clear enough.

Re: Functional programming in JavaScript is an antipattern

#23
post #10

I like Javascript. As a language. It's fun, enjoyable, and I'm productive in it. There I said it. I don't mind exploring interesting avenues like immutability, jsx, typescript, declarative or functional styles. I like that JS has enough flexibility to make all of these possible. I get the fatigue about the endless stream of new frameworks, libraries, approaches, and "new hotness". But I became much more relaxed about…

unfortunately this approach does not scale past single developer or multiple klocs of code unless you're really disciplined, but then wouldn't that cognitive effort be better spent elsewhere?

I get the impression that the OP wasn't talking about a team environment either? I could be wrong...

Re: Functional programming in JavaScript is an antipattern

#24
The author asks WHY hasn't clojure caught on if it is great.

I think I have a better answer than his conclusion that it aint popular because people shun things that aren't popular.

(1) coding when EVERYTHING is immutable by default is a royal pain in the arse.

(2) Coding directly in Abstract Syntax Trees is not pretty, there is a reason why most programming languages don't look like lisp.

Re: Functional programming in JavaScript is an antipattern

#25

Earlier quoted context omitted.

LISP isn't the ultimate programming language because you can write all others in it. You can write any Turing-complete language in any other.

True, you can write a language parser in any other language. That's not what I meant. I may have not been clear enough.

What did you mean?

Re: Functional programming in JavaScript is an antipattern

#26

Earlier quoted context omitted.

When you say you like JS as a language what do you mean ? ES5 or ES6 or ES7 or transpiling ?

They're the same language. It's incremental additions without breaking backward compatibility. This isn't Python we're talking about here ;)

I know that they are the "same" language. But having to maintain transpiled ES5 legacy app kills the joy for me.

Re: Functional programming in JavaScript is an antipattern

#27
>Functional programming in JavaScript is an antipattern

The article then shows ClojureScript as an alternative.

In the comment section Ken Aguilar mentions two other alternatives: PureScript and Elm.

But there are more! Bloomberg's BuckleScript (which is OCaml; possible used on onjunction with Facebook's Reason), GHCJS (Haskell), are two other FP langs that compile to JS. These two have the added bonus of being strong langs for performant server-side programming as well.

http://www.purescript.org/

http://elm-lang.org/

https://github.com/BuckleScript/bucklescript

https://facebook.github.io/reason/

https://github.com/ghcjs/ghcjs

Re: Functional programming in JavaScript is an antipattern

#28
I've been doing FP in JavaScript fulltime for a few years now. I find it much easier than the OOP approach.

My advice to the author is: choose ImmutableJS, Ramda, OR lodash. Don't choose all three.

I think that is his anti-pattern.

> I could be more productive if I didn’t have to wonder things like ... “Should I mutate this variable?”

If you're doing FP the answer is likely 'No.'

Re: Functional programming in JavaScript is an antipattern

#29

The author asks WHY hasn't clojure caught on if it is great. I think I have a better answer than his conclusion that it aint popular because people shun things that aren't popular. (1) coding when EVERYTHING is immutable by default is a royal pain in the arse. (2) Coding directly in Abstract Syntax Trees is not pretty, there is a reason why most programming languages don't look like lisp.

> coding when EVERYTHING is immutable by default is a royal pain in the arse

Not sure I'd agree with that. Scala is a pain to write at times, but it's not because of the immutable data structures--indeed, the APIs are structured such that it's pretty painless. And while under the hood Kotlin's "immutable lists" aren't actually immutable (they're just ArrayLists, the interface is more akin to C#'s IReadOnlyList), the API they present on top of it makes this pretty straightforward.

In both cases, you can do mutable things, but it's extra work.

I tend to think it's more of a Clojure-specific thing, and I think your #2 is more to the point: people don't use Clojure because it looks funny and is foreign to read for people who don't already know Lisps, that's all.

(I've used Clojure, but I don't claim to "know" Clojure. YMMV.)

Re: Functional programming in JavaScript is an antipattern

#30
Funny, but HN oldsters probably remember when functional programming wasn't at all tied to immutable data structures, and when Lisp and derivatives where considered enough functional programming, without every discussion of the topic requiring strictly requiring purity and immutability -- just first class functions, map, fold, and the like.
Post reply on HN