Live data from Hacker News

Functional programming in JavaScript is an antipattern

hackernoon.com

51–60 of 92 posts

Re: Functional programming in JavaScript is an antipattern

#51
post #3

The flagged comment was accurate - post claims FP in javascript is an antipattern, but then says FP is the most sane way to write javasript. Ergo author is claiming javascript is an antipattern, tldr clojurescript. /shrug

JS is an antipattern for itself.

Re: Functional programming in JavaScript is an antipattern

#52
post #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.

Agreed--being able to define functions for control flow & data transformation seemed functional enough (compared to having to rely on primitive reserved words).

Of course, even then, C was functional by that definition (as long as you could remember where the parens & asterisk went when defining your function!)...so what do I know.

On the other hand, if you have the attention span and interest, Li Haoyi has an interesting (and, in its conclusion, useful) take on this topic:

http://www.lihaoyi.com/post/WhatsFunctionalProgrammingAllAbo...

Re: Functional programming in JavaScript is an antipattern

#53
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 think this is one of the most sensible questions to ask wrt. JS (except where you have no choice but to use it).

Re: Functional programming in JavaScript is an antipattern

#54
I think the biggest weakness in the ecosystem is that it's cumbersome to map between different approaches to immutability. I'd like to be able to use clojurescript for some stuff, reason/bucklescript for other stuff, and immutable.js for still other stuff without having to jump through hoops when passing immutable data around.

Are there immutability constructs in flow or typescript that would allow libraries to conform to a type interface for conversion?

Re: Functional programming in JavaScript is an antipattern

#55
post #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.

Language is a tool for communication, and the great strength of English is that it is defined by consensus. Words shift in meaning.

Re: Functional programming in JavaScript is an antipattern

#56
I hate the arrogance of announcing that thousands of developers' work is an antipattern. This post contains valid discussion of some of the shortcomings of FP-in-JS, and presents alternatives. That's fine. But everyone has their own priorities and tradeoffs. The downsides of adopting Clojurescript in my current situation would outweigh the benefits.

> Clojure compiles to Javascript... So any Javascript job could be a Clojurescript job

That's not how it works.

Re: Functional programming in JavaScript is an antipattern

#57
post #36
post #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 stron…

Elm is nice. Really really nice. It make it very intuitive and straightforward to write well architectured front end code. The compiler tells you straight away when something is wrong. I have recently started playing with Bucklescript and am really loving it. There is bucklescript-tea which is a port of the Elm architecture to OCaml. So not only do you get the goodness from Elm - intuitively well architectured applic…

Curious question: Why did you choose Typescript over Flow? Flow's type system is better designed. Also, Flow's annotations are really optional, as in: Generating JS from Flow means throwing away the annotations. Nothing else, no code generation at all.

Re: Functional programming in JavaScript is an antipattern

#58

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.

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

I think it is, but I'm biased :). Still, I don't think this is the reason. I believe it's simply because, due to accidents of history, C won the popularity contest, and most languages followed with (incrementally altered) C syntax to stay close to what's popular.

Re: Functional programming in JavaScript is an antipattern

#59
post #36
post #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 stron…

Elm is nice. Really really nice. It make it very intuitive and straightforward to write well architectured front end code. The compiler tells you straight away when something is wrong. I have recently started playing with Bucklescript and am really loving it. There is bucklescript-tea which is a port of the Elm architecture to OCaml. So not only do you get the goodness from Elm - intuitively well architectured applic…

> Another worth mentioning is Typescript.

Sure it's worth all mentions (and so is Flow), but they do not specifically promote FP. And that's the topic of the article we're discussing :)

Re: Functional programming in JavaScript is an antipattern

#60
post #44

Earlier quoted context omitted.

I was taught in university that functional programming means using functions as first-class-values, so function can get other function as a parameter. That's all. You can write functional code with assembler if you want. Immutability is just another design choice with its pros and cons.

Not sure why you're downvoted. That's literally the way I learned it first, too. Functional "can use functions as values".

Functional programming is also a family resemblance thing: you can't necessarily give a strict definition, any more than you can define "blues music".

I'd say functional programming is a tradition that draws from sources like denotational semantics, lambda calculus, Church, Landin, etc etc.

There are some different subspecies of functional programming: the Lisp family that draws from AI engineering, MIT, Emacs, actor research via Scheme, etc; the ML family that draws from typed lambda calculus, inductive definitions, and logical proof systems; and more, like concatenative languages.

JavaScript was always inspired by functional programming, as evident by Eich's claim to have tried to sneak in a variant of Scheme dressed up as Java. I always use lots of anonymous functions, higher order functions, and nonmutating transformations in my JS, without using any special immutability libraries, and I'm pretty happy with it.

Post reply on HN