Learning Go for Fun and Profit

Okay, maybe no actual profit other than knowledge. But lots of fun!

One of the perks of knowing C is being able to learn a lot of other languages without having to deviate much from the “C formula.”  It wasn’t for a while that a proper “sequel” to C came out. Go, or golang, was created by Ken Thompson, of UNIX and C fame, and some folks at Google. It’s basically C 2.0 with a package manager. Which is actually pretty awesome! Not only is it a simple language, using and getting libraries is a breeze. Once you get started, it’s incredibly easy to start building off of other Go libraries, or creating your own thing for others to use.

So, how did I learn Go? Well, by virtue of knowing C, I already knew most basic things. Did that stop me from googling everything? Nope! For example, if you use a function from another library, say, from fmt, you have to capitalize the function, so you would do fmt.Sprintf. This is a little different compared to C, where it’s for the most part case insensitive. There are also multi line strings, some other odd formatting quirks, and neat tricks in terms of variable creation. My favorite thing about Go, and the first thing you learn, is short variable assignment and implicit typing. No more must you specify that 1 is an integer! Just say x := 1. Of course there are cases where you might want to specify x being, say, a float with a value of 1, or say that y has a string value of true .

Most of my learning was done working on my friend’s project Irkbot. Irkbot is a modular IRC bot written in Go using the go-ircevent library. Because it’s modular, it’s very easy to write new features. The first feature I did was the @interject command, which simply prints out the popular Linux/GNU copypasta with whatever comes after the command, otherwise defaulting to Linux. It took me… Much longer than it should have to do something this simple, but I got it eventually. This also gave me some experience coding for someone else. Most work I do is either for myself or a grade, so I rarely get to change code based on feedback. It’s an interesting process, and it’s cool to see how other people format their code.

The next feature I did was @xkcd, a command that searches for pertinent xkcd comics based on the search term. To do this, I used https://relevantxkcd.appspot.com as a backend, and the go-xkcd library to match comic numbers to comic names. This took a lot more work because I’d never done anything with HTTP requests like this before.

The most recent feature I did was @doom, which leverages the incredibly interesting RESTful Doom to play Doom! This was a whole bunch of fun to do, and it was a blast when it started working. I also tweaked Irkbot’s configuration to be able to connect to IRC servers that require /PASS auth, so it can connect to Twitch chat. While this means one can play Doom over Twitch chat, the lag makes it almost impossible to actually accomplish anything. I’d love to test this with a lot more people at some point, so who knows.

So far I’m really liking Go, and I haven’t found any issues with it yet. I have some plans in the future for extending Irkbot’s functionality, and to even create something completely new that will be used in conjunction with the ELK stack. Stay tuned on that! Or maybe keep your eye on my new lab.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.