A fun introduction to Go for Javascript Developers or people of a similar vein, as in predominantly dynamically typed language experience. There are many links within, as they were links that were integral in my understanding the language. Gopher-”hello human” You’re curious. You’ve heard of this mystical language that is steadily climbing the . You know the elusive dragon of Google created it. Perhaps you heard that the creator of Node JS t. But more then anything, you’ve noticed the gopher. rankings of the Software Industry writes in i There is one concept you must understand to properly conceptualise Go. That is… concurrency! But why does concurrency matter? . If there was solely synchronicity, our computers would be moving at a snail’s pace. There is no way around it And Go is quickly becoming the leader of concurrent . This is because it is beautifully written and it performs extremely well. In a way, it is the best of both worlds. programming Check out for further explanation this link Let’s learn by imagining. You are in a parallel universe. The setting of life is a maze. You can create copies of yourself and send these other selves in different directions. The meaning of life is finding a way through this maze. A million you’s finding (their? your?) way through life. You send your clones in every direction that is possible. When one finds the exit all the clones disappear and you become the clone that found the way. And you find the meaning of life. First, an example in : JavaScript to find the exit… yes, this is an oversimplification. JavaScript event looping And now…. Go! Look through it quick, there is a detailed explanation directly after. Ok, quite a bit to explain. Let’s start small ;) Struct? This is similar to creating a constructor in JS and associating two properties. But you must specify the type of your properties and you . cannot give a default value On to a nested struct: Now! Nested structs. So I can do this… . maze.Location.props.final And what is this? . It means this: . This is the type, two arrays inside of an array, extremely complex. [][] [[],[]] Onto interfaces: Now what? Think of these as… floating method constructors! In Go they are called interfaces! Once you associate them with a struct, the struct can call them. Prior to that, nothing can call them. Though, there is another step, the function must associate with the struct: As the comments say. Methods associated with a specific struct is classified in this way. But now there are functions, and what is with the *? Surely you’ve heard of a pointer but what does this mean in terms of Go? If you write this elsewhere: the variable of type Clone, c in this case, is… mutated! Sound familiar? If you want to read more about mutations: . &c.goDifLocation(...) There is no pass-by-reference in Go Back to the function! The parameter: . Yes, it must also be given a specific type. Also, it is common to give short names in Go for parameter names, hence the l for location. (l string) Next, a more detailed function: 1, 2, 3, 4 things? Well, yes, that is the reality. Ex. somethingOfTypeClone.findExit… (c clone) — This is the name of the function findExit Ex. somethingOfTypeClone.findExit(somethingOfTypeMaze) (m Maze) Lastly, the return value! TheMeaningOfLife The function as a whole: Now the function. Check out the first line: . Again, always remember: type is necessary. var currentLocation string Notice how I initialised currentLocation out of the if statement? Sound familiar? ! That link has a nice gist to explain if you do not know. Lexical scope And the if statement? No parentheses allowed! Wonderful, no? Solely double equals. Again, much nicer than JS. But know this, the curly braces are required. If you throw in an else statement? A short explanation: . Basically, what should be known is that the else or else if must be on the same line of the ending bracket — Go by Example: If/Else } else {... And the convoluted grabbing of a particular index. Let me simply say, a number between 1 and 3 is found. rand is a library, as is math that must be imported at the beginning of the file. A link if you are curious: . Though grabbing random numbers is in Go. Packages a bit complicated Onto the main function: Main is what is all that is executed when you the file, as in, all that is in this function will be what is outputted or returned. What’s about? . And yes, functions return values in similar way’s as in JS. is creating the struct with the as the values associated to it. := Implicit type Maze{ mazeData } mazeData Assume that looks like this: mazeData Each value needed for the structs are filled out. Or a is given if they are not. zero value As for: . This is called a . An array is created filled with 1000000 types of this struct, but all of them are empty! make([]Clone, 1000000) slice Concurrency! The last bit of code. The is similar to a forEach of the clones array. Though, the first argument is always the index, the second can be the actual instance. I am setting the id of each clone and… for := range Go Routines!!!!! You type this and every single clone goes into it’s own process to find it’s way through the maze. All going different directions BUT heading to the same goal! Concurrency in a nutshell. Busy gophers Like the gophers above, all doing the same thing, a quite horrid thing… book burning. But still! Each is a singular entity aiming for the same goal. Now, that is an intro to the Go language. Hope you enjoyed the journey. If you are looking for some more info to dive into: Go By Example A Tour of Go Go Koans Definitely this ! And by the mastermind of Go! video this one Thank you! Jerry