Engineering Blog

                            
Bishow Shrestha

Bishow Shrestha

Software Engineer

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…

Unnecessary nested code

Readable code requires less cognitive effort to maintain a mental model; hence, it is easier to read and maintain. A critical aspect of readability is the number of nested levels. Code is qualified as readable based on multiple criteria such as naming, consistency, formatting, and so forth. While programming, we need to maintain mental models…

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…

Comparing values incorrectly

Comparing values incorrectly

In software development comparing values between fields is a common operation. Writing a function to compare two objects, and testing to compare a value to the expected result are some of the frequently implemented comparisons. While comparing our first insight might be to use the == operator everywhere. But this should not always be the…

Never using named result paramater

In Go return or result parameters can have a named parameter. Having a named parameter eliminates the necessity of having a variable name along with a return parameter as the user can only use a return keyboard to return the result. When a result parameter is named, it’s initialized to its zero value when the…

Using a filename as a function input

While creating a new function that reads the file, passing the filename as an argument is not considered best practice and might have negative effects such as making it difficult to write test cases for a variety of criteria. Suppose we want to implement a function to count the number of empty lines in a…

Ignoring how defer arguments are evaluated

In order to understand how arguments are processed using the defer keyword, let’s consider a specific example. Suppose we have a function that needs to execute two other functions, called foo and bar. Additionally, this function needs to handle some status information related to its execution. We can use the defer keyword to ensure that…

Thinking concurrency is always faster

Many developers mistakenly believe that a concurrent solution will always be faster than a sequential one, but this is not always the case. The performance of a solution depends on various factors, such as the efficiency of the concurrency structure, the parts that can be processed in parallel, and the level of contention among the…

External Logging Feature in 01Cloud

External Logging Feature in 01Cloud

An External Logging feature is a feature that is used to collect and store log data from various sources, such as servers, applications, and devices. Logging are typically designed to be deployed in a container orchestration platform such as Kubernetes and to work in concert with other tools such as log shippers, log aggregators, and…