Golang for Java-Coders

I want to share my experiences when I started programming in Golang from my perspective as a Java Coder.

What is this and why???

So first I wanted to know what is Golang. Rumors from my colleagues put it into one class with C and C++ (which it is not), this is not true at all. Golang is not a low-level language, it is far closer to Java than to C (from an abstraction perspective). These rumors probably come from the fact that it has a small amount of keywords and control structures reminding a bit of C.

When you read or listen to the talk the creators of the language gave at google, you get a much better idea of what it is and what problems it is supposed to solve. Basically they wanted a language for their C + C++ coders which is safer and easier and which compiles faster and which was built with concurrency in mind.

“Go at Google: Language Design in the Service of Software Engineering” Rob Pike, Google, Inc.

(Video) https://www.infoq.com/presentations/Go-Google
(Transcript) https://talks.golang.org/2012/splash.article

Reading/watching this helped me to understand a lot better what the intentions behind golang were.

Down the rabbit hole

Golang ships with a lot of nice basic stuff builtin, but for medium sized projects you need more.

Dependency Management (like maven)

Golang has its build and dependency management tool builtin. You don’t need any external tool. Unfortunately the golang dependency management does not use some versioning system. Instead you point your program to the github (or other website) master branches of other repos. Yes, I am not kidding. Again this makes more sense if you see it from googles perspective where they run all their stuff in a big repo. Probably they prefer breaking stuff as they are able to fix it right away.

There are workarounds like gopkg.in or vendoring (including the other source in your repo in a vendor folder). We used the “govendor” command in one of our projects.

https://github.com/kardianos/govendor

Read more here:

http://zduck.com/2014/go-and-package-versioning/
https://blog.gopheracademy.com/advent-2015/vendor-folder/

Logging

Golang has very basic logging builtin, but doesn’t cover loglevels, etc. as a java coder you want something like e.g.:

https://github.com/sirupsen/logrus

There are a lot more golang logging libraries out there, just search for them if you want.

Testing

Golang has basic testing builtin, but for nicer assertions, etc. you might want to use helperfunctions from e.g. testify.

https://github.com/stretchr/testify

Again, there are a lot more testing frameworks out there.

Mocking

Mocking in golang is a bit messy, there are some libraries with generators, but I am missing mockito. For now mostly I just built my own mock structs which implement the interface I want to mock.

Best golang book for Java Coders

The bare minimum you need to program in go. Exactly what you need, not more not less. A quick introduction into the golang programming language for experienced programmers.

http://openmymind.net/The-Little-Go-Book/

pixelstats trackingpixel

Leave a comment

Your comment

Time limit is exhausted. Please reload the CAPTCHA.