text
stringlengths
0
2.35k
[1825.30 --> 1835.72] 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.
[1836.18 --> 1839.28] You might return the same slice with the new results.
[1839.42 --> 1841.74] That's also sometimes legal as well.
[1841.74 --> 1846.76] But let's just say for sake of logic, we're returning a new slice with new results.
[1847.26 --> 1849.52] Well, we're iterating through a list.
[1849.58 --> 1850.50] So that's a for loop.
[1850.86 --> 1852.00] That's just what it is.
[1852.14 --> 1852.26] Right?
[1852.64 --> 1853.86] We can write a for loop.
[1854.08 --> 1855.22] And that's the imperative way.
[1855.28 --> 1862.48] It's telling the machine to go through the list one by one, call this function every time, put the result into a new list.
[1862.48 --> 1868.10] Or the other way is someone else did that for you, and you just call map.
[1868.62 --> 1870.52] And that's the kind of declarative way.
[1870.98 --> 1877.06] Because when you call map, you're effectively saying, like with SQL, you're saying this is the data that I want back.
[1877.52 --> 1884.66] With map, you're saying I want a new list back with the results of the old list applied at the function that I gave to map.
[1885.14 --> 1885.38] Right?
[1885.44 --> 1886.48] And that's pretty much it.
[1886.48 --> 1887.38] Right?
[1887.48 --> 1907.98] So when we think about this question of should we get more features of FP into language, into code bases that are mainly go code bases, the way that I think about it is would this code base or this part of a code base, would it benefit in some way from more declarativity?
[1908.52 --> 1911.42] I think I may have made up that word declarativity.
[1913.50 --> 1914.28] But it works.
[1914.28 --> 1915.92] I think people know what I mean.
[1915.92 --> 1916.10] Right.
[1916.28 --> 1917.82] Would it benefit in some way?
[1918.50 --> 1922.44] And there are a lot of possible ways that declarativity can help.
[1923.00 --> 1925.00] It can reduce lines of code.
[1925.66 --> 1927.18] It can add structure.
[1927.92 --> 1929.30] It can add readability.
[1929.74 --> 1932.26] It can also reduce readability if you're not careful.
[1932.46 --> 1933.48] So that's a tradeoff.
[1933.86 --> 1935.42] It can fix bugs.
[1935.42 --> 1938.60] Like if you have an error in one of your for loops.
[1938.60 --> 1942.80] This happens a lot with parallel and concurrent code.
[1943.12 --> 1947.96] And thus also code that deals with channel sends a lot too.
[1948.06 --> 1949.06] I've seen that a lot as well.
[1949.34 --> 1954.30] So it can reduce bugs because you're just getting someone else's code that did it the right way.
[1954.30 --> 1955.12] Right.
[1955.12 --> 1960.86] So if you think about it in this way, and this is where I start with any code base.
[1960.86 --> 1970.22] I always start, okay, well, is there code in here that we can reduce by using the declarative features of FP?
[1970.22 --> 1974.72] Whether it's maps or reduces or filters or zips and so on and so forth.
[1975.40 --> 1988.56] And as a quick anecdote to close that thought out, I have seen filter as one of the most valuable tools to next tools to take and put into code bases.
[1988.56 --> 1997.70] Because tons and tons of code has for loops that reduce down into selectively taking things out of a list and putting them somewhere else.
[1997.90 --> 1997.94] Right.
[1998.10 --> 1998.68] And that's filter.
[1999.14 --> 1999.26] Right.
[1999.88 --> 2000.26] Awesome.
[2000.48 --> 2000.74] Awesome.
[2001.32 --> 2002.28] Yeah, I can definitely see that.
[2002.36 --> 2005.52] I think at least for me, it's a mindset shift.
[2005.66 --> 2005.80] Right.
[2005.86 --> 2009.58] So like I don't have a reason not to use FP.
[2009.72 --> 2009.86] Right.
[2009.90 --> 2015.72] Or not to bring some of the ideas or not really, or I should say not to think FP first.
[2015.72 --> 2016.02] Right.
[2016.04 --> 2018.64] In terms of how do I approach, how do I solve this problem?
[2018.82 --> 2019.02] Right.
[2019.04 --> 2023.60] Like I'm so used to the way I'm used to doing it.
[2023.62 --> 2023.78] Right.
[2023.78 --> 2031.76] So it's more of a sort of a, I think maybe education and maybe sort of a seeing more people talk about it, present about it.
[2031.96 --> 2036.88] And having, you know, shows like this where people knowledgeable like yourself come on and sort of advocate for it.
[2037.08 --> 2043.10] I think it's more of a sort of a education issue more than the merits of it.
[2043.10 --> 2046.74] Because all these things you're talking about here, these are things that make my program safer.
[2047.02 --> 2050.12] They make, you know, my programs easier to understand.
[2050.44 --> 2050.84] Right.
[2050.88 --> 2056.48] And obviously, like as with everything in programming, we sprinkle things where they make sense.
[2056.48 --> 2057.34] Yeah.
[2057.34 --> 2066.70] And if your team at work is not using sort of FP style for things, and perhaps they want to or don't want to, so don't force it kind of thing.
[2066.82 --> 2074.46] But I think every once in a while, even using your example, like Filter, for example, that I see the use case for it, not that you mentioned it.
[2074.48 --> 2075.52] I see that everywhere.
[2075.96 --> 2079.24] It could definitely be used in a lot more places.
[2079.90 --> 2082.92] And maybe, who knows, maybe that sort of triggers somebody to say, hey, what's that?
[2082.92 --> 2084.94] Like, I've never seen this particular approach, right?
[2084.98 --> 2087.14] And then, boom, that's a brown bag launch right there.
[2087.14 --> 2090.48] You can educate some coworkers around the merits of FP.
[2090.64 --> 2098.20] 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.
[2098.30 --> 2110.50] Is there anything missing in Go to nudge us even more towards sort of the, I don't want to say traditional FP, because I don't think we want to make an FP language per se.
[2110.68 --> 2116.62] But is there missing features in Go that would allow us to even take even more advantage of FP concepts?
[2117.14 --> 2120.26] Well, it's so generics are young.
[2120.48 --> 2123.88] And FP using generics is even younger.
[2124.40 --> 2134.36] So really, the best I can do to answer that is hypothesize based on very, very unscientific things like gut feel and things I've seen and anecdotal evidence, right?
[2134.36 --> 2146.22] I think the biggest thing that could unlock just making the building these things a little easier would be type parameters on methods of a struct, right?
[2146.22 --> 2148.30] Or a type, right?
[2148.64 --> 2149.98] So you can't do that now.
[2150.10 --> 2156.52] So you can't have, let's say you have a custom list type that's a list of type T.
[2156.52 --> 2165.58] You can't have a method called map on that list that takes a type parameter U and then returns a new list of type U.
[2166.28 --> 2168.04] You can still build map.
[2168.14 --> 2169.94] I have done it and I know others who have done it.
[2169.98 --> 2171.10] I've seen it all over the place.
[2171.30 --> 2172.26] You can still build it.
[2172.54 --> 2173.56] It has the same effect.
[2173.56 --> 2175.56] And it works the same.
[2176.26 --> 2194.66] The reason that I'm hypothesizing that type parameters on methods would make things easier is because for many folks who are trained using Java or C++ or other pure, what I'll call pure object-oriented languages, although whether they're pure or not is another podcast.
[2195.04 --> 2198.24] Pure in air quotes for those not watching.
[2198.62 --> 2199.14] Air quotes.
[2199.30 --> 2199.54] Yeah.
[2199.70 --> 2200.60] Thank you for that call.
[2201.10 --> 2202.32] Definitely in air quotes.
[2202.32 --> 2217.62] Folks who are trained with the classical OOP type of programming, the OOP design patterns and methodology, having a method on a struct feels a lot like a method on a class in Java.
[2217.92 --> 2219.92] It's not strictly the same.
[2219.92 --> 2247.62] But for folks who are used to thinking of methods, if you have a method, quote unquote, again, air quotes, if you have a method, air quotes on your list struct in Go, well, it makes more sense to do it that way rather than to do it the more kind of pure, again, air quotes, pure FP way, which woul...