Engineering Blog

                            
Bibek Pokhrel

Bibek Pokhrel

Software Engineer

Misuse of Init Function in Golang

What is init function? An init function is a function used to initialize the state of an application. It takes no arguments and returns no result( a func() function). When a package is initialized, all the constant and variable declarations in the package are evaluated. Then, the init functions are executed. Init Function Example Misuse…

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…

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…

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….

Not Understanding Floating Points

In this post, we are going to to understand about floating points in Go. What is Floating Point Types in Go In Go, there are two floating-point types (if we omit imaginary numbers): float32 and float64. The concept of a floating point was invented to solve the major problem with integers: their inability to represent…

Not knowing which type of receiver to use

This post is about choosing a receiver type for a method which isn’t always straightforward. When should we use value receivers? When should we use pointer receivers? In this section, we look at the conditions to make the right decision. How value or pointer receiver works In many contexts, using a value or pointer receiver…

Unintended side effects with named result parameters

In this blog we are going to know about unintended side effects with named result parameters. We know that named result parameters can be useful in some situations. But as these result parameters are initialized to their zero value, using them can sometimes lead to subtle bugs if we’re not careful enough. Let us look…

Returning a nil receiver

In this blog, we are going to discuss the impact of returning an interface and why doing so may lead to errors in some conditions. This mistake is probably one of the most widespread in Go because it may be considered counterintuitive, at least before we’ve made it. What is the problem? Let’s consider the…

Mixing up concurrency and parallelism

Even after years of concurrent programming, developers may not clearly understand the differences Developers who have been working with concurrent programming for a long time may still not fully grasp the distinctions between concurrency and parallelism. Therefore, before discussing specific topics related to Go programming, it is important to first understand these concepts and establish…

Being puzzled about when to use channels or mutexes

Given a concurrency problem, it may not always be clear whether we can implement a solution using channels or mutexes. Because Go promotes sharing memory by communication, one mistake could be to always force the use of channels, regardless of the use case. However, we should see the two options as complementary. This section clarifies…

  • 1
  • 2