Introduction to Routine Leaks

In the Go programming language, goroutines are a powerful feature for managing parallelism and concurrency. A goroutine is a lightweight unit that allows functions or methods to execute asynchronously, enabling the program to perform multiple operations in parallel wi...

In the ever-evolving landscape of programming languages, Go (Golang) continues to stand out as a stalwart, combining efficiency, simplicity, and robust performance.

Venture into this blog as we uncover some of the most exciting additions to Go 1.21 that will elevate our development experience.

T

...

ACME Corporation has commissioned Wile E. to build an Address Book component for their new flagship product.

Wile: "Ok, I will create 2 structs: Contact and AddressBook and they will be like this:"

  • Contact will be a struct containing the name, surname and phone properties
  • AddressB...

Everything we will describe here is fictional and has nothing related to real persons or real facts.

Wile Ethelbert is a software engineer who works for the ACME corporation and, while moving on to a new project, comes across a piece of code that has been running smoothly for about 10 months:

fu...

Although Golang does not support inheritance, we can achieve similar results through the usage of type definitions and type embedding.

Let's start with a simple object: we need to store contacts data:

  • name string
  • surname string
  • birthday struct

and birthday will be composed by:

  • da...

As we have seen in a previous post (Arrays vs Slices), in Golang, a slice is just a header pointing to a backing array. In this post, we will discuss slices again and we will focus on some pitfalls regarding the append function.

Let's start with a very simple example declaring 2 slices: one co...

Working with GO, one is tempted to think that arrays and slices are the same things other than array having an immutable size. That's not true and some quirks should be known. Take the following function for example (for readability no checks are done on slice bounds):

type NamesStruct struct {...

Optimizing struct size can improve both memory usage and application performance. Let's look at the following example:

package main

import (
    "fmt"
    "unsafe"
)

type Contact struct {
    enabled bool
    name    string
    surname string
    isSpam  bool
    age     int
}

func main() {...

Checking for a nil value is very common in GO programs so it is important to know the difference between checking nil on a given type and checking nil on an interface{} object.

Let's start with an example:

package main

import "fmt"

func GiveMeANil(value *string) {
  if value == nil {...