Great software documentation

Good and great software documentation is written from the perspective of the user. It includes all the necessary API documentation, lots of examples and a lot of guides explaining various common use cases.


One of the stoic principles

The ideas behind the philosophy of stoicism are very interesting as they have a lot of overlaps with the practices of many Eastern systems such as Buddhism.

Stoicism is essentially a system of personal ethics.

One of it’s interesting teachings consists in not worrying about other things or people as these are not under our control. Instead, it is suggested that, since the only entity which can be changed is oneself, one should focus on improving oneself and making oneself more stoic and resilient.

Bias towards action

When facing some difficult issue when programming, it is often better to write some code and try out some things even though one has no idea what the result could be.

Then, one can tinker around and make the code better.

Such a trial and error approach is ideal when approaching programming problems.

In a way, it is a bias towards action.

Dynamic programming

As with many computer science algorithms and techniques, dynamic programming has a mathematical background. The concept of dynamic programming was conceived in the 1940s as a mathematical optimization technique.

There are two main ways of applying dynamic programming to a problem: one is called memoization and the other is the bottom up approach.

A prerequisite for dynamic programming is that the problem has an optimal substructure and overlapping subproblems.

Memoization usually involves coming up with a recursive algorithm for the problem and then, making  use of the already calculated results in the recursion so that the number of recursive calls are reduced significantly.

The bottom up approach involves coming up with the solution for the subproblem and then building the results in a bottom up way  by storing the results in a table. The result of this usually ends up in the last element of the table.

A common example for dynamic programming is the fibonacci series problem. The fibonacci series is defined as a number at index n being the sum of the numbers at the previous two indices in the series: n-1 and n-2. The base case is that the series always starts with 1, 1, 2,…

Using memoization, the solution to the fibonacci series problem is as follows:

memo = {}

def fibonacci(n):
    global memo

    if n in memo:
        return memo[n]

    if n <= 2:
        return 1

    f = fibonacci (n-1) + fibonacci (n-2)
    memo[n] = f
    return f

Using the bottom up approach, the solution to the fibonacci series problem is as follows:

def fibonacci(n):
    memo = {}

    for i in range(n):
        if i<=1:
            memo[i] = 1

        memo[i] = memo[i-1] + memo[i-2]

    return memo[n]

Factory pattern

The factory pattern is one of the most commonly used design patterns.

The probable reason why it is so popular is because of it’s simplicity.

It takes care of the complex initialization of the objects it deals with and it does not store any state.

That such an elegant pattern is very popular is not really a wonder.

Designing good classes and functions

The principle of having a class or a function do only one thing is a very important and useful heuristic. This is known as the single responsibility principle.

Also, it is important to correctly name the classes and functions. The convention followed is to have class names be nouns and function names be verbs.

Doing these two things ensures that anyone looking at any class and function can quickly understand what it does and can plug in or remove or modify these without any issues.

For example, the below python code, which follows the above principles, is pretty easy to understand and follow along:

class ColorRetriever(object):
    def __init__(self):
      self.color = get_color()

    def pick(self):
      return self.color

Moving down from the cloud?

In the past few years, cloud computing has been the rage. It involves providing a lot of services from a centralized platform.

This could be almost seen as somewhat akin to how mainframes used to dominate in the early days of computing with their massive centralized computing power.

However, it appears that with the ongoing innovations in the IoT field, a wave of decentralization may take place in the field of computing similar to how PCs came to replace mainframes in popular usage.