Live data from Hacker News

Functional programming in JavaScript is an antipattern

hackernoon.com

41–50 of 92 posts

Re: Functional programming in JavaScript is an antipattern

#41

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…

You are right, it is great that there are endless options and styles to choose. A good chunk of the work is already done for probably every project imaginable! It's nice, especially for personal projects. And for multiple developers, well, at that point it's just a nice exercise in working with others to decide which framework(s) to use :)

Yes, in some environments you don't get to choose, but why blame the language for that?

Re: Functional programming in JavaScript is an antipattern

#42

What has happened to Javascript is the same thing that happened to other fundamental high-level languages before them. It has changed from a high-level language to an assembly language just like C and Java. Of course you canb choose to live in the past and keep on hand-rolling your Javascript just like others do with C and Java, but the world has changed. In today's world we write our code in a high-level language an…

> It has changed from a high-level language to an assembly language just like C and Java.

Neither C nor Java are assembly languages. What are you trying to express here?

> No matter how much you like C or Java or Javascript, it is always faster, more efficient and more reliable to write in a truly high-level language that incorporates the best knowledge of the latest research in Computer Science.

> always faster, more efficient > truly high-level > best knowledge > latest research

I uh.... what?

Re: Functional programming in JavaScript is an antipattern

#43

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.

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

Is it really? Because I haven't noticed writing my Erlang.

Re: Functional programming in JavaScript is an antipattern

#44
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.

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".

Re: Functional programming in JavaScript is an antipattern

#45

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…

A Lisp is a good lightweight way of expressing things. You can write a Lisp with any language. The main plus of a Lisp is that you are not burdened by Syntax and boilerplate. You can use Metaprogramming in an unconstrained way. We have Lisps written in most popular languages.

Python has Hy (newest Lisp on the block), Java has Clojure (currently the most popular one), Erlang has LFE (For BEAM just like Clojure is for JVM), Most scheme (kinda like lightweight lisp with a 100 variants) interpreters are in C. What does that make them? Nothing more than what they already are.

What makes Lisp a Lisp is Functional Programming and Syntax where the program itself is treated as Data (Very good for easy macros that transform like a Transformer) and S-Expressions (Every thing is an S-Expression). Not because you can write all others in Lisp.

Re: Functional programming in JavaScript is an antipattern

#46
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.

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.

I've always thought that functional programming is about structuring your program in functions and their composition (as opposed to classes) - nothing to do with immutability either.

As for JS, I've read "Javascript: The good parts" one day and realized that I can do everything I want using just functions and closures - it's really elegant imo. (even use this approach in Python sometimes)

Re: Functional programming in JavaScript is an antipattern

#47
post #37
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.

I think the reason is rise in CPU power - immutability has a processing cost, but it makes things easier for programmers. This is a general trend in programming languages over decades - higher abstraction (easier for programmers) but harder for compilers to optimize. For example, Common Lisp has two versions of list functions that modify list - one that returns a copy and another that returns mutated original list. (…

Common Lisp has all this stuff because it comes from a tradition of writing efficient code in Lisp itself, where code can be anything from a file system, network stack, theorem prover, graphics toolkit, to itself ... It is already its own implementation language where a programmer might want to control some aspects of memory allocation.

Other languages delegate this stuff to the implementation language/runtime, for example Java/JVM.

Re: Functional programming in JavaScript is an antipattern

#48
Not well reasoned. Mostly of the complaints boil down to 'not knowing' whether a given piece of data is mutable or not.

If you're doing FP with immutable data, there is no ambiguity: you never mutate. Doesn't matter which language you're in, nor whether the data-structure is mutable or not (e.g Redux mostly uses normal mutable JS objects, with the spread operator to avoid mutation when returning a new state).

Re: Functional programming in JavaScript is an antipattern

#49
post #34
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…

To add to the list: F# has a JS transpiler via fable http://fable.io/ (Elm and its architecture has even been recreated to a degree - https://github.com/AnthonyLloyd/Elm )

I believe Elmish is the current best Elm architecture for fable: https://fable-elmish.github.io

Re: Functional programming in JavaScript is an antipattern

#50
post #46

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.

I've always thought that functional programming is about structuring your program in functions and their composition (as opposed to classes) - nothing to do with immutability either. As for JS, I've read "Javascript: The good parts" one day and realized that I can do everything I want using just functions and closures - it's really elegant imo. (even use this approach in Python sometimes)

[deleted]
Post reply on HN