xhroot

Go Language

A welcome side-effect of exploring new languages is that they tend to force you to think differently about language design, at times bringing improvements to the languages you use daily. Here are some observations about Go:

  • Declaration is very concise. := is used as declaration + assignment. var and a type are necessary if there is no assignment (and thus no type to infer from).
  • Multiple assignment. This is not unique to Go, but it highlights what is so attractive about it: you can compose code in a way that is so natural that others find it easy to read. How do you swap 2 integers in C#?
1
2
3
var temp = a;
a = b;
b = temp;

In Go?

1
a, b = b, a

More importantly, multiple variables can be returned from a function. This eliminates having to create transport objects whose only purpose is to wrap multiple values.

  • Implicit interfaces. Implement an interface without having to declare it.
  • Strict compiler. Does not compile if imports or variables are unused, which has prevented many bugs. So much is caught by the compiler that I’ve been pleasantly surprised by how frequently I’ve gotten past compilation and the program ran without errors.
  • Slices. Think of them as sub-array pointers.
  • Error handling. Idiomatic Go encourages always checking for errors as soon as they may occur or be returned. If you use guard statements often, you’ll probably be OK with this style of coding.

Here’s a list of some great resources for learning Go: Go Resources.

Comments