text
stringlengths
0
2.35k
[784.96 --> 788.94] Well, I can invent infinity types, right?
[789.38 --> 799.66] So if I can invent infinity types, then that function can take in infinity different types of parameters, which means there are infinity different implementations of that function.
[800.36 --> 806.10] And, you know, the Go compiler is going to figure out how to define actual implementations that take in those actual types.
[806.10 --> 810.82] I don't have to worry about that anymore, which means I don't have to generate code or anything like that.
[811.24 --> 815.06] But now that we have this power and this is immense amount of power.
[815.88 --> 821.62] Now we can start to have things like, say, take the map example.
[822.24 --> 829.78] We can start to have things like a single function called map that can operate on a list of any type.
[829.78 --> 836.62] Instead of before, we had to have a function called map that only could operate on a list of one type.
[837.08 --> 842.48] And we had to repeat the implementation of map over and over and over again for all our different lists.
[843.02 --> 845.50] Now the compiler just does that for us like magic.
[845.78 --> 846.66] Thank you, Go team.
[846.88 --> 850.82] You all gave us this opportunity to save tons of generated code.
[850.92 --> 851.58] And that's amazing.
[852.24 --> 853.84] So that's kind of where we're at now.
[853.84 --> 856.16] The implications of this go beyond map.
[856.86 --> 874.78] But fundamentally, now we're at a point where instead of using interface, raw interfaces, or, you know, the any type now, instead of doing reflection, now we can add compile time proof that certain functions will work for some definition of work.
[875.10 --> 875.20] Right.
[875.62 --> 880.20] We can prove via the type system that certain types of functions will work.
[880.70 --> 881.98] Like map, for example.
[881.98 --> 893.88] We don't have to wonder whether our reflection code or our type assertion on an empty interface does the right thing and figures out the right type of the list and then applies that to the function.
[894.28 --> 908.12] Now we know that if our code compiles, that you've passed in the right function that takes in the right type for the type of elements in the list and you will get back another list with the output type of that function.
[908.12 --> 916.44] So if I'm hearing you correctly, it seems like now, so we're no longer arguing about the benefits of FP, right?
[916.52 --> 923.98] So we've done a pretty good recap of why you'd want to introduce FP or at least know of its usefulness, right?
[924.10 --> 925.32] In certain contexts.
[925.76 --> 931.04] It's about now how easy is it to actually implement in an elegant way and go.
[931.04 --> 932.70] And that's what generic gives us, right?
[932.74 --> 937.72] Because like you said, there were FP libraries and talks and blog posts and everything.
[937.94 --> 939.38] It was possible before.
[940.00 --> 951.38] We just either had to write a lot of boilerplate ourselves or use, you know, go generate to produce, you know, a pile, a variance of a particular function to support the different types as many types as we wanted to support.
[951.88 --> 952.12] Right.
[952.12 --> 957.12] Or we had to do, you know, some voodoo with reflection to get to some type information.
[957.30 --> 957.42] Right.
[957.74 --> 965.16] So now it's about sort of the elegance, right, that we get to leverage, right, with type parameterization.
[965.46 --> 966.66] Let's say that three times last.
[967.26 --> 967.50] Yeah.
[968.90 --> 969.30] Okay.
[969.40 --> 981.62] So if I'm understanding correctly, then some of the libraries pre-generics, is it fair to say that you were going to see a lot of, at least for those who practice FP and are interested in practicing FP and doing FP in Go,
[981.62 --> 985.58] which is something we'll touch on as a separate sort of a thread, right, in our conversation.
[986.18 --> 993.18] So we can expect that a lot of those FP libraries are going to start adopting generics because it just makes the implementation that much easier.
[993.60 --> 993.88] Yeah.
[993.88 --> 1009.22] I think as someone who has written a 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,
[1009.22 --> 1015.86] but also it extends those guarantees to the caller, so the user of the library too.
[1016.46 --> 1028.16] So, you know, like I said, I no longer have to take in an interface or any type and return an any type from, or a list of any types and return a list of any types from map.
[1028.16 --> 1042.82] And since now I can return the type parameter T and then a new type parameter for the return type of the list, well, now those guarantees are extended to my user, the user of the library.
[1043.42 --> 1048.82] And now they can also say, oh, well, my program compiles, therefore my types are right too.
[1048.82 --> 1061.84] 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.
[1062.18 --> 1065.84] They don't have to remember it's one less thing they have to keep in their head, right?
[1065.98 --> 1072.16] That, oh, well, the input should be a slice of ints and return should be a slice of strings.
[1072.16 --> 1081.14] But all a compiler knew about in the past was it's just an empty interface or maybe a little better, a slice of empty interfaces or something like that.
[1081.56 --> 1083.70] It is simplicity, but it is benefit too.
[1084.28 --> 1093.18] So I was looking at sort of the, how Go sort of provides this, or how Go talks about sort of this instantiation, right, of a generic function.
[1093.18 --> 1104.14] So for those who haven't sort of gotten into generic setting 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, right, based on the typeset information you provide.
[1104.60 --> 1113.06] And basically what happens behind the scenes when you compile your code is that Go is going to generate an instance, right, of your function for each of the types you say you support, right?
[1113.18 --> 1121.96] So it's kind of like an actual code generation that basically that we have that provides a type safety, the type checks, right, that the compiler is able to provide.
[1121.96 --> 1128.14] But now the language itself is actually producing that for you behind the scenes and you don't have to actually write your own generators, right?
[1128.34 --> 1133.58] So effectively you're doing the exact same thing you were doing before, except now it's basically baked and supported to the language, right?
[1133.80 --> 1142.54] So this is an efficiency game, right, in terms of you, the programmer, being able to write these libraries, being able to support multiple types of given functions and things.
[1142.72 --> 1147.80] This is an efficiency game, really, not really a game changer for functional programming and Go per se.
[1147.80 --> 1152.38] I think just a more efficient way of writing the functions, basically.
[1152.80 --> 1162.06] 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, right?
[1162.38 --> 1167.50] The empty interface is the set of all types, all possible types in this context.
[1167.50 --> 1174.36] So you could have a function that take in an empty interface and that is a function that can take in anything you can come up with, right?
[1174.50 --> 1179.98] Same thing, it can return if you have the empty interface return and it can be the set of anything.
[1179.98 --> 1188.28] So your task before was write the code to define a subset of all things that your function wants to deal with.
[1188.70 --> 1191.84] Now there is a massive efficiency gain, right?
[1191.94 --> 1203.58] 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.
[1203.58 --> 1213.58] So do you want it to be integral or do you want it to be comparable or do you want it to be stringable or anything else under the sun that we can come up with?
[1214.08 --> 1217.26] You write less than a line of code, right?
[1217.42 --> 1222.26] And maybe you write a new constraint somewhere and then you apply it on your type parameter.
[1222.94 --> 1232.02] And the compiler does what I consider a very advanced and very useful computation for you across your entire code base.
[1232.02 --> 1237.84] And if you're writing a library, across everyone's entire code base that uses it, which is pretty amazing.
[1238.00 --> 1238.38] It's awful.
[1238.76 --> 1239.00] Yeah.
[1239.20 --> 1239.92] That is amazing.
[1258.62 --> 1261.40] This episode is brought to you by Honeycomb.
[1261.40 --> 1263.88] Find your most perplexing application issues.
[1264.18 --> 1271.10] Honeycomb is a fast analysis tool that reveals the truth about every aspect of your application in production.
[1271.58 --> 1275.56] Find out how users experience your code in complex and unpredictable environments.
[1275.86 --> 1280.76] Find patterns and outliers across billions of rows of data and definitively solve your problems.
[1281.20 --> 1282.68] And we use Honeycomb here at Change.
[1282.72 --> 1286.52] Well, that's why we welcome the opportunity to add them as one of our infrastructure partners.
[1286.52 --> 1294.36] In particular, we use Honeycomb to track down CDN issues recently, which we talked about at length on the Kaizen edition of the Ship It podcast.
[1294.62 --> 1295.30] So check that out.
[1295.52 --> 1296.02] Here's the thing.
[1296.26 --> 1299.52] Teams who don't use Honeycomb are forced to find the needle in the haystack.
[1299.52 --> 1302.80] They scroll through endless dashboards playing whack-a-mole.
[1303.00 --> 1306.06] They deal with alert floods, trying to guess which one matters.
[1306.44 --> 1311.64] And they go from tool to tool to tool playing sleuth, trying to figure out how all the puzzle pieces fit together.
[1312.00 --> 1318.32] It's this context switching and tool sprawl that are slowly killing teams' effectiveness and ultimately hindering their business.
[1318.32 --> 1325.48] With Honeycomb, you get a fast, unified, and clear understanding of the one thing driving your business.
[1325.74 --> 1326.16] Production.
[1326.66 --> 1329.16] With Honeycomb, you guess less and you know more.
[1329.56 --> 1334.74] Join the swarm and try Honeycomb free today at honeycomb.io slash changelog.
[1334.90 --> 1338.36] Again, honeycomb.io slash changelog.
[1348.32 --> 1358.32] How do you think you're going to be able to do this?
[1358.32 --> 1368.64] So the Go team has been very vocal and deliberate about advising pretty much everybody to not go gangbusters, which is on other things.
[1369.30 --> 1372.02] Not use it as a hammer with everything being a nail.
[1372.24 --> 1373.68] Just don't spread it everywhere.
[1373.68 --> 1377.20] Where it's a very sort of cautious approach, right?
[1377.24 --> 1383.82] Until some of the best practices start to emerge and still can see the sort of best use cases for generics in Go.