In general, while doing code reviews, I have developed a strong notion of why the use of null
(or nil
, NULL
, nullptr
etc depending on your programming language) generally causes more problems than it solves.
The fundamental problem of null
is that it is trying to represent the fact that it is not a value while being assigned as a value. This fundamental flaw then snowballs and manifests into problems that we see in everyday production code.
Here, I have made an attempt to document the various types of issues I commonly find with using null.
Certain languages have not handled edge-cases of null
type variables in a consistent manner. For example, in Java, you have primitive and reference types of variables. …
Golang’s native libraries provide an immense amount of functionality that can be leveraged to deal with time in its various formats, extract detailed information from it and manage it effectively in your codebase. Let us take a look at them.
All common use cases related to formatting and using time values are available natively in the time
package. For example, we can use the Now()
function available in this package to get the current time.
func main() { t := time.Now()
fmt.Println(t)
}
giving us the current time in the output:
2020-06-17 16:35:55.374219 +0530 IST m=+0.000097244
The Now
function returns an instance of the struct time.Time
available in the time
package. …
Recommender Systems are extremely powerful tools in personalizing the experience of your digital product. Personalization is a proven tool that makes your product more sticky, improves retention and conversion rates. Be it Spotify recommending you the best music for your taste, Amazon recommending you the next thing to buy, or Medium recommending you the next article to read, recommender systems are incredibly powerful in making users derive more value from your product.
As PMs, having a fundamental understanding of how recommendation systems work can go a long way in driving product decisions and having meaningful discussions with engineers and data scientists to ensure everyone is trying to achieve the same goal. …
Regular expressions are a widely used way of defining and using search patterns for strings and building find/replace functionality into software. However, dealing with them can sometimes lead to frustration from the confusion created by hundreds of libraries and frameworks, each using slightly different approaches to regex handling.
With Golang however, the builtin regexp
package contains all use-cases of regexes and is very robust and extremely intuitive to use.
Let us take a look at the various functionalities of the regexp
package.
Use the MatchString
method to find a pattern in a string. The first parameter is the regular expression to search for, and the second is the input string. …
Accepting and processing signals from the operating system is important for various use cases in applications.
While many server-side languages have complicated or tedious approaches to processing signals from the OS, with Golang applications it’s extremely intuitive. Golang’s in-built OS package provides an easy way to integrate and react to Unix signals from your Go application. Let’s see how.
Let’s say we want to build a Golang application that when requested to shutdown prints a message saying, “Thank you for using Golang.” …
Java 12 is here. And it has brought a lot of new features and improvements that I’m personally very excited about. From a language and syntax perspective, the most impressive upgrade is the new optimized way of writing switch cases. Let’s take a look at it!
For our sample scenario, we will just write a function which takes the number of the month as input(numbers ranging from 0
to 11
), and return the number of days in that month. For simplicity, we will assume February has 28
days in this scenario.
Before Java 12, we would write a function like…
Unit testing is a mandatory component of writing good code. Every developer should know how to write good unit tests. With more and more organisations using Golang, it is imperative that as developers, we learn about writing beautiful unit tests for our Golang functions.
This guide is the most basic introduction to Golang unit testing. It does not cover advanced topics such as mocking, benchmarking, and idempotency. I will try to cover these topics in the future.
So let’s get started.
The functionality we test today is quite simple. We have an interface Operator
which has two methods.
Generate
takes two integers and creates a key based on some template, and Degenerate
takes a key and decodes out the the integers from which the key was created. …
Profiling functions is important. Knowing execution time can reveal hidden bottlenecks in your code, provide clear latency estimates before releasing features in production environments, and provide impetus for looking for inefficient algorithm choices in your code.
However, the important thing is that measuring time is not a critical part of the core logic of the function, and thus the code for time measurement should be as non-intrusive as possible.
Let’s say we have a function that does something expensive. For a sample case, we will print the numbers 1 to 5, with intervals of 100 milliseconds between them.
func expensivePrint() {
for i := 1; i <= 5; i++ {
fmt.Printf("Current number is %d \n", i)
time.Sleep(100 * time.Millisecond) …
In the previous installments of the Zero to Hero Python series, we covered:
In this piece, we will be looking at Python’s in-built collections for supporting mathematical concepts like sets and key-value pairs.
Let’s get started!
A set is used to store a sequence of unique values.
A set can be declared by making use of curly braces {}
.
>>> numSet = {1, 2, 3, 4, 5}
>>> print(numSet)
{1, 2, 3, 4, 5}
If you put duplicate elements in the initialization of a set, only one instance of the elements will be retained. …
About