Days 1-8 of Advent Of Code 2018 written in Go

Having been a full time rubyist and now gopher, Go strikes almost a perfect middle ground in my opinion.

There's a lot of magic that happens with that ruby code, and there are certainly comparable higher level libraries that would let you write equally concise code in Go (one that comes to mind is https://golang.org/pkg/io/ioutil/#ReadFile) but the reason I prefer the go code in this case over the ruby code:

  1. It is immediately obvious where things can go wrong and we have options for pivoting (rather than just logging + exiting).
  2. It is immediately obvious that we are being good citizens and cleaning up our resources
  3. It is immediately obvious the time complexity of the main loop of the program.

Where as in the ruby code, you actually have two 2 iterations of an array needlessly, you could have been summing as you iterate through, but instead, you first collect everything into an array, then you iterate over the array again with sum. Case and point it is easier to write inefficient code and hide dangerous corner cases when you have nice and convenient methods that hide complexity. It's a double edged sword.

/r/golang Thread Parent Link - github.com