Check out a free preview of the full Hardcore Functional Programming in JavaScript, v2 course

The "Refactoring to Point Free Style" Lesson is part of the full, Hardcore Functional Programming in JavaScript, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Brian demonstrates how to refactor functions using the point free style, explains that it allows parallelization and a better data processing workflow thanks to the high level declarative syntax.

Preview
Close

Transcript from the "Refactoring to Point Free Style" Lesson

[00:00:00]
>> Okay, faster car, fastest car, excellent. I'll rename this. All right, what's happening here? So we start by sorting the car and the horsepower, all right? Let's go ahead and start a composition here. And we'll do this first and I'm not gonna do prop, yeah, I am. Whatever.

[00:00:22]
[LAUGH] We're having a good time. And then we're gonna get the last, right, we got sorted, gets passed in into last, great. Good times. And then, uh-oh, what's happening here? We're gonna add is fastest to the name. Okay, so we have to get the prop name. And then we're going to concat and this is, lame.

[00:00:53]
I went through this a little bit earlier. But you know these helper functions that just magically pop out of nowhere to help you solve the problem are all in the Ramda docs. I was just counting on myself to introduce them before you got here. If I didn't, I apologize.

[00:01:08]
Looks like we're not quite there, spaces. Look at that. It put it on the beginning, not the end. So check this out. [LAUGH] That's the theme of the day. [LAUGH] Wait, let's do this. We're gonna flip concat and apply that with that. That's fine. That's great. Who wants to piss off their co-workers?

[00:01:32]
>> [LAUGH]
>> So why don't we make a append, right? And we'll call it that. There we go. And this is a little bit more digestible. This is your application logic. You want to bubble up all the the primary business like process workflow through this composition and it kind of keeps you at a high level declarative kind of syntax where you're forced to think about data flowing through your pipe, right?

[00:02:07]
And also staying at the same level of abstraction. Like if I jumped in here and twiddled a bit, right, and I said like xx, modulo two and did some weird stuff. [LAUGH] You would see that over in a large procedural function. Here we're kind of restraining ourselves or constraining ourselves to this declarative syntax.

[00:02:29]
A few other words on that is that this compose does not specify order. We know that it's going to go right to left but the compiler, the language rules does not really know how it's it's actually calling these functions under the hood. We have a lot of freedom and parallelization.

[00:02:45]
And that's why we're able to just rely on Ramda or Lodash to just fuse those two for us. I wrote two loops in a row. So I'm gonna figure it out. You can make it optimized and they do. And that's awesome. If you're writing two for loops, you have to go back and manually figure out what's happening in the middle of these loops and things to be able to combine them.

[00:03:08]
So it's really nice this high level declarative is where writing applications, we'll go back to our example here. Hopefully, this one that was this what we're gonna be doing today makes sense now a little bit. So maybe not the bottom line yet, but we'll talk about that. But this is where this high level application specification starts to pay off with just reading a pipeline, it wrangles control flow, it gets rid of state, you're making generalized things that aren't specific to their names, and you have tons of freedom in implementation underneath.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now