Choose Your Weapon

Choose Your Weapon

Before we start digging into software development world and creating own admin tools we should choose a programming language. I want to write about language I’ve chosen for myself few years ago, Go. I don’t say that this is the language that you should use, but I’ll try to convince you in this post why this might be a good idea. Also most of my posts about software development will be in Go. I’ll try to describe why I’ve chosen this language and why I think it’s a good language for both beginners and professionals.

First I want to say that regarding of the language you will choose, please, don’t jump from one to another in every occasion. At the beginning, for me it was very tempting to use different programming language in every project. Just to learn new one while building something. At least I thought that I’m learning them, but this was a big mistake. I wasn’t learning those languages at all. This was just basic syntax knowledge and nothing more. Most of programming constructs are same in every language. There are variables, flow control instructions like if and switch/case, functions that encapsulate some logic into single entity and loops like for and while. Different is just syntax that allows you to write down those constructs (I don’t count language specific constructs as those are not that important at the beginning). So knowing what should be the content of a function or how to use loop in order to achieve desired result is far more important than knowing syntax of 10 languages. You will forget this syntax very fast, once you will finish the tool you were developing it will be gone. When you stick with one language for longer period of time you don’t need to waste your brain “resources” on learning new syntax and tooling. Instead you can focus on improving actual programming skills, like knowledge of algorithms or more advance language features. Once you will get to the level where you can write new, non trivial program from scratch then you can check other languages when developing small tools. Although at the very beginning it might be good idea to write some “Hello World” like program in few languages and choose one that feels most natural. For DevOps world usually writing very simple HTTP API server might be a good idea. Just search “http hello world [language]” and make it work on your PC.

After this rather long disclaimer, lets move to why I decided to use Go both in my job and side projects. First of all it has very clean and simple syntax. I’ve tried few languages before it and when I look at Go source code it’s always simple and readable. When I think about it, it seems that its a lot harder to write unreadable code in Go than in other languages. Big part of why this happens is very simple syntax and go fmt command. Simplicity is important because you can focus on purpose of the code and not on implementation. Fmt command formats your code according to standard, thanks to this every source file in Go have same formatting. Even if someone don’t use it you can always use go fmt to reformat his/her code. Both simplicity and standard formatting help a lot when you try to learn something from open source projects. You can just open some project on Github, start reading and easily understand what is going on there.

Another helpful feature that isn’t unique to Go is static typing. If you once define type of variable as string, integer or any other available type it will stay as such forever. This eliminates lot of potential errors and pitfalls. Many problems will show up on compile time or even before if you use modern IDE and save you some time on debugging strange errors. Maybe it’s not much but it really helps in bigger projects. If for some reason you will decide to use JavaScript (for example to use same language on web page and server) then please consider TypeScript instead, just to get static types.

Compilation step moves us to third important feature: Go code compiles to single binary file. When you came from SysAdmin/DevOps world this sounds like a blessing. No more installing various application runtime environments on servers. Java needs JVM, PHP needs PHP interpreter, JavaScript on servers needs NodeJS, Python, Ruby,… All of those runtimes have versions which have different features and sometimes it’s non trivial to have more than one installed at once. Golang doesn’t have separate runtime, all you need to do is compile it and copy resulting binary to as many servers as you need. You don’t have to install Go there first. Trust me, this simplify deployments a lot.

Despite overall design simplicity it also allows creating complicated applications capable of handling lot of users and processing huge amounts of data. One of reasons is that Go was designed to simplify parallel data processing. Features like channels and go routines simplify a lot creation of very efficient applications capable of handling thousands connections per second.

If I managed to convince you that Go is appropriate language for you then great, go to A Tour of Go and start learning. It’s a great way to learn the language as it doesn’t require to install anything. It can be done straight from your browser. I won’t have Go basics tutorial here as the Internet is full of training materials, creating another one makes no sense. Although if you think that Go isn’t for you, please, remember what I said at the beginning: Choose one language and stick with it! It will pay off in long run.

If after this post you are still interested in improving your IT skills check out my other posts. Disagree with something, want to high five? Leave a comment and we can discuss it. Happy coding!