#programming #backend #learning Recently, I've been getting the itch to learn a new programming language. Most of the time, when I get this itch, I go out and learn the syntax of a new language, but I rarely apply it or start using it. JavaScript has always been my bread and butter. A recent exception is GDScript, which I learned for the Godot game engine and thoroughly enjoy using. Basically, I like programming languages that end in "script". However, I really want Go to be my primary backend language for the web. I don't want to bother screwing around too much with Typescript, though I will if I ever have to. Go feels fresh and new, and I've heard so many good things about it. So I set out to learn it, and really add it to my arsenal. I figured I would keep a running article of how I'm learning it in case it could help other new Go devs like myself. ### Learn Go Fast I really enjoy learning quickly. It's the easiest way for me to get hooked in and gain momentum with something. So when I found this [video](https://youtu.be/8uiZC0l4Ajw?si=3cq2pciOerMs1Np5) by Alex Mux, I knew that I had to give it a try. I'd heard you could learn Go fast, but the whole thing in an hour? With an example API project at the end? I had to see it to believe it. Overall, LGF is a good, succinct tutorial if you already understand programming concepts. Some of the things that we don't have or use in JavaScript like interfaces, generics, and even pointers threw me off, since I haven't looked at anything like that since college (even though I did screw around with C++ for a bit of game dev). However, the pieces are slowly clicking into place. I watched the whole video and completed the tutorial ([repo](https://github.com/rboddy/LGFAPI)). While a lot of the things in the example API project went over my head, I took some good notes and I'm glad to use this as my first foray into Go Land. ### Kaizen One thing I really liked while attempting to learn Rust (I put it down for a bit, but I'll come back to it), was Rustlings. Rustlings were small, bite sized exercises that I could use to get better at Rust. I've heard these exercises be referred to as *Kaizen*, which is a Japanese business philosophy that is a combination of two words which translate to "continuous improvement". If you have worked in an agile environment, you have likely heard retrospectives be referred to as Kaizens. However, in my case, I wanted to start doing small, increasingly more difficult, Go exercises so that I could learn the syntax and language more thoroughly. While I'm sure that something like "Golings" exists already, I wanted to make my own. So I started with three today: 1. Hello World: Simple enough, print "Hello World!" 2. Hello Ryan: Take in user input from the command line for their name, and greet them by name 3. Hello Pointer: Take the user input from the command line and print the memory address of the value of their input. Then, use a dereferenced pointer to get the actual value of their input I'm sure I'll come up with more, but the last one in particular was helpful to me. I'm learning a lot this way, and I think I'll keep coming up with challenges to get better at this. ### The Go docs API Tutorial and ChatGPT So after building the API in "Learn Go Fast", I decided to look at the Go docs to see if I could answer some questions I had. I noticed that they had their own "build an API" tutorial, so I decided to try it out. When I saw it was a single file, and it was just writing values to memory, I thought it would be much simpler. I was happy to learn that it was an accurate assumption. Building the API was an easy, step by step, 30 minute exercise. I learned quite a bit. I did note that both API tutorials so far used libraries to manage their API functionality like a router and response handling. I guess that's to be expected though, given I would never write an API in JavaScript without something like Express. Gin was a lot simpler than chi, though I think that has more to do with the fact that we didn't really need any middleware on the Gin tutorial. There were a few things that were fundamental to Go that tripped me up, but I decided to ask ChatGPT to explain it to me, and it worked like a charm. I'm generally against the use of generative AI (something I'll add nuance to in a future post), but asking it to explain code to me in the simplest terms was kind of a game changer. Why was Go assigning the results of a function to err? To perform error handling afterwards. Turns out, this is a common pattern. What the heck does that underscore mean in the for loop? It's a placeholder variable, almost like a temporary variable. Saves time from defining an iterator that we don't care about after the for loop is done. I really like this method of learning, and think I'll work some AI code explanation into my efforts in the future. As a final note, Gin made it absurdly easy to implement an API. I'm really starting to catch the Go bug now. ### Writing an Interpreter in Go After doing a couple of APIs of varying complexity, I wanted to try a larger project that would really plunge me into using Go. I heard a recommendation from The Primeagen to purchase Thorsten Ball's book "Writing an Interpreter In Go". I'm a few chapters in, and I'm really enjoying it. Not only am I learning about Go, but I'm learning about interpreters along the way, which is really interesting. However, I made a fatal flaw here. I bought the paperback book. Don't get me wrong, I enjoy having physical books. It's my favorite way of consuming written content. However, this book is large and I don't have much desk space right now. So I was trying to find a way to prop the book open on my desk to type out the examples. I couldn't find space except on top of a laptop to my left, and I had to turn my head 90 degrees to keep reading. This is less than ideal. I'll keep the paperback version of the book, and save the rest of this project for when I get a bigger desk or more space. I'm moving into a new place where I'll have my own office next month, so it's not far off. In the meantime, I **am** going to buy another book (this time in eBook format) that has been on my list recently. I'm going to grab "Let's Go" by Alex Edwards. I'll go through that book while I wait for the space to prop open WAIIG, and I'll document my experience with that book in the next section of this article. ### Let's Go So I am now three chapters into <u>Let's Go</u> by Alex Edwards. So far, it's been an easy read, and I'm picking up a lot of Go knowledge. I think I'll buy the second book, <u>Let's Go Further</u> when I'm done with this one. Building a web app is making is simpler for me to draw on my previous programming experience. While building the interpreter from the previous book was fun, and I learned a bit more about Interpreters, it wasn't doing much teaching of Go. By contrast, <u>Let's Go</u> is meant to teach the language. Once I finish this pair of books, I have a short list of projects that I'd like to build in Go. I may even try and learn a little HTMX and pair the two up, since I've only heard good things.