« previous

simplicity in go

I have been coding in Go for a while but I keep reading about it’s problems because as Gophers, we can take criticism. The common thing is that the language is too simple and use Rob Pike’s quote to emphasize that. This in turn is totally misusing the quote.

So I have found a few things that I ask myself everytime that I write some code.

  1. Is my solution in the simple and elegant form?
  2. Is what I wrote readable?
  3. Did I code myself into a corner for future development?

My attraction to Go has been the focus of readability and there is usually one right way of doing something. It all comes down to preference.

There are no ternary operaters.

I hate ternary operators, they are annoying to read later on if I didn’t read them nor do I understand the point of them but that’s just my opinion. Essentally I hear: you wanted to shove an if statement in one line because you didnt want to type it out on multiple lines? I am all about being lazy until it effects the person after me. You have switches if you don’t like the if statement. Why do we need a 3rd way of doing something basic? Let’s solve something more interesting than a compacted if statement.

There are no generics.

Let it go... Let it go...

People hold on to generics too much. I have coded in Go for a while and have not needed a generic yet. Interfaces have solved my problem if I absolutely need something close to a generic. Go is not Java. If it was, there would be no need to create a whole new language. Am I against them? Not at all but I have no desire for them. This is another easy helper that sacrifices readability.

Single Character Variables

… are a thing in Go and it works! Why you ask? That is because we have types. I can tell you what you need to know with that.

func add(x, y int) int {
	return x + y

I am adding two integers. Who cares what they are named? Not complicated enough? Okay, well there is a principle that I was taught from effective-go: The less important the variable the shorter the name. So don’t use them if you hate them but usually there is a good reason such as a for loop which leads me to my next complaint.

There is no while loop.

Yes, there is but it’s a different keyword which we call a for loop. Where is my deal with it gif?

x := 0
for x < 100 {
	x += 10

The point of this blog post is that we do have what you are asking but if we don’t. There is an explanation why not that we didn’t think about. It’s about being simple. That is one of the main purposes of the language.

Rant complete… for now.

comments powered by Disqus