Engineering Blog

                            

GoLang

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…

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

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…

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…

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…

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…