
As I discussed in a previous article I will be going through Learning Go: An Idiomatic Approach to Real-World Go Programming by Jon Bodner and along the way I will be comparing with modern Python. First, up is setting up your development environment.
Different but the same philosophies
If you have never written a line of Go before, you should. It’s very nice to have everything you need included, along with your tools and language be opinionated. The opinionated bit might be a turn off for some people, but honestly, if you just receive the Mark of The Necromonger- I mean- use the tools Go provides for you then I promise you will be able to focus on actually writing code.
At its core, the Python community is comprised of a bunch of hackers who like to do things themselves (myself included), but the last couple years Python has seen a convergence on a similar idea. I don’t know if I could name a time when I didn’t use uv to add packages to my virtual environment. It’s also been about 2 years since I used Black, flake8, or isort for formatting and linting, as everything has consolidated to Ruff. Mypy is still hanging around, but if Ty ever hits v1.0 I will surely be getting yelled at for my poor types in a tool written in Rust thank you very much.
Back to Go. Both Python and Go can be installed via Brew with a brew install go & brew install python. If you are using a distro like Debian you can install with
sudo apt update
sudo apt install golang-go python3 python3-venv python3-pip
Here’s a breakdown of the functionality the Go binary ships with and their Python corollaries:
| Go command | Python equivalent |
|---|---|
go run main.go |
uv run main.py |
go build |
uv build for packages |
go install pkg@latest |
uv tool install pkg |
go mod init |
uv init |
go get pkg |
uv add pkg |
go mod tidy |
uv sync |
go mod download |
uv sync |
go mod graph |
uv tree |
go work |
uv workspaces configured in pyproject.toml |
go test ./... |
pytest |
go fmt / gofmt |
ruff format |
go vet |
ruff check |
go fix |
ruff check --select UP --fix |
go doc pkg |
python -m pydoc pkg |
go clean |
None built in. |
go env |
python -m sysconfig or uv python find (partial) |
go version |
python --version |
go list -m all |
uv pip list |
go tool pprof |
python -m cProfile, py-spy, or scalene |
go tool trace |
viztracer |
go tool cover -html |
coverage html |
go bug |
None |
Some interesting tidbits on gofmt:
- You cannot specify a line length or any other stylistic parameters (take that Henry Ford).
- You cannot have a bracket on a new line like so-
func main()
{
fmt.Println("Hello, world!")
}
Because the go compiler inserts a semicolon after identifiers (int/float64), basic literals (numbers/string constants), and token words (“break”, “continue”, “fallthrough”, “return”, ++, –, “)", or “}").
The above code snippet would result in the compiler inserting a semicolon after the main closing parenthesis like such-
func main();
{
fmt.Println("Hello, world!");
};
There also exists goimports which sorts your imports, although this doesn’t ship with the go binary.
Task Runners
When it comes to task runners, there seems to be pretty strong agreement in both Go and Python. I’ve only seen Makefiles in the wild, but allow me to plug Justfiles for just a moment.
Justfiles are a handy way to run repeated commands easily. Admittedly, it seems Go has less of a variety of commands to memorize than Python, but nonetheless, I find the reasons below as great reasons to roll with them over Makefiles.
Justcomes with a formatter which is a lifesaver. If you’ve ever had issues with tabs vs. spaces in application code, it’s a nightmare with Makefiles.Justcan be and executed from any subdirectory. It will execute the first matching recipe of the first Justfile it finds. This means, if your Justfile is infoo/justfilebut your working directory isfoo/bar/you can still execute any just recipe withjust {recipe_name}without having to change working directories likecd ../ && just {recipe_name}which is super handy.- It has a sweet terminal picker you can use via
just --choose.
When using justfiles I recommend using a {noun} {verb} (e.g. just backend test) set up for your recipes, or just using a verb for root recipes (just fmt).
Conclusion
That’s it for an overview of tooling. We will dive into specifics, like formatting, types, and specific tools in follow up articles.