 Yeah, thank you very much. And firstly, I just want to start by saying thank you very much to Perry and to Joe and the whole babies group and Most of all to everybody who's watching. I'm hoping that I can Share a little bit of what I've learned in my time working with Golang as I said, I I Don't consider myself a Traditional programmer. I believe that all programming languages are tools to accomplish a particular task well in my world anyway and Different tasks for you know, different tools for different tasks for me Golang has worked out very well for the tasks I'm trying to accomplish And I'm thinking that maybe some other individuals in here can find similar use As a note today, I'm going to be using the Golang IDE In what I say here, obviously Golang and Golang are different things Golang IDE is simply one of many IDEs You could be using VS code Or do what I did for a long time and simply code it in Vim I'd like to claim that I coded in Emax, but well, not even I am and that masochistic So we're going to be using Golang and The other reason for using Golang as an IDE in these training sessions is I'm going to show you certain things which Are the reasons why I prefer to stick to an IDE these days different IDEs have different functionality but all in all Yeah, you'll you'll get the point as I as I go So Golang firstly, let's talk a little bit about Golang and you know what it is Golang is one of many languages, obviously Now Golang is a language is actually I Would call it a merge of three different language branches being C on the one side Pascal on the other and then some features of another Group of languages which if memory serves me correctly was originally developed in-house at Bell Labs, but I don't think I Can't be a hundred percent sure of that or the names of those languages But they took the best components and they kind of merged them together It's a compiled language. This is something that a lot of people get a little bit confused about Is Golang a compiled language isn't an interpreted language and they get confused about this because you can do a go run without compiling things It is a compiled language It's fast it's versatile and it's very well designed When you're trying to do multiprocessing and threading but let's talk a little bit now about actual Golang projects and How Golang organizes its code? I think is a good place to start. So in my IDE here I'm hoping that everybody can see the IDE well. I'm just going to start a new project there now Golang Organizes all of its code into Almost modules or projects in this particular case. I'm going to start a Project here called go babies in F drive go source go babies And I'll explain a little bit about how the code is organized in its folders and directories shortly But let's go ahead and create that And now I've got this base project here now The thing to note about Golang is that as I said if you've got a library or you've got your main routine, etc Golang works by Packaging these things into directories and folders So if you've got if I now want to create a sub project, and we're going to call this one over here I'm actually going to create a directory for it and In there I can go and create a go file and this will make this Hello world. Go Okay, so what you are seeing here is now the very base of A go application. There's nothing in there other than the package name That package name is incredibly important All the files within a directory Have to contain the same package name If that package name happens to be main That becomes a package that will compile to an executable if it's anything else it'll be compiled as a library and That package name is also used unless you alias it to reference things once you import them into other projects In this particular case and I'll demonstrate a lot more about that later, but we're going to call this now package main the next part of a Golang package like any language if you look at see if you look at Python any of them They've all got the imports no exception To to Golang and those are used to bring in extra commands now one of the things to know about Golang is that a Lot of its come on similar to see are coming from Libraries that are actually part of Golang itself obviously there are thousands of external libraries But things like your print commands etc etc are all going to come from imports and you'll see that in a second It's right a basic program quickly and then I'll take you through everything in that program Okay, so if you now look at this the first thing this did as I started typing format printf because I've got a clever IDE It inserted an import line That format is the library that it is imported to use the printf command and the printf command is obviously what I'm going to be using to print something and This looks pretty similar to see in many ways But if I wanted to import multiple libraries, I'd need to group them so that I can group them like that And we'll talk about how Golang Groups various things as we go as well because it's not just imports that you can group this way The other thing to know just while I'm talking about these imports is that if I didn't want to have to type Fmt.printf every time I can convert this sorry to a dot import alias and If I do that, I've removed the need to actually add the fmt extension on my libraries to every command that I'm doing One note about that if you've got libraries that have conflicting functions in them and you dot import both of them you're going to have a problem so you need to be a little bit careful about that and That's kind of the absolute base structure of Creating a Very very basic Golang program. I'm going to remove this dot import alias quickly just to avoid any confusion This program now it's got it's the main function here is The function that basically everything stems from so your main function in package main is the start of your top level of your code effectively and This sits there and it will print hello world and you will see that if I go and Run this Run Takes a second because I think it's still indexing. There we go it printed hello world nice and simple, right? Now at the moment obviously I've called one command within the main function, so I Think that the next step that I want to talk about With regards to Golang because this is absolutely fundamental to understanding That the language is what's called a typecasted language. So like any other language you have variables You have constants you have different types Golang is very very sensitive that Your variables of a particular type cannot simply be assigned to another type, etc. And you'll see that as we go But first I want to talk about the basic types of variables that you will find within the Golang language I also want to just check for those on the stream and in zoom Whether or not people have Any questions up until this point so that I can address those before I continue if I'm Saying anything that's losing anyone at any point. Please just stop me The questions are being relayed from both Facebook and zoom to me Within WhatsApp. Thanks very much for Perry and Joe for that Say that again. Okay in Okay, so At all the imports are importing from libraries on the local machine So There are a bunch of libraries that are built into Golang the math library the format library Well, there are loads and loads of them You can also import External libraries Now this goes back to what is called the go path in my particular case I have go path set to F drive go and then under that there will be a source directory and under that there will be a whole bunch of directories that contain all my different libraries At the same time that goes internal libraries are stored wherever goes installed generally And that'll also be in your go path. I hope that answers that question Okay, great stuff. So Let's talk about types a little bit like any Language you've got various types. So in this particular case when you declare a variable, you can declare it like this fall X equals 10 nice and simple Default on that is X is going to be an integer if I were to do a UN 16 Sorry second Y Z UN 8 10 Those are all completely different things X will start off being an integer and integer is not the same as a UN 16 is not the same as a UN 8 They're all numbers that different types of numbers and If in my code for example, I were to go a colon equals X plus Y You'll notice at least I noticed I don't know how well it's showing up on the screen, but that's underlined saying all done a sec. I Can't do that The reason being is that there are mismatched types X and Y you can't add a UN 16 to an integer UN 8 to a UN 16 Here you actually have to assert that the variables are of the same time So for example, if I know that my X is an int and I tell it that my Y is an int Suddenly it'll be okay. Not a problem So you've got to keep that in mind in dealing with going another important thing if you look at this code here it's all Entirely valid in many ways But I've got an underline on my Zed I've got an underline there on the a and it's telling me up here in my IDE that I have errors Here's the thing about Golang it enforces in some ways a level of cleanliness to your code You cannot have a variable declared That is never used You can have a function declared that's never used you can have a type declared that's never used But you can't have a variable. It will tell me if I try and run this now Declared but not used will not compile So if you've got something in your code that's declared as a variable here You've got to actually use it If I were to suddenly tell it to print X is percent d y is percent d Z is percent d XY Z and then add in here Suddenly I've got no errors because I've actually made use of those variables that Makes sense to everybody everybody clear on that I'm going to assume so since I'm not getting any questions back on this so That now with regards to we'll go back to what I was saying about variable types X equals to I Can never I've been working with C for a bit so Excuse me if I'm a little bit C and Golang tend to declare their variables and types Back to front So in what's in C and what's in Golang tend to be reversed here, but I Can also declare a variable if I do it something like that for xint now With Vox int I've declared a variable called X. I've assigned nothing to it. So there it is. It's just there It's an integer Again with types we're gonna. I'll list all of the kind of important ones here all the ones that I use most often We'll talk about the letter. We'll we'll talk about each of these okay, so These are the basic basic basic variable types and there are a lot of them because we'll talk about structures and all the rest as we go but Your most common ones that you're going to be using at the beginning are going to be strings You're going to be using integers. You may be using floating point numbers When you start getting into float 32s you in 32s you in 16s you in 8s You'll use those if you're writing kind of optimized code or doing specific things that require smaller numbers But again, please keep in mind and I keep stressing this that Golang is a type-costed language So you cannot for example where you have F here that is a string Suddenly say that it's going to be equal to an integer because it's not going to know what to do with it Because they are different types Same way that you can't take an integer straight into a float you actually have to do some assertions That's a major difference to what a lot of Python programmers see And I know that a lot of Python programmers really struggle with that type-casting at first and it Causes much swearing Personally, I like it because it keeps my code formal precise Any questions on this before I start talking about how we use these variables, etc in functions and in other things Well, we all clear Okay, so In G and H I'm going to talk about those in a bit That's not an array. It's a slice and there is a big difference between an array and a slice Let's add That is an array so an array In Golang terms is a static size it Cannot be changed. It's you can add data into it But you can't change the size on the fly, etc. It is a static sized grouping of a specific element Whereas a slice is a different thing a slice is an array that is almost dynamically sized But they do have certain fairly different properties in working with them as you code So for example, if you look at VARG here, which is a slice of bytes. It's a grouping of bytes Versus VAR H, which is a grouping of you in 32's Versus I which is an array of bytes I is always going to be four bytes within that grouping G however and H at that point or Zero length slices, which means that at the moment I haven't actually allocated any memory to put anything into them and If I were to try and put something into them at the moment, so I were to do something like G zero equals one which will put one into the first byte It's probably going to allow me to compile this. I just want to Remove some of the other code here Let me just comment out some of this here so that again remember these variables are declared But they're not used the net result of that is I have to comment them Also, I'm never going to be able to compile anything And we'll come just comment that out as well. So we've got something here called G which is a slice of bytes and I'm now going to try and put something into it watch If I run that index out of range, there is no space In there to allow me to put anything into it If however, I were to allocate some memory for it. So G G equals make By 10 now I've got a 10 byte space a gripping of 10 bytes that I can put things into so I could full G zero G 1 G 2 G 3 etc and It'll work just fine Now the question with regards to type cost, sorry, I did just see that question Type costing means that a variable is a specific type. You can't Use one type as another type if that makes sense I'm trying to Find a an easier way to explain that but I think you'll you'll catch it as we as we move along But effectively data in Golang is assigned a specific type and that type is What that data is expected to be types or not you can't add types together, etc. They are different data With regards to the question as to why someone should use slices Because slices are dynamic you can grow them You can shrink them and you can do all sorts of other fancy tricks with regards to slices And I'll explain more about that in a bit an Array and a slice Everything with in there. Yes holds the same data type. There is another data type which Allows you to get around that but I'm not gonna go there yet because I Think we need to cover some some more elementary aspects of the language before I go Into what are called interfaces, but we will get there and it's Yeah, let's let's get there in a bit, but for now. Yes slices contain all the same data types Now Let's talk a little bit about what happens when we attempt to use Okay, now the other question that I I've just seen coming in from Facebook is with regards to how I've Handled my variables so if you look at Va x Int like that that's declaring an empty variable. I haven't put anything into it Whereas if I comment that one out and I do x colon equals Into 10 That's creating x with a value of 10 in it now Go lang's a little smart here. So if it's a number, right? x equals colon equals 10 That by default is an integer Unless I specify otherwise in the same way That will declare why I believe is a float 64 If I were to do Z colon equals ABC Z is automatically a string and so you can Play a little bit there without having to declare Va x whatever type and stick with the default types but you do lose some flexibility there and There are reasons to use the other variable types outside of that default as well but essentially For the purposes of starting off if you do Va x into over there and do x equals 10 That says declare x as an integer and then x equals 10 means put 10 into that variable that there is Identical to saying that for the purposes of learning. There are some differences on the back end But for now you can consider those pretty much identical One note it's talk about what's called scoping variables within Golang are very constricted to the scope In which they were created being the function or the sub routine in which they were created What I mean by that is that if I have something like Va x int and I were to do something like Just trying to think of a good example of this and then I over here What I've just written there is actually really really bad coding practice, but it highlights a point X over here as defined at the top of main is local to the main function and Interestingly enough if I were to use that Inside the for loop here. It would be equal to two However, this x over here x colon equals one right is actually declaring an entirely new instance of x inside the for loop if I'm Got my if I remember correctly Because effectively what is happening inside here has got a completely different scope you've got to be careful of this because If I were to do something like this that they Okay, so for loops are I just want to verify this Yeah, you'll see here that this print statement, right? Can't actually see what y is because y was declared inside the for loop y's got a different scope, so it's not available however x over here, which was declared above the for loop is available inside the for loop But you can also Re-declare a new x inside the for loop which won't be available and then it'll use the outside one That sounds confusing. I realized that so let me stop for a second and take questions on that before I continue Is everybody? understand Scoping and when I refer to scoping what that means Questions anybody or have I completely lost everybody? Yeah, okay, cool. So then let me continue, but effectively That's something else to really remember inside Go lang and scoping is incredibly tight. So a for loop even in an if statement, right? if You in certain cases, and I'll show you examples as we go You can have things inside an if statement that aren't available Outside of the if statement because of the localized scoping status kept very very localized but That's a little bit about variables What I meant by typecasting that talks a little bit about scoping etc now as with any language a Language is based in terms of its variables its constants its functions which are divided routines and You've also got you know in the object-orientated world you've got objects and they will have various methods associated with them We will get to that and go lang is not a typical object-orientated language, but it does have similar Concepts on that Which we'll talk about but I first want to talk about Constantly we've talked about variables We've also have these things called constants so This is a constant equals 10 This constant here, right? Let me just delete that over there You'll see that It's in italics It's got a soft error in it because a constant I can compile that without ever using it because it's a constant But I can't change it. So a constant is simply data that is locked again. These are Type-Costed so that there will be an integer constant of 10 I can print it. I can use it. I can use it as a reference to things But I can't ever change it and it's an integer forever more I Did just see One comment that came directly to me on WhatsApp that some people saying that they can't comment on the Facebook link If you can't comment on the Facebook link, it's either because you haven't joined the group or alternatively. You're not properly logged into Facebook The other question that I saw was about the variable types again Another question about going over those variable types. So let me do that really quickly and step back a second an integer is a Whole number no decimal point, etc. And on a modern 64-bit machine, which most of you will be using will be 64 bits long, which means that it's a really large number Two to the 64 whatever that number is I'd have to work it out. Well, actually we can See what that is so To demonstrate the difference between the variable types we will go ignore the syntax here because I'm just filling in the Full length of the number One two three four five six seven eight is a UN 64 B is an int of Actually, we can just take up that end B is an int of The same thing I want to Think I've got that right C is a UN32 and you'll see when I actually print these what the difference is Just make sure the reason that I'm just using hexadecimal notation here is that it's just easier than trying to remember what the Actual decimal numbers are so if I were to now print these in normal decimal format UN 64 and Int D and UN 32 percent D a BC and We run and Interestingly enough into science so I can't actually take it this big so an inch actually slightly slightly smaller than that I Think if I set that as F zero It's also still too big I can't remember exactly the size of an integer, but an integer is basically a smaller number So if I take that out I'm gonna take that out as well and Take this out Come back to that Where did I make a typo somewhere? That's your difference your UN 64 is a much bigger number than a UN 32 the UN 32 typically runs to about 4.2 billion 2 to the 32 an integer is A signed version of a UN 64 so slightly smaller than the UN 64 Because you've got your signed bit in there, which means that it can be positive or negative Anything that says you in front of it is unsigned. It's always going to be greater than zero or greater than zero floats are Numbers with decimal points again can be positive and negative Strings are obviously strings of characters By types single character or single number that can range from zero to 255 That makes sense to everybody. Sorry for the diversion to go back. I just saw that question wanted to make sure everybody understood this Yes, okay So I just got a question that I saw in the zoom chat that says does scoping mean that a variable is valid only within the scope function or sub function with That it's defined in yes, that's exactly what it means Unless you pass data in and out of the function It's only going to be valid within that particular scope or with where it is defined. You can define Global variables Generally, you don't want to do that. It's not good practice to do it and I'll explain a little bit about passing things around in a second and how that works Let's do that. So as I said to you we talk about functions in any language, so you've got your function main you've got Whatever other functions That's critical to any language because it's how you group your code, right? So in Golang a typical function This is X Okay So now I have a function Let me make this Just look nice We have a function of called it print this and it takes an argument called X and it's going to print That's argument And it's going to be 10 because that's what I'm passing into the functions I Just seen another question which I'm going to come back to you in a second about memory leakage and different Variable types I will come back to that so This year we've got this function it takes this argument called X and it's going to print it right this is fairly simple if I run it You'll see that it's printed this is 10 right now This is where we start getting a little bit interesting with regards to scoping and variable types So firstly remember what I said about variable types and Golang being very specific as to the type if I were to do this that there Where X is a UN 32 with a value of 20? I cannot pass X into that print this function because print this is expecting an integer It's not expecting a UN 32 and so it's going low this is the wrong variable type and Even though it's a number It's strict to this I could however tell it To assert that X was an integer and that will work fine now We're going to talk about okay, so that's the other thing about case sensitivity, right? two totally different variables variables in Golang or case sensitive functions or case sensitive so With a capital X and a lowercase X totally different variables totally different types, right? So yes, the language is case sensitive There were also certain other caveats about the case sensitivity in the language with regards to packages and I'll talk about that in in a second when I actually demonstrate that because You have this thing where You're building remember we're working in package main here as I said that that's kind of your main routine And everything else is imported into libraries from libraries only functions Whose names start with a capital letter or exported out of the library? So you cannot call a function from an imported library if the function is defined with a lowercase letter And I'll demonstrate that later But Effectively if you're defining a function and your name starts for the lowercase letter You will only be able to use it within that particular module You won't be able to export it as a library and that that's quite important to remember and I've seen that trip up a lot of people There are good reasons for it because it allows you to create functions in your libraries Which are used inside the library, but you don't necessarily want to expose on a wider basis Does that make sense to everybody? Yes, effectively that is that is very similar to it's similar to that. Yes It goes a little bit further than that though because When you start looking at declaring things like structures, etc, which we will get to as we go a Structural elements that are uppercase or exported if they're lowercase they're not exported They become private elements of the structure, but I'll show you all of that as we go But let's first go back to where I was here talking about variables and scoping if you look at We'll just take this back to for x equals into 10 and So I'm passing an integer into this print this function and I'm printing it out and The variable name here is called x. I'm also taking x as an input if however in here x equals 20 and I print it and then I print x like that What's gonna happen here when I run this anybody care to take a guess? Okay. Well, let me tell you what's gonna happen, right? X over here is declared as part of main over here X is a completely different variable and I said x is 20. I am not affecting The input here. So what's gonna happen is this is gonna print 10 I'm sorry. This is gonna print 20 This is going to print 10 store because I haven't changed the variable at the higher-level scope and You'll see that here We have I could okay. Yeah, that's fine This is 20 which is what it's printing from over there and the x in the main function is 10 Now that's because as I said what I passed in here and This variable are completely unrelated obviously there are ways of Passing data into a function in such a way as to be able to modify them Before the function returns and we'll get to that it goes into pointers but before we do that we're talking about Functions at the moment and you'll notice that that function there doesn't actually return anything at the moment so let's say I now wanted to return X and I were to do Something like that First thing you'll notice is that it's got errors and I can't compile it one of the things about Golang Your functions will only return what they're told to return. So if I change this definition slightly and I tell it this function is going to return an integer that there is now valid code and What happens here is I'm passing 10 in there I set the local variable X to 20 I return it and I put it into my X in the main function now. I'm going to be printing 20 and 20 20 and 20 but the same way if I were to rename this to Y All of that is local to the function But Y is going to return and I'm going to put it into X. It's still going to print 20 and 20 that makes sense to everybody Any questions Facebook or or otherwise? Yes, you can't you can't a constant is a constant is a constant We'll we'll talk a little bit about pointers and the rest going forward, but no a constant is a constant is a constant Which is a good thing because there's a reason why it's called a constant You know if you're going to be changing your constants you probably shouldn't have them as constants because I'm Prone to breaking rules I will also say however that there are ways you can do some of those some of the stranger things But let's give it a few weeks until I get you guys to the point where I don't confuse you when I start Showing you how to break almost every rule that go lang has Because there are ways to do it, but you don't do it unless you know what you're doing and you've got a good reason to do it Let me let me say that Now with regards to we were talking about functions here if you want multiple inputs on a function, this is quite simple if I were to do a BC and Change this to see and we are going to Just return zero and change this to 10 20 30 and You'll also notice just one note here some it's a it's a good thing. I actually Remembered to say this you'll see here that x equals print this That is very different To typing x colon equals in x colon equals. I am declaring a new variable x equals sits a variable so if I had That is valid because x is declared over here. It's set over here That is not valid because I'm now declaring two versions of x in the same function. So That's why I Needed that colon over there. So what does this do this says into this function? I'm passing three bits of data 10 20 30. I'm returning zero x will return a zero and the footprint as zero If I wanted to expand this with different types B is a string E is a Another end This function call here is invalid at the moment the reason that it's invalid. I don't pass it enough arguments if I were to Pass it like that. That's valid. I'm now passing at the same arguments Arguments have to be in order. They can be in different types obviously separated as I've shown over there You also have Ways of declaring Verratic arguments that I will go into at some point in a further session Where you can effectively pass a variable number of the same type of argument But we'll get to veratics once I've covered slices because it's quite important to understand the slices before we get to the variables Now You'll remember earlier when I showed that if I pass a variable like x into a function and I change it And I return it what I'm actually returning is something very different to what I was passed in because they're two totally different variables There are Certain exceptions to this and I want to talk quickly about slices so If you'll remember earlier I showed you guys something like a byte that declares A slice of bytes that has no data in it, right? I can put a number of different bits of data I could also by the way declare that like this In which case I've declared a slice of bytes That contains one two three four five six seven and if I print that slice By the way, you'll see that in this particular case. I'm using the the percentage v Operator for the print that's purely because that allows Golang to determine what it wants to do with the data that's passed in there it's a Whereas a percentage d will print an integer a percentage F is a float S is a string etc. So those are just the different print operators They pretty much mirror what's in c If anybody wants to contact me offline I can give you a full list of the print operators and examples of all of them, but there are a whole bunch of them When I run this You'll see that Effectively I have a slice or an array going from one to seven, right? Here's the thing If I were to do something like this that there Will add something to that slice So now if I were to run this I've got that extra eight and that's the difference one of the main differences between a slice and an array A slice is variable. It can change size And you can add things you can also Start removing things from a slice So if I do something like that That effectively is going to say that a Must now start from element number two So zero one two a is going to start at three and if you run it A is suddenly being shortened So you can slice it and that's obviously in an assignment, but you can also print Something like that If I were to do something like let's take that out Something like that where a is now printing Just bytes two three four and five Notice that five isn't included in in that print by the way. It'll print elements two three four On that so slices allow you to reference sub elements, etc Um with regards to the question on is append a public function Append is part of the base language. You don't need an import library for append. It's actually part of the base language Now The other important thing to remember So I can append over here to grow a slice What I can't however do is keep in mind there are I'm actually just going to number this from zero just to make this easier because Remember all slices are zero offset In going so zero is still a valid byte. So we'll just align this nicely so that I know zero one two three four when I reference it I can append eight now. I'm going to have a slice that contains zero to eight If I were to do that, it's invalid because that says assign to slice point nine Slice point nine doesn't exist yet. Append allows you to add Once I've added I can change what's in that slice point. So if I were to do a eight Equals nine that is entirely valid because the actual point within the slice exists So it has to exist in the same way And this is really really important if I were to do B equals make by 10 That is going to make me a slice that's filled with zeros But it's going to have 10 elements zero through nine That allocates memory so B one equals one B two equals two those are all Entirely valid things that you can do but this make over here Cannot be used to extend a slice because it'll override it If you look at Let's take out this B. I'll show you what I mean by that If I were to print a at the moment You'll see that that a eight did change that byte to nine and it works fine, but now watch In there, I've got effectively nine bytes zero through two eight. Well, I renumbered nine if I were to do equals make byte nine and then print Suddenly, it's all zero be careful with make make will basically Reallocate the entire slice and you will use your data in it. So you use it for allocating memory You can also use it for cleaning up memory if you do that You clean up your slice rather nicely That makes sense to everybody Any questions you use make when you first declare a variable Or potentially where you want to clean up memory so if for example I'm trying to think of kind of Simple examples of this if you were to do something like this So in this case, I've declared make I mean I've declared a and it's a slice of bytes. It's got no elements in it, right? I Oh, this is something also that's quite important which I will Show you in a second Sorry That right there. Firstly, there are a number of problems with what I've just written number one A has a zero length So I'm going to end up effectively overrunning my slice If I change a over here to say that It's got 10 elements I'll be able to fool that in rather nicely. However, I've still got an error there You'll see here That it won't let me assign it because a Is a slice of bytes I in the for loop Because I is being instantiated as a variable and I am not explicitly specifying its type Is an integer That's a slice of bytes. You can't put an integer into a byte So if you wanted to do that That would be valid So that makes sense to everybody Questions on that before we get Let's just have a look Okay um Okay, so Append is for appending deleting I'm trying to think of the best the best way to put this because There isn't a specific word for deleting Inside a slice. There is in what's called a map variable and I'll I'll talk about maps in in a little bit But yes append Allows you to Effectively grow a slice if you want to remove it right, so make Can be used to delete everything inside a slice It can be used to null nullify everything in a slice while keeping at the same size, right? So if you look at this piece of code over here That prints zero through nine. So we have our ten numbers in our slice If I were to do That That's going to say replace the entire slice with a new slice Of five bytes of all zero So that's going to replace the slice and it's going to make it smaller This other slice is just going to disappear. You'll see this here. It's all gone So make is used to basically remake the entire slice at whatever length anything that was in there is going to disappear if however, I wanted to Delete something out of a slice. There are various ways to do this, right? If it's at the front of the slice and I do that You'll see that I've just chopped off Zero and one which are the first two elements of the slice by effectively telling it that this slice Now only starts from element two and I've replaced a with itself except minus the front two bytes if I wanted to do that at the end of the slice Uh, can you can you hear me now? Okay Ah, sorry about that so If you look at the first one which I which I wrote there, um, I'll just repeat that That says a is now equal to itself but starting from the second element within the slice This top one which I've just pointed here. So Len in Golang is length. So what's to say it says a is equal to a But only going to the length of a minus two bytes because Remember if I've got a slice that says a zero Um at element zero and I make that equal to one I have a length on my slice of one not zero because a zero is still part of the length So your actual Offset is always length minus one for your last element of the slice In this case, I've said a Is equal to a but ended at the length of a Minus two and that's going to chop off the last bite of the slice if that makes sense So that's how you chop off the front of the slice. This is how you chop off the back end of the slice And if I run this you'll see what I mean You'll see that now my slice is missing zero and one which got taken off over there It's also missing um eight and nine Yeah, eight nine, which are being chopped off over there If I were to Do that It's chopped off just the last element Uh, because remember what I said earlier as well The last element that you refer to here is not going to be included in the slice. It's the end point It's not actually included Um, which is why you see length of a is going to be 10 there but Position nine Which will be because of the zero offset And then it's not actually included in there, which is why you can do lend minus one to chop off the end of the slice Does that make sense to everybody? I know when I sounded that I sometimes I even confuse myself here Yes, then minus two means to chop off the last two bites But note the colon there right because the colon here says If you've got a number colon you're referring to Act on the stuff to the left of the colon And that's what you're acting on and the rest is remaining Colon lend says keep everything before the colon But only up to that point. So If you were to do this um Actually, uh, let let me let me Print this over here So if you were to print that and I've got no colon there, right? The reason that I can't assign this by the way and you'll you'll see why in a second What I'm doing in this print statement is I'm printing not the slice But a bite because I'm printing a single element that colon Allows you to say that you're still working within the context of the slice with multiple bites Whereas the lend statement as it sits In that definition of the print will only print one bite and it's going to print the last bite You'll see it prints eight Which is The last bite after I chopped off the bite over here That makes sense Okay, so copy a colon minus two That's very pythonic Notation I actually can't remember. I don't think no you can't do that in um In going you actually have to specify a lend over there um so I just had a question on the zoom channel for those on the facebook channel that says does this work something like a script record colon neg to close script record the answer is you can't do that you actually have to put a proper number in here because You have to You're going to a particular point if that makes sense so That will work like that, but if you just put neg one it won't everybody kind of clear so far on on this brave What you just asked about with regards to slices by the way on What you wrote about The back end array on slices I will get to that in future sessions, but if you want to know about that Earlier than the future sessions. Let me know because that gets quite complicated and goes into How golang Organizes things in the back end um What I will say to all of you guys just to address a question that I saw on facebook um About slices and arrays having a back end array that the slice doesn't point to back end data directly Um, and is actually a structure that is actually correct Effectively if you look at strings if you look at slices, etc. All of those are effectively different forms of structures that are Largely invisible to the user but can be made visible In the fact that the compiler is interpreting a structure which is telling it about what is underlying on the on the slice But is normally invisible to you. There are ways to access it But I can talk about that in a future session because it gets quite complicated um I think You know I think for now what I want to do is I want to leave it here for today, right? because I need people to kind of Get hold of go Play with some of the stuff that I've taught you there is a ton of reading material out there I'm available on The the babies group and joe can talk about how you can join the babies whatsapp group I'm available on facebook and I can you know answer questions that have come in and As best as I can and as much time as I can I will attempt to help you and guide you But what I would say is The stuff that I've talked to you about today that is in this video Go and play with it Experiment with it and when we come back, um, I'll be doing another session like the same time next week. I think joe We'll take this a step further But if I go much further than this I think that without giving you the chance to revise and play with what I've told you I may end up losing you guys And I'll say another thing about as you learn any language The more you play with it, the more it will embed itself In you if you take a language and you don't Play with it and experiment with it and use it. You will forget it So I think let's possibly um, uh, I've just had another question by the way But if we got to the slice, let me answer this first before we close Yeah, no, I'll I'll read out the question I'm just reading I'm reading the question myself and trying to figure out in my head how to answer it Um, so the question was so if we wanted to lead so let's say the fifth element of the slice Then we need to take slice from zero position to fourth position and From the sixth position to the end position and then concat them Yes, that is effectively right and I'll show you How you would do this actually because It depends on whether or not You want an ordered slice Or whether or not the ordering of the elements in the slice isn't important So let me show you something here If we print a right now, so keep this really really basic We have A slice zero to nine, which is 10 elements If I wanted to now remove position By four, which is be position five And I do not care about the ordering of my slice I could do something to this effect I just need to um, so I just got to I've got to wrap my head around this again. Um So That looks really complicated, but it's not actually What I effectively did there is actually one of the more efficient ways of removing something in the middle of a slice what it's doing Is it's effectively saying That it must swap the fifth bite with the last bite And then it chops off the last bite of the slice in the second line So if you look at this, it says make a five equal to the last bite in the slice Make the last bite of the slice equal to a five. So there's the swap, right Then a is now a minus the last element because you've just done the swap and suddenly You've removed that element, but you've also completely Removed any ordering on Your on your slice the other way to do that would be something to This effect, um, I'm just trying to remember the exact syntax of this if I were to do a zero to five and sorry declare a new one and then b equals append b comma a six colon Uh That dot dot dot is effectively expanding the slice to bites because append only does one at a time But that dot dot dot allows me to expand a slice. I'll end up with b with the element removed in the order so there are ways and means of doing this but To answer the question that I had there about removing a middle element The ways and the methods that you do that depend on whether or not the ordering of the slice means anything to you Um with regards to the question that I've just seen on the chat about Goland and is there a freeware edition available? There's a 30-day trial after that. Unfortunately, you do have to pay for it. Um In my book, it's well worth it. I can't remember exactly what it costs, but it wasn't a huge amount um, otherwise There is vs code, etc I haven't used vs code enough to comment on whether it's better or worse I think other people possibly could what I can tell you is that Goland as a product is fantastic and I'd recommend it to anybody So I got comment on the other things, but I can comment on goland and I'd say that goland For me is probably one of the best ide's I've ever touched in any language Um, oh, there we go. Somebody said it's about nine dollars a month. I'm not going to break the bank here for anybody Yeah, exactly. Um So you get a Yeah, just remember I am hoping that next week we see more people not less I'm going to be very unhappy if half of you guys never come back So Firstly, let me explain a little bit about what I do In my in my daily life. Well, I'll explain parts of it and I know that there are colleagues of mine sitting Um, listening to this I have to be careful what I say here Um A lot of my job is about network r and d Which means that I write a lot of low level code that interacts with the network um That includes writing extensions to protocols like bgp other network functions um I write a lot of code that is related to collection of network data and analytics thereof So very high speed data point input pipelines Which we then analyze with goland code um There is code that we write that's doing stuff like live packet analysis to detect Attack traffic, etc. etc. So effectively I write really really really low level code normally for a variety of functions Um, and for a lot of r and d purposes I've also written A fair number of apis Um, because golang has a fantastic method of writing apis that I will share with you guys in time um And in fact one of the reasons that I really liked golang was because I could move away from flask Sorry to the python defenders, but it was just so much better when I went the golang way on that particular point um And yeah, so golang for me is used For a variety of things nowadays, even if I want to do a basic script to process things where I've got a text file with a hundred thousand entries in it and I need to isolate and add things together For me, it's so much quicker to throw a 10 line golang piece of code at it Than to do it in anything else. So golang for me is very general purpose Hope that answers that question okay, so It's a fascinating question And I'm going to answer it in this way terraform influx time sequence database docker um telegraph All of them are written in golang That tells me firstly that golang not going nowhere, right? Secondly Unless the u.s. Department of Justice has their way and manages to break google up into a million bits, which would be insane Google's behind golang. I don't see golang going anywhere you are seeing Yeah, um, you're seeing Various bits and pieces where you're starting to see more and more golang in Certain parts of azure where I've seen various golang libraries and bits and pieces there You're seeing it very heavily with inside google obviously um And in fact google actually has an internal google choir and if you go and Search on youtube they sign songs about golang And if you're seeking songs about the language that you came up with Probably don't get a let it go anytime soon. So I do see a very bright future for for golang One of the things I will say that I really like about golang is that they make a commitment that as they develop the language They make sure that it's backward compatible So a new version of golang is not going to be like going from python 2 to python 3 and everything blows up in your face um, they do keep feature parity very nicely there And and I think that'll also help it Lost obviously, you know languages come and go you can never be sure um for some bizarre reason people 10 15 years ago, I believe that Paul would be around forever um It's still around but not very much. Um Thank god for that. Sorry. Oops. Did I say that? I'm not a fan, but yeah, it you know, I see a bright future for golang. I really do As for copy your question about is golang good for iot My friend What is good for iot is going to be but depend on What you're doing with the iot You know Being good for any particular function is going to be how you apply it and What is the particular device if you I mean If you're for example writing a server that a lot of iot devices are going to be communicating to And collecting data on it. Yeah golang will fit that purpose rather nicely If your iot device is running a microprocessor that is going to require Assembly language to write write down at the machine code level because it's not normally pc compatible Then no golang is probably the wrong choice So it it depends the other question that I've just seen is can I recommend a good book for golang There is a book called the go programming language um and One of the guys behind it is one of the guys who wrote what is called the k and r book in c in the c world Otherwise known as the c programming language by kernigan and richie um The go programming language is probably the best go book i've seen out there In the same way the c programming language is the vital to learning c So, yeah That works as well. And then what i'm going to also going to do is after these sessions And i'll post the link both in the whatsapp group and on the facebook channel Is i'm going to set up a GitHub repo that's got a couple of bits of code in it that covers some of the stuff that we've done here You can go and check out that repo. So you've got examples of that code um There's also a site called play dot golang dot org where you can type live code into the web browser and then Play with it and you'll be able to copy my github repo bits and pieces into there If you want to play with them I will try and get a permanent Play repository up Locally where the code won't ever disappear. I unfortunately didn't get to that today But as soon as I do i'll post that into both the whatsapp group and the facebook group as well And and and unfortunately and and unfortunately um for joe over there facebook is also recording it had it free there ha ha ha ha Now I just want to say that you know that that's really important to anybody in here is that You can sit in classes. You can read books. You can whatever But if you really want to learn a language the only real way to to learn it Is to sit and play with it, you know take what you hear on this Use it to play experiment What if the other things I would say that in learning any language is that One of the things that I do is always set myself a task which I do not know how to do when I set it and I it's deliberately that way And I keep trying until I know how to do it and this turns out to be impossible, which occasionally you know, but set yourself a Something that you want to accomplish with the language Make sure that it's something that you cannot do when you set it And keep trying until you can go and google research, etc, etc That keeps forces you to keep learning. It's a good. It's a good way to learn coding And and just by the way, we will also be comparing your code To joe's code to make sure that he actually writes this in better code than you. So that challenge is binding on him as well Are there any questions from the facebook group if I may ask any comments from there, um, you can just type them into the chat Oh, no, that's perfect Well, that that was my problem with that question because I was sitting there thinking I'm not sure that I know how to do that Anyway guys, thanks so much and we'll see you at two o'clock next week I hope you guys enjoyed it. Um, as I said on the whatsapp group on the facebook channel I'll be monitoring both I'll help with I can if I do take a little while to answer questions or whatever It's not because I'm ignoring anyone. It's just about time But I do try and answer as much as I can Um, I also will say that particularly within the whatsapp group It's always best if you post your questions publicly in the group rather than directly to me because that way everybody benefits from the answer And and by the way, there are no stupid questions Anyway guys, thanks so much. Um, like I said, I hope to see you all next week and bring your friends Well great stuff. Cheers guys. Thanks. Bye