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…

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…

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

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…

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

  • 1
  • 2