Starting a new Go project is delightful.

I started a couple projects recently, a mock crypto exchange and my latest project a unicode manipulation library. But what struck me is that its really simple to get started. You need the go runtime and a GOPATH setup.

Then you specify the package and the main method and that is a valid program.

package main

func main(){}

Above is my program so far. It is a short program with a bit of exploratory code that converts strings into their unicode rune ids. Back when I mainly used Java, I would have had to setup an IDE, integrated maven and think about package structure. In Go I just have a main.go file, if I need dependencies I create a /vendor directory and usego get github.com/gin-gonic/gin to pull the dependency.

Overall the lightweightness of the Go tooling makes it very easy to build small programs.

 

 

Code Challenge Usability Testing

Coding Challenges have become a common step in the Software engineering interview process. I have had to review a couple challenges and the biggest mistake is a lack of usability testing. People are usually in a rush when they do coding challenges, either to limit the amount of time they are spending, or because they decided to attempt something challenging and time is running out. When we do side projects we often think that because its just us less complications will come up and our estimates will be more accurate. But the reality is that the project is still going to take longer than you expected. 

Since most coding challenges end up being rushed, its surprisingly easy to stand out through usability testing. Ask a friend to clone your repository and try to get the code running without any support on your end. A surprising number of code samples and challenges don’t even start once they get into the interviewers hands. Or even worse, your code works perfectly, but the interviewers don’t realize it because you didn’t document what the ‘working’ state looked like well enough. 

It might seem like a simple thing to do, but just having two people try to start your app and give you feedback can result in a smooth stress free review of your code sample and give you a strong foot in the door. 

Using pprof to examine the heap and memory usage in Golang Programs

I had some trouble getting the info I needed to setup pprof in my program and the steps to get actionable data out of pprof, so here is my attempt to provide the minimum steps needed to use pprof.

Instrument your code

import (
     _ "net/http/pprof"
        )

func main() {
    go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }()

    //Your program
}
Make sure you have the above in your main.go file. This sets up a webserver that provides pprof data from localhost:6060/debug/pprof/

Heap Memory Usage

In your shell run:
go tool pprof http://localhost:6060/debug/pprof/heap
This will open a cli program, enter top into the prompt.
This gives you the top 10 nodes of memory usage. It will truncate the results if most of the memory is in the top 3 nodes.

CPU time

To sample 30 seconds of cpu time, with 50ms of time ‘sampled’.
go tool pprof http://localhost:6060/debug/pprof/profile
pprof Godoc:   https://golang.org/pkg/net/http/pprof/