text
stringlengths
0
2.35k
**Aaron Schlesinger:** That's crazy, yeah...
**Johnny Boursiquot:** Okay, so if I'm understanding correctly, then some of the libraries pre-generics - is it fair to say that you are going to see a lot of -- at least for those who practice FP and are interested in practicing FP, and doing FP in Go, which is something we'll touch on as a separate thread in our conv...
**Aaron Schlesinger:** Yeah. I think, as someone who has written library to do a bunch of FP things - yeah, I saw not only did it make the implementation easier in the form of less code and more guarantees at compile-time about types, but also, it extends those guarantees to the caller, so the user of the library, too....
So this is like a domino effect of benefits that if a user is using someone's FP library, or even rolled their own, now they know that "Well, my types are right." They don't have to remember -- it's one less thing they have to keep in their head, that "Oh, well, the input - it should be a slice of ints, and return shou...
**Johnny Boursiquot:** \[18:04\] So I was looking at this, how Go talks about this instantiation of a generic function... So for those who haven't gotten into generics yet in Go, pretty much when you create a generic function, what you're basically saying is that you're going to support a number of types based on the t...
So this is an efficiency game, in terms of you the programmer being able to write these libraries, being able to support multiple types of given functions, and things... This is an efficiency game really; not really a game-changer for functional programming in Go per se, just a more efficient way of writing the functio...
**Aaron Schlesinger:** Yeah, that is a really great point, is that everything we can do now, technically, you could do before, because we had the empty interface. The empty interface is the set of all types, all possible types in this context. So you could have a function that took in an empty interface, and that is a ...
So your task before was write the code to define a subset of all things that your function wants to deal with. Now, there is a massive issue again, because now you can constrain a type parameter and have the compiler compute for you whether a given type, for a type parameter that has constraints on it, is legal. So do ...
**Johnny Boursiquot:** That is amazing.
**Break:** \[20:41\] to \[22:39\]
**Johnny Boursiquot:** So the Go team has been very vocal and deliberate about advising pretty much everybody to not go gangbusters which generics on all the things, right? Not use it as a hammer with everything being a nail; just don't spread it everywhere. It's a very cautious approach, until some of the best practic...
**Aaron Schlesinger:** Well, that is good advice for all software, I think. So yes, the answer to your question is yes. There is no telling right now whether map is enough. Or no one wants to use it. And if people do want to use map, there's no telling whether the parallel version of that is better, or complementary to...
\[24:22\] So these things should be tried... Maybe we should go a little crazy, as they say, as the Go team has said, a little overboard, to see what is possible... But we should not say that this is the result, this is the solution to all problems in FP. We should get these things out there, play around with them, exp...
**Johnny Boursiquot:** So piggybacking off of that, the thread that we paused and now I want us to resume - you see what I did there...? \[laughs\]
**Aaron Schlesinger:** I do, I love it.
**Johnny Boursiquot:** The idea of -- basically, the when to use generics, and in our case here, when to use functional programming... I think that's a fair question to ask, regardless of generics. So one of the strong gripes that I found out there, that I've heard even in talking to some folks, is that, look, Go is im...
**Aaron Schlesinger:** Well, it's already here. Anyone who uses context is using a part of FP, right? Because context has a -- with cancel and with timeout, those return a function. This is how pervasive FP is. That is technically a higher-order function, because with cancel is a function that's returning a function th...
And I think, like all technologies that are used by more than a trivial number of people in the world, a corner of this technology is used a lot, right? SQL is as another good example here. You can do many, many things with SQL. You can turn Postgres SQL, or PostgreSQL... I think that's how you say it, right?
**Johnny Boursiquot:** Yeah, yeah... I'll allow it... \[laughs\]
**Aaron Schlesinger:** \[27:53\] Yeah? Okay. It's got the Johnny stamp of approval... So you can turn PostgreSQL into a time-series database, if you want to, for example, right? By using very advanced features of SQL. But not many people do that, because obviously, a lot of times it's not the best tool for the job. But...
So if you need to capture some state of a function, and expose one operation on that state to the caller, using a higher-order function makes a lot of sense. It's a lot easier than doing a bunch of boilerplate, and building a whole struct, and storing the state in the struct, and having a bunch of methods on it. And th...
Now, I'm going to modify your second question a little bit, accordingly... You said "Should we be trying to get FP into more workloads?" Well, given that it's already in a lot of places, I'm going to modify it and say, "Should we get more features of FP into more workloads?" Will you allow that? \[laughter\]
**Johnny Boursiquot:** Yeah, let's do it. Yeah, tell me more.
**Aaron Schlesinger:** Alright, so now we've got the seal on that, alright... So the way that I think about it is trying to model it as the imperative/declarative difference, I guess. There's a fundamental difference between imperative and declarative. You can see it with SQL versus Go, right? Because SQL, you say, "De...
Now, in the FP world, let's just take this map example I keep using. So with map, the intention is to take a function, apply it onto every element of the list, the slice, and then return a new slice with the results. You might return the same slice with the new results. That's also sometimes legal as well. But let's ju...
So when we think about this question of "Should we get more features of FP into codebases that are mainly Go codebases?" the way that I think about it is "Would this codebase (or this part of a codebase) benefit in some way from more declarativity?" I think I may have made up that word, declarativity...
**Johnny Boursiquot:** \[laughs\] It works.
**Aaron Schlesinger:** \[31:53\] Yeah. I think people know it. We did benefit in some way. And there are a lot of possible ways that declarativity can help. It can reduce lines of code, it can add structure, it can add readability... It can also reduce readability if you're not careful, so that's a trade-off... It can ...
And so if you think about it in this way - and this is where I start, with any codebase. I always start "Okay, well, is there code in here that we can reduce by using the declarative features of FP?" Whether it's maps, or reduces, or filters, or zips, and so on, and so forth.
And as a quick anecdote to close that thought out, I have seen filter as one of the most valuable next tools to take and put into codebases, because tons and tons of code has for loops that reduce down into selectively taking things out of the list and putting them somewhere else. And that's "filter".
**Johnny Boursiquot:** Awesome. Awesome. Yeah, I can definitely see that. I think, at least for me, it's a mindset shift. I don't have a reason not to use FP, or not to bring some of the ideas... Or I should say, not to think FP-first in terms of "How do I approach, how do I solve this problem?" I'm so used to the way ...
So for me, I think it's an education thing more so than capabilities or features... Which kind of leads me to my next question. Is there anything missing in Go to nudge us even more towards the -- I don't want to say traditional FP, because I don't think we want to make go an FP language per se... But is there missing ...
**Aaron Schlesinger:** Well, generics are young, and FP using generics is even younger. So really, the best I can answer that is hypothesize based on very, very unscientific things like gut feel, and things I've seen, and anecdotal evidence. I think the biggest thing that could unlock just building these things a littl...
\[36:05\] You can still build map; I've done it, and I know others who have done it, I've seen it all over the place. You can still build it, it has the same effect, and it works the same. The reason that I'm hypothesizing that type parameters on methods would make things easier is because for many folks who are traine...
**Johnny Boursiquot:** "Pure" in air quotes, for those not watching.
**Aaron Schlesinger:** Air quotes, yes. Thank you for that call-out. Definitely in air quotes. So folks who are trained with the classical OOP type of programming, OOP design patterns and methodology, having a method on a struct feels a lot like a method on a class in Java. It's not strictly the same, but for folks who...
So really, I'm gonna just limit it to the type parameters on methods thing, because that thing is not very controversial, but higher-kinded types or higher order types are a very interesting and cool thing that I really do wish was in Go, because it would enable some very slick FP things.
**Johnny Boursiquot:** Yeah, that doesn't sound controversial to me. I can see that.
**Aaron Schlesinger:** Some might. Maybe some people will.
**Johnny Boursiquot:** \[laughs\]
**Break:** \[39:35\] to \[41:12\]
**Johnny Boursiquot:** Okay, so before we transition into unpopular opinions, maybe I want one of those controversial ideas... \[laughs\]
**Aaron Schlesinger:** Okay...
**Johnny Boursiquot:** Alright, let's get it going.
**Aaron Schlesinger:** I'm not gonna give one that talks about higher-kinded types, because it's been a while, first of all, so I don't think I would do it justice, or maybe even get some parts incorrect... Also, it would take me a while. But I want to mention one pattern from FP that I think is really great, and it's ...
Now, the first function takes no parameters and returns the result, the data; it might take one parameter if the data is multi-dimensional, like a map, and you want it to specify a key... And that's up to you; that's part of the design pattern. And then the setter potentially takes in the dimension of the data, again, ...
So if you could kind of imagine how these functions would be created, they would probably be closures. They would close over your data, they would take some parameter... Let's take the get case, for example - it would take the parameter for the thing to get, and then they would return the value of it. Same thing with t...
It's a fancy term called a lens, but it's a fairly basic, foundational thing. And that is a common theme in FP, actually. So I call this the lens, and it is in Wikipedia, and it's in the textbook, and everything... But it just boils down to functions, like most things in FP do. They just boil down to one or more functi...
\[43:59\] So I would challenge everyone listening to just give it some thought. Can that reduce code somewhere in your codebase? If you have a bunch of getters, can you get rid of those getters and just replace them with a closure, the lens? That's a very interesting one to me, because it is exceptionally simple... I'l...
**Johnny Boursiquot:** Very cool. I'd love to see that in action, like in practical use. The way you explain it, it sounds great. That sounds like something I'd be up for.
**Aaron Schlesinger:** There you go, yeah.