What is point-free style?

Point-free style is a way of defining functions with a very simple constraint: you cannot name arguments or intermediate values. How can you possibly do that? Well, with higher-order functions, of course. For instance, with function composition, you can define a new function without naming the arguments. Some languages, like the APL family, or Haskell, let you do this very easily. ►► Audio, Video, and Transcript available: https://lispcast.com/what-is-point-fr... ►► Subscribe on iTunes: https://itunes.apple.com/us/podcast/t... Transcript What is point-free style, and does it have a point? By the end of this episode, you'll know what point-free style is. How you might already be using it and why it makes things hard to read sometimes.Hi, my name is Eric Normand and I help people thrive with functional programming. Point-free style, it's an important term because you might come across it when you're reading about functional programming, or in a discussion with someone who is into functional programming.It's good to be familiar with it. It's also an important style for programming, because it helps you think at the right level of abstraction. These things are good to name. This is where my head is.That said, it's not like once you learn this, you should be doing point-free style everywhere. Except maybe as an exercise. It is not "The last style" that we should be learning, it's nothing like that.What is point-free style? It means you're programming in a way that you don't need to name your arguments or name any of your intermediate values. When you define a function, normally, you have to name the arguments. Most languages require it, or they make that the really easy way to define a function.Likewise, when you're in the body of the function, you're writing what this function does. Often the easiest way to use the result of calling a function is to save it to a variable, and then pass that variable to the next function. Use it later in the expression.Point-free style says, "Can we do without that? Naming is hard, it takes a lot of room. It's a line per variable. Maybe we don't want to do that?"How do you do this? The easiest example to really hit home is, let's say you're calling map, and you're calling map with something like toUpperCase, the function toUpperCase. On a list of strings, you're mapping toUpperCase over those strings.One thing you could do is you could define...you're calling map, you're passing in a function, so you're going to define a new function, give it an argument, maybe call it S because it's a string. Then you call toUpperCase on that string and return it. Why did you wrap toUpperCase in a new function? It already is a function. You could just pass that toUpperCase function directly. It already takes one argument, it already returns the right value, why would you wrap it up a lot? I mean, just my personal experience, I see a lot of JavaScript programmers doing this. A lot of JavaScript code seems to unnecessarily wrap functions up in other functions. I don't know why it's common there.I know in some cases you need it because the map passes both the value and the index, and you'd want to ignore the index. There's reasons for some of it but a lot of times it's unnecessary.Removing that extra layer where you have to name the argument and just pass in the function itself, it's a way to achieve point-free style. Point-free style has a bunch of little techniques that remove the need for arguments, one little step at a time until you got no arguments. That's the point-free.You could have point-less, point-minimal style where you have one or two arguments left maybe. It seems like a spectrum, that's what I'm trying to say. It seems like a spectrum, you can get down to point-free style, but you could move along in that direction.Another one that we've already talked about in a previous episode is function composition. Function composition in the general case is, you have two functions, you want to take the return value of one and pass it to the other.So you make a new function, it takes the arguments, passes them to the first function, saves the return value then calls the second function with that return value, then calls the second function with that return value, and then returns it.Well, there's a special case where the second function only takes one argument. The return value can go right in there. You don't even need to wrap it in a new function that you write explicitly. You can put all that boilerplate into another function, a higher-order function that takes two functions and returns a new function.