[00:00.000 --> 00:15.720] Okay, thank you. We have to stay on our schedule. So our next speaker, Rona, she stood here [00:15.720 --> 00:21.160] three years ago, but before the pandemic was a thing, and she gave us a challenge to solve [00:21.160 --> 00:24.680] the go diversity problem within a year. Rona, is it solved? [00:24.680 --> 00:36.560] As far as I can tell, yes. Well done. Well done. No, no. So actually, Marty has stole [00:36.560 --> 00:41.560] this from me because, yeah, three years ago, I did challenge this forum to solve the problem [00:41.560 --> 00:49.600] of lack of diversity within the Go community within a year. And then the pandemic hit and [00:49.600 --> 00:59.600] it seems that these issues kind of took aside, were pushed aside, unfortunately. But we can [00:59.600 --> 01:07.800] start again. So I'm here to talk to you today about a lighter topic is Go object oriented. [01:07.800 --> 01:13.920] Now, it appears to be something that people have many opinions about. And I hope that [01:13.920 --> 01:22.480] you do too because that will be fun. So I am Rona. I am a Google developer expert for Go. [01:22.480 --> 01:27.480] I create workshops. That's kind of like my thing when I want to teach something. I make [01:27.480 --> 01:35.760] a workshop about it. And in 2022, I kind of realized that after a few years of seeing [01:35.760 --> 01:43.000] developers struggling with different paradigms around the Go typing system, specifically [01:43.000 --> 01:47.800] with interfaces, I figured why not create a workshop about it. And I submitted it to [01:47.800 --> 01:56.120] Go for Con Europe. It was the name of the Go workshop was object oriented design with [01:56.120 --> 02:07.040] Go. And then the comments started coming. So something between object oriented is dead. [02:07.040 --> 02:20.080] Somebody posted a comment on my tweet and then blocked me. Because apparently that's [02:20.080 --> 02:29.360] how the internet works. So, yeah, and somebody blamed me for introducing Spring into Go. [02:29.360 --> 02:35.320] Now, I have been a developer for 20 years, but I have not done any Spring in my life. [02:35.320 --> 02:46.120] And that is such a specific accusation. I was fairly surprised. So I am not here to promote [02:46.120 --> 02:54.160] my workshop, even though I am giving it again this year in Berlin in June, because that [02:54.160 --> 03:04.320] will be bad. So what is object oriented programming? So it's the idea of separating [03:04.320 --> 03:11.720] software into things or objects or concerns or instances and adding some functionality [03:11.720 --> 03:20.280] to them usually called messages or methods or member functions. So that we can work [03:20.280 --> 03:25.080] with software in a more intuitive way, the way that we understand how we interact with [03:25.080 --> 03:34.160] the real world. That's it. Now, where there are things, it can get incredibly messy. That's [03:34.160 --> 03:43.800] the business model behind Marie Kondo. Yeah. I felt the sigh. You don't have 14 items maximum [03:43.800 --> 03:53.880] in your house. You're not alone. And we have this lovely quote from Joe Armstrong. The [03:53.880 --> 03:59.040] problem with object oriented languages is that they've got all of this implicit environment [03:59.040 --> 04:04.320] that they carry with them. You wanted a banana, but what you got was a gorilla holding a banana [04:04.320 --> 04:15.480] and the entire jungle. And that feels like it does. It really does. So gone really went [04:15.480 --> 04:22.080] a different way. It tried to sort of stay away from this. But we will see what remained [04:22.080 --> 04:29.680] and what actually remained from this and what actually we were able to let go of in a second. [04:29.680 --> 04:34.040] So we're going to hold a trial where we're going to check. You're going to be the jury. [04:34.040 --> 04:38.160] You're going to decide if Go is object oriented. I'm going to try and convince you. I'm going [04:38.160 --> 04:42.280] to show you the arguments for both sides. And I'm going to have to convince you that [04:42.280 --> 04:52.200] it is object oriented or I am responsible for defamation. I am taking the goes good name [04:52.200 --> 04:59.720] and dragging it through the mud, tarnishing it, hurting its reputation. You're the jury. [04:59.720 --> 05:08.360] You will decide. So disclaimer, this is not a real trial. But and I'm the judge and the [05:08.360 --> 05:12.960] rules are what I say they are, which is to say that these proceedings are going to be [05:12.960 --> 05:21.320] ridiculous. But yeah, we're just going to have to do it. So what have we come to expect [05:21.320 --> 05:27.080] from an object oriented language? Most of you know this by heart, really. We have classes [05:27.080 --> 05:34.160] because classes and only classes can have methods. Classes can also have these constructors. [05:34.160 --> 05:56.480] Classes are created, allowed to create objects safely. And we also expect inheritance. Objection. [05:56.480 --> 06:05.480] So in go, we don't have classes. And therefore we don't have constructors. But we pretend [06:05.480 --> 06:12.400] to have them. So here's where we pretend to have something. Now this one is quite fun. [06:12.400 --> 06:20.280] So this is a package that I created. And you can see here that inside type robot, the Godoc [06:20.280 --> 06:24.880] aggregated nicely, a function called new. Now you can see that it doesn't actually have [06:24.880 --> 06:31.120] a receiver. It's not a method. It's not anything. And it's just a package level function that [06:31.120 --> 06:37.160] the Godoc understood to be a constructor. And then he added it where it should be nicely [06:37.160 --> 06:43.360] nested inside the robot type. Which is really interesting because what that means was that [06:43.360 --> 06:49.480] the Go team essentially decided at some point that safe construction of objects is a tooling [06:49.480 --> 07:00.920] problem, not a language problem. It's interesting. We work with constructors. Okay. All types [07:00.920 --> 07:07.120] can have methods. So you've probably seen this or code similar to this at some point [07:07.120 --> 07:13.800] in your life. So I created a new type my thing out of an integer. So we have a new type with [07:13.800 --> 07:23.080] an underlying type int. I added a method foo to it using the receiver. Just remember that [07:23.080 --> 07:31.600] we said earlier that we have objects interacting through messages. It's called a receiver because [07:31.600 --> 07:45.640] it perceives. It's that easy. Come on. All together. Nobody agrees? What's going on? [07:45.640 --> 07:58.600] Yeah, okay. Pathetic. I said I was going to judge. All right. And then we have, so now [07:58.600 --> 08:04.120] we created a variable t of type my thing. We assigned it one. And then we're able to [08:04.120 --> 08:12.600] call a method on t foo. Voila. We have a primitive type and it has a method. Because in Go, all [08:12.600 --> 08:32.960] types are created equal. Thank you. Okay. So let's move on to inheritance. So we get [08:32.960 --> 08:39.920] in Go. We get composition. We don't get inheritance. That's not something that's available to [08:39.920 --> 08:46.640] us. So this little snippet here is supposed to show the difference. I created a type a. [08:46.640 --> 08:54.640] It's an empty struct. I added a method foo to it. It has a method bar. foo calls bar. [08:54.640 --> 09:02.000] That's nice. Returns bar. We have type p that embeds a. It can embed as many, as many as [09:02.000 --> 09:10.360] many as many types as it wants. It embeds a. That means that now it has foo and bar. [09:10.360 --> 09:19.720] And then it decided to override bar. Fine. Variable b of b lowercase b of type uppercase [09:19.720 --> 09:29.760] b. To be confusing. Not to be confused. Okay. Get it. And we can call b.bar. And we expect [09:29.760 --> 09:39.280] b.bar to be invoked directly. And then we call b.foo. Now, with inheritance, we would [09:39.280 --> 09:53.000] expect b.foo, which returns a.bar, which is overridden, to be called. So we would expect [09:53.000 --> 09:59.480] to get b in both cases. But that's not what's going to happen. Because we do not have this [09:59.480 --> 10:08.320] type of polymorphism. That is true. Who was it that said it earlier? Raise your hands. [10:08.320 --> 10:18.040] Round of applause to the gentleman. Okay. Moving on. So let's talk about single and multiple [10:18.040 --> 10:23.400] inheritance because this really bugs me. So I started my career with seven years of C++. [10:23.400 --> 10:34.560] And yes, it sounds biblical because it is. Thank you. Yeah. So I started with seven years [10:34.560 --> 10:43.880] of C++. C++ actually has a really nifty feature. You can inherit a lot. You have multiple inheritance. [10:43.880 --> 10:50.760] It's not limited. Java, Ruby, they allow you to inherit exactly once. That to me does not [10:50.760 --> 10:55.320] feel like a feature. That feels like a limitation. I don't understand it. Let's say that you [10:55.320 --> 11:02.040] have a truck and you want to describe a container of goods and a vehicle. You cannot inherit [11:02.040 --> 11:09.280] from both. What do you do? Well, in Go we have composition. But in many, many languages that [11:09.280 --> 11:15.040] offer inheritance, you only get single inheritance. Now, I will say this. If you feel, and I know [11:15.040 --> 11:22.400] that a lot of people do, if you feel that inheritance is that important, it just doesn't [11:22.400 --> 11:28.280] make sense that it will be so limited a feature that you will not be able to use properly or [11:28.280 --> 11:34.440] fully. And I do believe also that that is the cause of all the messy code that we see [11:34.440 --> 11:41.480] because the classes that I used to define were very small were one function, two functions. [11:41.480 --> 11:47.440] I didn't have to make odd choices of what is going to go into a class or what wouldn't. [11:47.440 --> 11:55.240] So it was really easy to be very expressive. So that's what I personally, my personal opinion [11:55.240 --> 12:00.920] is about single and multiple inheritance. I don't feel in most common languages, since [12:00.920 --> 12:10.400] it's usually single inheritance, I don't feel that it makes it something that is going to [12:10.400 --> 12:16.280] determine whether a language is or isn't object oriented. Because if it is, then as far as [12:16.280 --> 12:22.760] I'm concerned, single, any language that has single inheritance cannot be object oriented. [12:22.760 --> 12:29.440] So Go is not object oriented. The usual argument summary, and I'm going to, like, you have [12:29.440 --> 12:34.160] to understand that I'm aggregating here everything that was said to me over the internet, which [12:34.160 --> 12:42.400] is a great source of information and also a great source of information. So Go is simple, [12:42.400 --> 12:47.640] object oriented programming isn't, therefore Go is not object oriented. Go doesn't have [12:47.640 --> 12:54.400] classes, so Go cannot be object oriented. It doesn't have inheritance, so it's not object [12:54.400 --> 13:00.240] oriented. And lastly, and this one is a great argument, we're going to dive into that one. [13:00.240 --> 13:05.640] Objects are not really messages, so Go is not object oriented. Now, this one is fun. [13:05.640 --> 13:11.920] So this comes from the Alan Kay School. So all the fans of Alan Kay have jumped in to [13:11.920 --> 13:17.400] let me know everything about the history of object oriented. So here's what I've got. [13:17.400 --> 13:22.760] One person said, technically they aren't methods, so he's referring to method receivers. They [13:22.760 --> 13:29.280] aren't methods on type T, they are functions where the first argument is type is the type. [13:29.280 --> 13:34.040] The promotion to them as methods is syntactic sugar. It's why you can call, now look at [13:34.040 --> 13:45.920] this, this is amazing. V.foo with bar or T, call the type, invoke a method on the type, [13:45.920 --> 13:55.880] and provide V as a parameter. And it's true. Show you what it looks like. So same code [13:55.880 --> 14:06.840] as before, we have a empty struct. We have method foo that we added to A. Quiet in the [14:06.840 --> 14:19.600] court. We have method foo that we added to type A, which is nice. And we can invoke it [14:19.600 --> 14:26.960] using two ways. One is clearly less common than the other. So this is the common way. [14:26.960 --> 14:45.080] Or we can invoke it on the type and pass in lowercase a as a parameter. You have the screen? [14:45.080 --> 14:51.680] That's why, by the way, a pointer receiver can be nil. So I have this game. I play this [14:51.680 --> 14:57.360] game all the time with people who are new to go and I ask them what's going to happen. [14:57.360 --> 15:07.920] So we are able to create methods with pointer receivers. So I add foo and make the receiver [15:07.920 --> 15:16.960] a pointer. I create variable a, which is a pointer to uppercase a. It's zero value is [15:16.960 --> 15:28.320] nil. And I invoke a.foo. And then I ask people what will happen. Now, we're not going to [15:28.320 --> 15:35.600] be able to do this quiz here because we are late on time and we have to make up some time. [15:35.600 --> 15:48.320] So I'm just going to run this. So high from foo is actually returned by foo, which means [15:48.320 --> 15:55.800] that we are able to invoke a method on a nil pointer. It's possible because there is no [15:55.800 --> 16:00.960] receiver. There is no actual receiver. Most of the time when we call a method in other [16:00.960 --> 16:10.240] languages, what happens is that we have to go and go through some reference that's somewhere [16:10.240 --> 16:20.400] in the address space of the variable itself. This tells us that it's not where the method [16:20.400 --> 16:32.080] is at all. It's not where it's defined. It's not where the runtime looks for it. It's just [16:32.080 --> 16:33.080] not. [16:33.080 --> 16:37.320] So my co-organizer, my women who go co-organize it, Jessica Green saw this and said, ah, so [16:37.320 --> 16:44.600] there is no spoon, which I thought was amazing because this is kind of a design thing, right? [16:44.600 --> 16:49.120] So everything is in our minds. Really everything is in our minds. We sort of, you know, we [16:49.120 --> 16:53.120] have these philosophical ideas and then we put them into code. If there is anybody who [16:53.120 --> 16:57.200] actually thinks that the gopher that you saw, the gopher that you saw on the screen in the [16:57.200 --> 17:06.680] maze, there is an actual gopher out there doing this, let me know. I want to hang out. [17:06.680 --> 17:12.760] So where do receivers come from? So listen to this because this is very interesting. [17:12.760 --> 17:21.880] Going to the Go team, the Inspiration 2 method receivers came from Oberon 2, which is the [17:21.880 --> 17:43.880] object-oriented version of Oberon. Okay? And they're called receivers because they receive [17:43.880 --> 17:52.760] messages, except there is no receiver. So everybody's right. Another thing that the [17:52.760 --> 17:58.760] same person brought up, which is really cool, he said, well, I forgot to say who Alan Kay [17:58.760 --> 18:03.960] was. What's wrong with me? Alan Kay is the creator of Smalltalk and also is considered [18:03.960 --> 18:09.480] to be the person who coined the term object-oriented. So he's supposedly supposed to know stuff [18:09.480 --> 18:17.520] about it. So that's why people quote him and that's fine. It's totally fine. And he has [18:17.520 --> 18:23.840] a lot of opinions, which is also great. We encourage opinions. So what a person said [18:23.840 --> 18:28.000] to me, so in Smalltalk, you don't need to explicitly declare that an object can have [18:28.000 --> 18:35.200] a specific message. You send it a message and then it decides whether to handle it. [18:35.200 --> 18:44.400] So duck typing. Now, this is really interesting. Can we do this in Go? Can we check if a certain [18:44.400 --> 18:52.520] value, if it can handle a certain message or has, in layman's terms, has certain methods? [18:52.520 --> 19:00.400] Well, the answer is yes through the magic of interface conversion. So again, we type [19:00.400 --> 19:08.920] a, we added function foo. It doesn't do much. We don't actually care what it does. And we [19:08.920 --> 19:18.920] created interface i, uppercase i. And this interface has one function, defines one function [19:18.920 --> 19:30.080] foo that returns a string. And a coincidentally or pointer to a coincidentally also has foo, [19:30.080 --> 19:36.600] which is a string. Now, this is where Go completely differently than other languages. [19:36.600 --> 19:46.320] In Go, interfaces are implicit. In most languages, if you have, let's say, class A and you wanted [19:46.320 --> 19:51.920] to implement interface i, you have to, at the time of creating that class, you have to say [19:51.920 --> 19:58.840] something like class A implements i. That means that you cannot have a type that is [19:58.840 --> 20:09.400] not aware, has no idea that an implements, that a certain interface exists and will implement [20:09.400 --> 20:16.680] it. Not unless, not unless, that's why a lot of people move to scripting languages, because [20:16.680 --> 20:24.720] that allows them to pick some code from the internet and use it. You know, just use it [20:24.720 --> 20:29.960] unless of what's going on. And Go allows you to actually download some random code from [20:29.960 --> 20:40.680] the internet and plug it in using your own interfaces. It's very strange. It's very unique. [20:40.680 --> 20:47.200] So with that in mind, if you have implicit interfaces, it makes sense to be able to try [20:47.200 --> 20:56.280] and be able to ask whether a type implements an interface, because maybe it does. In other [20:56.280 --> 21:06.040] languages, it just doesn't make sense, because the answer will be no. Right? Right. Okay. [21:06.040 --> 21:10.400] So therefore, we use interface conversion. Now, this is the syntax. What you need to [21:10.400 --> 21:17.400] understand from this expression is that if everything was fine, then Val will have a [21:17.400 --> 21:30.400] type, will have B, which is, which it points to A. And with the interface of i, inside [21:30.400 --> 21:36.400] the interface of i, Val will have all of that and will be able to invoke foo, which is this [21:36.400 --> 21:43.200] one, which is exactly what's going to happen. And this is how stringers work. Now, we said [21:43.200 --> 21:49.440] that small talk, we said that, we said that small talk was created by Alan Kay and he [21:49.440 --> 21:58.400] coined object-oriented. Well, actually, he created small talk with explicit, explicitly [21:58.400 --> 22:06.400] with his ideas of what object-oriented is supposed to be. And it's important, because [22:06.400 --> 22:11.680] according to Robert Grisimer, who is one of the creators of the Go programming language, [22:11.680 --> 22:18.200] this is what, small talk was actually the inspiration for this kind of interface conversion, [22:18.200 --> 22:25.840] so that at runtime, we can actually check if a type has certain methods. And Russ Cox [22:25.840 --> 22:32.360] compared it to duck typing. And by the way, this is a really, really nice read. So if [22:32.360 --> 22:38.440] you just Google Russ Cox duck typing, you will find it. It is a really nice read. He explains [22:38.440 --> 22:44.040] how the runtime does it and also how the caching works, because obviously you cannot compute [22:44.040 --> 22:49.360] well, compile time, you cannot compute every type against all the interfaces in the world. [22:49.360 --> 22:57.960] It's really, really nice. And finally, we have a surprise witness. Martier is going [22:57.960 --> 23:02.080] to be the proxy of said surprise witness. Do you have your? [23:02.080 --> 23:05.360] I am here. [23:05.360 --> 23:16.280] So before I introduce our witness, I am going to ask the witness, do you remember, given [23:16.280 --> 23:23.040] an interview in 2010, to Danny Kalev? [23:23.040 --> 23:25.560] I don't recall. [23:25.560 --> 23:27.920] Well it's on the internet, so it must be true. [23:27.920 --> 23:29.720] It's true. [23:29.720 --> 23:43.080] I submit into evidence a web page. Exhibit 90210. So please read a portion of the text [23:43.080 --> 23:46.600] from the web page in your own voice. [23:46.600 --> 23:52.120] Go is an object oriented, even though it doesn't have the notion of a class, the type system [23:52.120 --> 23:59.320] is more general. Any type, even basic types such as integers and strings, can have minutes. [23:59.320 --> 24:05.200] Thank you very much. So what makes you such an expert to be able to say such, to make [24:05.200 --> 24:07.320] some such claims? [24:07.320 --> 24:09.720] I co-created the language. [24:09.720 --> 24:11.960] You created the language. What is your name? [24:11.960 --> 24:14.400] Rob Pike. [24:14.400 --> 24:16.000] Thank you, Rob. New glasses? [24:16.000 --> 24:19.560] Yeah, new dress. When they made it. [24:19.560 --> 24:28.600] Thank you very much. Thank you, Martia. [24:28.600 --> 24:34.560] So yes, Rob Pike actually said that in 2010. I don't know if he actually changed his mind [24:34.560 --> 24:41.560] since. But the truth is that I feel that at this point it is clearly a matter of opinion. [24:41.560 --> 24:47.400] So I would like to know yours since you are the jury. [24:47.400 --> 25:04.080] Voting is now open. So the verdict. It's verdict time. I hope it's now open. Yeah, it is. [25:04.080 --> 25:10.560] The co-team is not permitted to answer. [25:10.560 --> 25:18.160] I believe one of my members asked the co-team last year if go is object oriented. [25:18.160 --> 25:32.680] That's a dare. [25:32.680 --> 25:52.040] I am going to give you 35 more seconds because we have to wrap it up. [25:52.040 --> 26:01.720] Am I correct? You already see 105 judgments. 108. Oh, no. [26:01.720 --> 26:12.040] I created a bunch of bots. [26:12.040 --> 26:22.360] All right. So I have to close this. Unfortunately, let's find out what you said. [26:22.360 --> 26:28.720] That's interesting. Why can't I see the results? [26:28.720 --> 26:48.720] Yeah, I don't know what happened. [26:48.720 --> 26:55.720] Let's do this. That's what I did. Wow. [26:55.720 --> 27:07.520] Okay. So I am going to cancel these proceedings because clearly you're out of your minds. [27:07.520 --> 27:19.360] As the judge, I condemn myself to providing you with stickers, lots and lots and lots [27:19.360 --> 27:24.560] of stickers. Iris, Rona, thank you very much. I have to get off. [27:24.560 --> 27:38.720] Thank you. If you have a sticker, you have also have to give her one if she convinced [27:38.720 --> 27:43.720] you. Again, housekeeping announcement, if you submitted [27:43.720 --> 27:49.160] lightning talk, check your mail, matrix, discord, WhatsApp, whatever you sent to me, I'll try [27:49.160 --> 27:54.800] to contact you if you got accepted. If you aren't sure, our master on account has [27:54.800 --> 28:22.280] contacted me on Twitter.