Skip to main content

Command Palette

Search for a command to run...

The "Idiomatic" Golang

Updated
2 min read

When working with Golang, you will read one word; "idiomatic" alot on all the forums and in the community discussions.

But what does idiomatic actually mean?

Idiomatic, this word is only and only associated to Golang. Generally idiomatic in programming means writing code that follows the conventions, style, and best practices of the language you're using.

We use idiomatic a lot while talking about Go, because Golang's way of doing things is a bit different as compared to other general purpose languages. And hence many a times when you try to do something in Golang, the way you did the same in an OOPP environment like Java and C++, you might break patterns or you might not follow the idiomatic way of doing things in Go.

In Go, idiomatic code usually means:

  1. Keeping things simple and readable

  2. Using structs and interfaces effectively

  3. Avoiding unnecessary abstraction

  4. Keeping functions small and doing one thing

  5. Reusing instead of re-initializing

The problem is, this is so vague, the Go community does suffer problem where someone might say something is idiomatic while the others saying it is not.

But Golang is evolving just like any other language and new features (for e.g. generics) are allowing you to decide what you can do and what you "should not" do. It is not "can not" and it is always "should not" while the community forces "must not".

At the end, if your Go code doesn't look simple, if your code does magic at runtime (hidden dependency injection), if your code enforces a lot of rules, maybe you are over engineering. Go likes to be simple (while it's verbosity doesn't look simple) and Go asks you to write small functions, simple & efficient code.