 guess what we have Dana and she's gonna be talking some really cool stuff about Golang and we should all listen to what she has to say. Hi everybody my name is Dana and I work in on Solner in Auckland and I have spent a couple of months learning the Golang and I want to share my experience. Let's start it. So just I want to mention that Golang and Golang is the same thing and I believe Golang was created for the sake of googling because it's really hard to google about Gol when you just have to use Gol especially now when one famous game was introduced. So no, I'm not googling about how to catch pack more Pokemon. I just want to know about the programming language. So I will go through all this presentation though there is Golang on the name of the presentation. So I'm a Python developer since 2010 and I have experienced with the sea and assembly in the past. I tried C sharp and C++ and wasn't really happy with that and as every good developer I want to have different languages on my arsenal so I would kind of have a two-chain to solve the different problems and I was thinking about which language I should learn next. Here what was in my mind it was Java because Java is quite profitable and quite popular language but when I was looking at the book and documentation I realized that it's probably not too... I will spend some time to pick up it and it's a bit obscure when you look at the code and it scares me a bit. So functional languages. Functional languages are quite popular now even cats want to learn it and if you start to learn the functional language I believe you probably will be even got some programming skills which help you to struct your code, your existing code non-functional better and with functional languages you can easily move to the programming scientist side but I wasn't really sure if I'm ready to move from web development what I was doing currently to the scientific data science machine learning which is actually amazing but don't really saw how I can use the functional language in my day-to-day web development so go. I started to read about it and I saw that creators of Go is Rob Pike, Robert Grismer and Ken Thompson which you probably know they was working on a different stuff on the operation system like Unix, Blend 9, C++ and C and B languages. They were working in Bell Labs for some time but end up all together on a Google company and programming on C++ and they get frustrated with the C++ feature bloating like for every task C++ seems to have a different feature and there are lots of features and programming languages became so complicated so every programmer have his own set of features to learn to use and they have a big really complex programs in Google so they like compile for hours and legends say that at one time during the compiling especially big program they thought like oh why not to write the new programming language which actually will compile fast and we don't have to spend time waiting for that. So here's the points for the Go. It should be compile and execute fast. It should have in core and simple concurrency. It should be a static edit type and garbage collected and should have a simple type system without any obscure hierarchy and it's based on C. It's basically look like C. You will see it later in the code and overall it should be clean and simple code. It should correspond with the modern computers. It should use their ability, their power of multicore computers and it's really not about scientific design and putting in this language a lot of features. It should be really simple and easier to learn and like you should start to work with it straight away and it reminds me that. So I was thinking ah okay probably that's the language I want to learn. So let's look closer. Go is compiled unlike Python, statically typed unlike Python and does have curve braces unlike Python. So this is the hello word it looks like in Go. It's a little bit more verbose but still plain and simple. And as you can see it probably reminds about C for those of you who knows. Go is called structure. It's pretty strict. You have to have the structure, you have one Go path and you have all your packages on workspace on the package folder, all your sources on the source folder and all your compiled bins in a bin folder and rules say that Go programmers typically should have only one workspace and all this workspace can contain multiple packages, multiple sources and so the path when you're importing the package will show the whole way not just import something but import the GitHub and that's it. So you can easily get the package using this path. And this is how it looks like when you have a lot of sources. It's a little bit frustrating for the Python developer I think but you can get used to that. And about testing. The testing is not frustrating at all. It basically looks like Python testing. It got Go got his own test framework and it's a special comment in a two-chain which called Go test. And Go recognize the test if it starts from the capital test and have the test pointer to testing T as receiver. So pretty much like Python. And yes, you should use this comment to run all your tests. Dependency management. There is nothing like PIP but you can get this using the comment from Go to chain. Go get package and go get update. In a new version, a part of these folders, you will have special vendor folder which will separate the external packages from your own, from your local one. And you still can control the versions of the Go but unfortunately for now by third-party tools. Go code deployment. That's fairly easy. In the easiest way, you can just have a binary which is statically typed which you can easily check with FDD Linux comment. And in simple case, you just can use the Go to chain and go install and you don't need .ex and PIP running. But in real life, you probably want to deploy the configuration file. You want to deploy the assets. So as in Python, you can use the table, and Docker. What about syntax? Probably in learning, it's the most important part. It was for me. So Python and Go are similar. And in this part, I want to show you, so it's not frustrating to learn Go. So as you see, Hello World is quite plain and similar. And Slices, by the way, if you have problems to see the code, just yell, I can make it bigger. Slices. Go doesn't have lists. Well, it has arrays which is type of lists. The thing is you have to determine the type of the list and you have to determine the length. But how can you even work if you don't know the length of the lists, then you can use the slices. And slices under the hood. It's basically like a structure which have on it the pointer to the array. So we have, with each slice, we have underline array which is basically slice is just a part of this array. And we have capacity and we have length. And capacity is not like a length. Length is what actually how many elements you have. And capacity, how many elements you can extend this slice if you will use extend comments or append. Dictionaries. Dictionaries are pretty much like in Python. So the only difference you should make it with a special comment make. And unfortunately, you can't get all keys or values so you don't have this syntax sugar. You have to iterate through them. Wild loop. So go syntax is quite simple. And while in Python, we have a while. In go, we actually show in the same logic with a for. We use for infinite loop as well. We just not specify anything. And we use for the range loop as well. If statements. Don't get me wrong. Go have if statements, if else, and everything else. And it does even have go to. But it does have switches as well. So if you miss switches in Python, it's really nice. And it has a fall through thing. For me, it was quite interesting. So if you want to hit in the case one, go straight away to the second case, you can use fall through. So you like hitting two cases at once. But Python and go are different. And here's the thing which can be both enjoyable and frustrating to learn. Like you have to use it. So exceptions. Here's the Python exceptions and go. Sorry, there is no exceptions and go. There is something else, though, differ and panic and recover. Which you can pretty much make the program act the same. So differ is the function which differ is the method which push function in stack. Like, for instance, we have the same logic when we use with in Python. And after the logic which was under the with will finished, it will close file for you. It will clear the memory. And it specifies somewhere in with, I believe. But here, you can specify the differ function. And it will say that it will execute after you have done stuff. And if you wrap your logic in a differ function, like specified before, this differ function will execute after this logic was done. Panic function make the piece of logic or the function you do ends straight away. And it's just go up to the stack of your program. But you will just like basically out the program. But if you want to control it, like not just out with some kind of ugly error, you can use the recover. And recover is the function which returns you the power to manipulate your piece of code which you just halted. So it's basically you can make it look like try accept finally using these three functions. No exceptions, but in a simple way, you can check errors state as well. So the thing is the methods function returns actually two variables. It's actually the result which is F and error if it happened. So if error happened, you have to do with something. If not, you just want to go further. And I read that some people complaining that and for some people frustrating and well, I'm not lying here. For me, it was frustrating too at the first time. Like I have to check every time if my error is there, if not. But then if you're doing it with try accept, is it the same thing? Like basically the more text, it's just bit different text. Object oriented programming. That's the thing I really like. Go doesn't have something called object or class. It doesn't have self, this inheritance types hierarchy. No explicit relationships between the other interfaces. And no method overloading. And when I was reading about this for the first time, I was like just another functional language. Not really. It's just a bit different. So in Python, as you can see, you can have a class person. You can have a class attendee which inherits the class person and have access to all the class person data and have his own methods say hello about which will deal with the data on the person by inheritance. In Go, you will have struck person with data on it. You will have struck attendee which have his own data as topic. And you can include the person. So you're not really declared that attendee is inherit from person. You just include this on it. And there will be function hello which will receive which have receiver as struck attendee and function about. So they kind of all separate pieces. You just compose them how you want to. And this is the main principle of the goal that the composition over implementation. And this is how it looks like in the code. I understand that's quite a big piece. So let's go through it. So this is the structs with the data, name, city company, topic and person included. You define the data structure. Then you define the function. And pay attention. This is attendee as a receiver. When I say receiver, you probably want to think is as argument. It's just a goal terminology. And in the main function, you still can use the data from the person because you have this person included on the attendee. So it's everything fine too. The guy be attending still be able to say hi and about. But I should mention that any type of the goal can have his own methods not only structs. But it's really uncommon to have any method to have the methods not only structs. But you can do it. And you can add methods for a type which is only exist in this package. But you can avoid this rule using anonymous fields. So you're not really including on your struct like instance of this, say, of the type of the different package. It is including like some anonymous kind of thing through which you can actually enter to this type, the data. Yeah, this is a composition of implementation. I was hoping to make you remember that with the animation. And there is actually more. You can, so let's imagine that it's our struct person have say hi and about methods. And there is struct attendee and struct listener which have their own data and person included. And listener have own method yarn and struct person have say hi and attendee say hi. So which method will be like more, which method will be executed when you will call it from attendee. So here's the thing, the outer methods have a bigger privilege than the inner methods. I call it inner, I call this say hi inner method because person is kind of inside the attendee. And here how it will look at the code. And this is the function, pay attention that I define say hi two times. And once the receiver was the person and other it was the attendee. So in the main program, the attendee, Norman, when he will say hi, he will actually mention his topic because he has it. And the previous say hi has it as well. So yeah, it's a bit like methods that we're voting, isn't it? Interfaces. So we want to organize our methods a bit. And say we have an interface as a set of methods. And dev interface have say hi and about. And listener interface have say hi, about, and yarn like something new. And as we remember, the struct attendee, struct listener, a struct person was having a person included. So they have these methods. And the interface type dev can be applied to them. But only listener have the yarn method. So listener interface can be applied only to listener struct. And here's the thing, actually, you can interface is not only the set of methods, it's actually the type. And you can assign this type to any variable which have this set of methods which this interface have. So here, oh, sorry. So here the John Jeline and Steve, because they all have the person included and they all have a dev interface corresponding to them, say hi and about. I can actually declare the slice of this interface and put all the structs on the slide and iterate through them. Which looks a bit like generics. And duct typing. Here's the thing, though go is like have a strict type language, you could duct type with the interfaces. Because it has empty interfaces. The empty interface doesn't contain any single method. So we actually can declare anything by this empty interface. Because it will implement all zero its methods. For instance, you can actually, you can make interface as receive the two methods as argument. And this behavior usually used for the storing structs or methods inside, not really for behavior changing. And for instance, you can use interfaces to functions reloading, for standard function reloading. As I said, there is say let's reload the standard print method. It's probably when I was reading about this first, I was thinking like, oh, is it looks about monkey patch and not at all. You can actually like inherit this, like inherit and override it a bit. I will explain that printf have a stringer interface. And this interface have a string method inside. So I make the string method on a person, which have received a person. And because person have a string method and interface stringer has this method too, they can both apply for the interface of printing. And that's why I can actually mock it and modify the function and make this person printed like this, not just like John 29 years, but use this funny special effects on it. Concurrency. Concurrency is like the most claim the most powerful feature of Go. And I can understand why. When I was introducing to this feature and reading about this, I actually find myself that I don't really see the difference between concurrency and parallelism. I was thinking it's quite the same thing. I was thinking it's all about the doing stuff parallel. So parallelism is definitely doing many things at once. But the concurrency is about dealing with lots of things at once, like scheduling, right? So in Go, concurrency is really easy to use because you can turn like simple, simple function in a concurrent one just with two letters. So this here, it goes say hello, you're actually initialized Go routine. And it's nothing changed. And it's quite simple. Because I was dealing with a concurrency in Python. And there is so many ways, especially nowadays, like I think your stackless Python, just a classic method with threads. And it was a bit of a element to learn. But in Go, it's just one way and quite simple ones. And the core thing in concurrency is Go routines and channels. And Go routines are kind of greenish and lightweight thread. And you will avoid the log inhale because you shouldn't think about sharing memory like a lot. You shouldn't think about what log now and what make weight or something. Go will make it for you. And concurrent code looks, as I mentioned before, quite the same as the usual ones. So for instance, with a channel switch, actually like a bridge between Go routines, it could have certain load capacity, it could not. It depends which channel you use, buffered or not. So this is an example of using channels. And as you can see, it's quite simple. And you can specify even strongly having one direction of channel, like only receiving or only sending, which is quite useful sometimes and make your program simpler. And the thing in synchronization, like both sender and receiver should be ready when logic is happening. Otherwise, they will wait until they are. And the real life example is generators. Yes, you have to write your own using the concurrency in Go. There is no such a thing as generators like in Python, unfortunately. But, well, you can do it. And as you can see, the main trick here that you can actually pass the channel to the function. And that make all the logic work. And here's the thing, sometimes you don't really want your program to stack and wait while a receiver and channel will be free. You want to do something in a meanwhile. And here you go, the selects. Each case will execute if C1 is ready and C2, or C2 is ready. If they both are ready at the same time, it will just pick the random. But if they're not ready at all, you will just to default and do your default logic meanwhile. Yes, and here is the example of executing this program. Defer. Defer is actually quite the same as explained before. It commonly used for cleanup. And as I will remind you now, it will execute the functions which you put in on stack after your main logic happened. So you don't have to really worry about this. And you can put any logic on defer function. Yep. So what have you choose? Have I ended up like, oh, my God, God, it's amazing. I will stick with that and ditch the Python or not. Not really. I don't think you have to choose. And I think you should have both. And that's what I was going for. They both have benefits. This is what I really like in Go. I really like how object-oriented programming is structured. It reminds me of the Lego constructor. And it's really neat and nice and clear. Go actually teach you to make your code really simple and understand. It's easy to pick up. It's easy to understand. And yeah, I like the defer function. It makes everything plain. But it's just for me. I don't really like try accept finally thing. But it's not because it's bad. I just don't really like it. And I really like to chain, especially Go FMT. You can't really have different styles on Go. Because if you run Go FMT, it will style the code for you and in the right way. And there is certain strict rules like you don't have to argue about the Egyptian braces. It always just one way. And it's easy to pick up and really fast to learn. And yes, I really like concurrency. It's not frustrated there at all. But some things I really miss from the Python. Lots of syntax trigger. I really miss it like list and dictionary handling. You can extend it. You can append it. You can just append it and go, unfortunately. You don't have to care about capacity. You don't have to think that this size is just have underlying array. And I have to do something with that. And you have dot keys. You have dot values. Python is less verbose. Again, it looks simpler. No brackets. No semicolons. But it's like taste thing. And yes, I miss duck typing. Though probably it will prevent you from making your work from the first time if you're not really experienced. So introducing Go and Python. You can actually mix these two. Because Python can talk to see and Go can talk to see. Well, Go can talk to Python. There is a third party libraries. I was listening to talk about the Rust. And the first thing I was awesome in Rust that you can easily embed the Rust code in Python and easily code that. Unfortunately, it's not that easy on Go language. You have to use Go third party packages. But then they're not really up to date. And they doesn't have the Go routines conversion. And there is the memory sharing is not really advised to use. Yeah, this is how it works for nerds. If you want to see details. Yeah. I probably won't do that. Because embedding Go in Python is quite immature. But when I was just started to learn it, I was so excited. I was thinking, okay, I will now write super fast web crawler. No, I failed. So the further reading. I'm not only including the official docs. Which is really easy to read and plain. And you can find basically everything there. And even the good things as a Go playground. Which is basically like JS Fiddle. You can put your code. You can change it. You can play with that and do it without any IDE. But I included the talks I really enjoy. And which helped me to understand the Go better. And some articles too. So, thank you. We have a few minutes for questions. They don't have a question. No questions. Going once. Going twice. Okay then. Let's thank Dan right again.