Engineering Blog

                            

GoLang

Interface on producer side

Interfaces are used to create common abstractions that multiple objects can implement. Before delving into this topic, let’s make sure the terms we use throughout this section are clear: It’s common to see developers creating interfaces on the producer side, alongside the concrete implementation. But in Go, in most cases, this is not what we…

Interface Pollution in Golang

Interfaces are one of the cornerstones of the Go language when designing and structuring our code. However, like many tools or concepts, abusing them is generally not a good idea. Interface pollution is about overwhelming our code with unnecessary abstractions, making it harder to understand. So, first we understand the concept of interface and then…

Not being aware of the possible problem of type embedding

Concept of embedded field A struct field without a name is known as embedded field. For example :- In the Employee struct, the Address type is declared without an associated name; hence, it’s an embedded field. But this can sometimes lead to unexpected behaviors if we don’t understand all the implications of type embedding. Note…

Being confused about when to use generics

Introduction The Go 1.18 release introduced a new feature called generic types (commonly known by the shorter term, generics). This allows writing code with types that can be specified later and instantiated when needed. However, it can be confusing about when to use generics and when not to. In this blog, I will try to describe the concept…

Returning Interfaces

While designing a function signature, we may have to return either an interface or a concrete implementation. Let’s understand why returning an interface is, in many cases, considered a bad practice in Go. We know that interfaces live, in general, on the consumer side. Let us consider, there is producer package, we define an producerstore…

Optional Function Parameter Pattern

Go doesn’t support optional function parameters. However, the need for optional parameters will always exist. There are many ways to provide optional parameters to a function in Go, but the most graceful way is to use functional options. Do in this blog we will go through a concrete example and covers different ways to handle…

Project misorganization

Project organization is one of the most common mistake made by Go Developer. Go provides a lots of freedom for designing the packages and modules hence it is not easy task to organize the project. is The purpose of organizing the project are maintainability, readability, consistency and so on.

Any says nothing

The interface type that specifies zero methods is known as the empty interface: interface{} An empty interface may hold values of any type. (Every type implements at least zero methods.) Empty interfaces are used by code that handles values of unknown type. With Go 1.18 the predeclared type any became an alias for an empty…

Creating utility packages

This blog is about how it is a bad practice to create shared packages such as utils, common and base. We will learn about the problems with such approach and how we can improve our code and project structure by avoiding such an approach. Let’s look at an example inspired by the official Go blog….

Creating confusion with octal literals

Octal is a number system with base 8, it has 8 values (0, 1, 2, 3, 4, 5, 6, and, 7). In Go programming language, an octal literal can be written with the prefix 0 (Zero). The value which is prefixed with 0 is considered as an octal value and it can be used in the program statements like…