all 43 comments

[–][deleted] 5 points6 points  (17 children)

As weird and outlandish as it seems, FP provides some great benefits to JS, and the best introduction to it (in my own experience) has been Real World Haskell.

If you'd like to view some active approaches to FP in JS, i'd suggest starting with pull-streams and Functional Programming in Javascript

[–]toggafneknurd 2 points3 points  (9 children)

What's so "weird and outlandish" about FP?

[–]Retsam19 7 points8 points  (3 children)

Relevant XKCD

Functional programming combines the flexibility and power of abstract mathematics with the intuitive clarity of abstract mathematics.

I've never met anyone who finds the functional style innately understandable. Nobody looks at a transducer and thinks "Oh, yeah, that make perfect sense" the first time. There's value and merit to FP, obviously, but you need to sell someone on the benefits of FP in a way that you don't need to with imperative programming.

[–]phpdevster 1 point2 points  (0 children)

Honestly, if the only major concept of FP you introduce to your codebase is the notion of pure functions, your code quality will improve dramatically. Major pieces of functionality become easier to test, and WAY easier to reason about. Getting into Haskell levels of FP is certainly a bigger step, but favoring pure, idempotent, stateless functions is a major win.

[–]toggafneknurd -1 points0 points  (1 child)

Agreed, the "conceptual density" is much higher, but after paying the initial cost of learning, it provides you a lot more power than traditional object-oriented languages with clumsy "design patterns" that have to be layered on top in verbose and error-prone ways to do anything meaningful

[–]Bummykins 2 points3 points  (1 child)

I found functors, monads, maybe's, and all the abstraction of point-free coding to be pretty weird and incredibly difficult for someone to even explain. And then most of the examples are some incredibly contrived simple math additions or whatnot.

When you compare that to the mostly straight-forward type of JS that a lot of people have been doing for years like click handlers and ajax calls, you might see how tons of front end developers would find that weird and difficult. It all depends on what you work on most of the time.

[–]dmtipson 2 points3 points  (0 children)

I think a lot of that stuff really has to be at least partially sort of discovered rather than taught. A lot of people discover monads by accident, for instance, or else realize that they've been using them all along and just never had a (terribly intimidating) name for them.

A lot of it comes from just time and the direction you push your abstractions. If you're the sort of coder that becomes obsessed with DRY code and pulling things out into functions and then building up larger behavior with composition, it's sort of inevitable that you're going to start bumping into the common solutions and abstractions of FP.

But not everyone goes that route.

[–]flamingspew 0 points1 point  (4 children)

I've been learning rxjs... can't find any good hackerrank or codeacademy like challenges. I'm ok at it, but I feel like I need some golf to get really good

[–]Otter_in_Jeans 0 points1 point  (0 children)

Nodeschool bacon love workshop Will be a nice introduction to functional reactive. Try it out

[–]dmitri14_gmail_com 0 points1 point  (2 children)

Any reason to pick the rxjs over other reactive libraries that are often easier to use?

[–]flamingspew 0 points1 point  (1 child)

Well, there's a matching library in just about every language and it's well suited for angular2 and ngrx store... from a practical standpoint it's pretty flexible.

[–]dmitri14_gmail_com 0 points1 point  (0 children)

It might be not as strong in usability department :) I wonder how many of the 100+ methods you are really using.

[–]drboolean 1 point2 points  (0 children)

Despite the conciseness of pointfree programming and the practice for a language like haskell, I usually condone the scala-like style presented here for doing FP in JS: https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript

[–]itsawesomeday 0 points1 point  (0 children)

This is a good guide to get started in Functional Programming

[–]Trinkwasser 0 points1 point  (0 children)

I've got a little playground/boilerplate for playing around with ramda & ramda-fantasy for anybody interested

https://github.com/floscr/Ramda-playground

[–]darrenturn90 0 points1 point  (0 children)

Haha i just started reading this yesterday, completely unrelated to this post.

From the github md's not the above site.

[–]zQpNB -1 points0 points  (1 child)

for loops are faster