Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> What is the benefit of being functional?

For React, the idea is building the UI as a function of the state. The benefit is to make the code easier to understand, debug, test, etc. I don't think I have to discuss with your the benefits of pure functions.

> If there is a benefit to FP that isn't easily achievable using other styles, then does React achieve that benefit by doing FP style?

I think it does, partially. Though it isn't going as far as something like Elm.

> Or is React leaning on the cachet of FP for marketing purposes?

I would almost say the opposite, React succeeded at first because it didn't push too much the functional stuff. Elm went farther, and doesn't have the market share of React, because insisting too much on FP, especially at that time, would only scare away developers. If you start to go the FP path, at some point you realize that using JavaScript can't work, and you have to switch to something new. People have experience and huge codebases, so they don't want to switch. You can see the same with TypeScript. TypeScript succeeded because it embraced JavaScript, especially its flaws. That means that as standalone language, TypeScript isn't as good as it could be. But as an incremental improvement in the JavaScript ecosystem, it's good, very good.

To see what happens when you use FP for marketing purpose, you can take a look at ReScript, the current reincarnation of ReasonML.



> To see what happens when you use FP for marketing purpose, you can take a look at ReScript, the current reincarnation of ReasonML.

Reason has always felt weird and half-baked. It had all that nice syntactic sugar for the benefit of javascript developers — but in the middle of it, there was some OCaml ugliness, like different math operators for integers and floats, or special treatment of recursive functions. Plus a half-baked async story, or lack of unicode support. It was all very weird.

But in other areas: I understand Swift was a great marketing success, and it is heavily influenced by FP, right (I haven't used it personally, so don't know). And so was Kotlin?


I agree, I like OCaml, I like JS, I'm not a fan of Reason. It just feels off somehow, and half-baked.

From my limited exprience in Swift, it does have functional parts, although I don't know if that's the main focus of the language, or just a nice thing to have.

Kotlin seems a bit more functional than Java, although Java has been catching up recently (sealed classes, pattern matching, record).


> > What is the benefit of being functional?

> For React, the idea is building the UI as a function of the state

Well, if you have state you're already not functional.

Look, React does not have to be functional to be useful! Let's not misappropriate the FP label and apply it to a tech that is clearly not functional, misleading a whole generation of developers.

React is great, hooks are OK, but FP it is not!!


> Well, if you have state you're already not functional.

That's just wrong. State will exist, wether you like it or not, and you'll have to deal with it.

Again, you're using FP to say pure FP. Is Standard ML not functional according to you?


> State will exist, whether you like it or not, and you'll have to deal with it.

Yes, state will exist... in a thin outer layer. Pure core with a thin impure outer layer. If state is distributed throughout the entire program then it is not FP.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: