Golang Project Structure

Tutorials, tips and tricks for writing and structuring code in Go (with additional content for other programming languages)

go programming

Tag

Rob Pike’s Go Proverbs (Part Two)

Rob Pike, one of the creators of the Go programming language.

This is the second part of a three-part series discussing the Go proverbs that were devised by Rob Pike. (The original post is available to read, if you haven’t already. UPDATE: And the third and final post is now available to read too.) gofmt’s Style Is No One’s Favourite, Yet gofmt Is Everyone’s Favourite The […]

Should Go Be Used for Machine Learning?

An computer rendering of a brain made from metal with wires and lights attached. It is supposed to symbolize artificial intelligence and machine learning.

Go is widely known for its simplicity, concurrency model and performance in large-scale distributed systems. But when it comes to machine learning (ML), the most dominant programming languages have traditionally been Python, R and C++. These languages have become almost synonymous with machine learning due to the wide range of mature libraries, frameworks and communities […]

How to Test Code in Go

A health worker in a laboratory is performing a medical test using high-tech scientific equipment.

Testing should be considered an essential part of the software-development process, because it helps to ensure that our code works as expected when handling a wide range of reasonable values as input. So today we are going to look at how to write tests in Go, using the built-in syntax, and how to run the […]

Let’s Do the Knuth Shuffle

A croupier in a casino shuffling a deck of cards by hard.

I know it sounds like a funky dance move, but the Knuth shuffle is actually an elegant method for randomly rearranging the elements in an array — or, as we Gophers tend to prefer, a slice. The algorithm is very easy to understand and implement, which means that you should be able to use it […]

Companies Using Go Code in Production Right Now

Three plastic credit cards and debit cards. One of them is an American Express card, another is a Visa card and the third is a MasterCard.

We spend a lot of time on this blog thinking about things like syntax and code style, or building example projects, but today I want to zoom out and look at Go programming from a bigger perspective. Who Uses Go in Real-World Applications? Since Go is one of the most popular languages being used in […]

How to Make Go Structs More Efficient

A small yellow car is shown in a huge parking space. Either side of it are two huge white buses.

It may be surprising to learn that two Go structs can contain exactly the same fields and yet one can require more — or less — memory than the other. Since we generally want to ensure that we never use more memory than required, we are going to look at a technique called structure packing […]

Guide to Printing to the Console in Go

A row of wooden letters spelling out the word "format".

Most programs will need to emit some kind of output if they’re going to be useful to the people using them. So today we will look at the various ways to print content to the console in Go, focusing on four related functions in particular. Introducing the Fmt Package The Go standard library’s functions for […]

Did You Know That Slices in Go Can Take Three Indices?

Three cute cats sitting in a row.

I’m going to show you a little snippet of syntax today that even many experienced Go programmers may not be aware exists, which involves performing an operation on an array or slice with the use of three different indices. We’ll look in more detail at this special syntax that’s used in a slice-indexing operation below. […]