Engineering Blog

                            

TECHNICAL

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…

Neglecting integer overflow

Concepts Integer is a basic data types. Golang supports integer data types extensively. Integer are divided into two types which are signed and unsigned integer. Now we will see it’s types Signed integer in go Types Range Types Range int8 -128 to 127 int16 -32768 to 32767 int32 -2147483648 to 2147483647 int64 -9223372036854775808 to 9223372036854775807 Types…

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 understanding slices length and capacity

Slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. It is just like an array having an index value and length, but the size of a slice is resized they are not in fixed-sized just like an array….

Ignoring the fact that elements are copied in range loops

Range is the form of for loop that iterates over a slice or map. We may forget or be unaware of how a range loop assigns values, leading to common mistakes. First, let’s remind ourselves how to use a range loop; then we’ll look at how values are assigned. Concepts A range loop allows iterating…

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…

Inefficient Slice Initialization

Inefficient Slice Initialization

A slice is a flexible and extensible data structure to implement and manage collections of data. Following are the different ways of slice initialization. While initializing a slice using make, we saw that we have to provide a length and an optional capacity. Forgetting to pass an appropriate value for both of these parameters when…