Engineering Blog

                            
Avinaya Acharya

Avinaya Acharya

Software Engineer
Overusing getters and setters

Overusing getters and setters

Encapsulation is used to hide the values or state of a structured data object, preventing unauthorized parties’ direct access to them. In Golang there is no by default support of getters and setters, so it is optional. There are few advantage of using getters and setters event in golang and they are mentaion below :-…

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…

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…

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…

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…

Using defer inside a loop

Using defer inside a loop

The defer keyword allows a function call to be postponed until the surrounding function has completed execution. This can be useful for reducing redundancy in code, such as when a resource needs to be closed after use. However, it’s important to be mindful of using defer within a loop, as it can have unintended consequences…