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.

# Month: July 2017

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

# Solving mathematics problems

Mathematics is sometimes a very useful tool to exercise one’s brain cells.

I have found that solving a simple math problem or two sharpens the mind like nothing else.

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

# Grappling with new concepts by teaching them

Often, when one is grappling with new concepts and fields of study, it is often very helpful to try to teach these concepts to others as a good mental exercise.

If one writes a blog post or creates a YouTube video to “teach” these new concepts to others, it almost always helps in the learning process.

# 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
continue
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
```

# Getting past hurdles

Hurdles which are tough to get past often teach us valuable lessons that help us in the future.

So it is important to not get discouraged when facing hurdles.

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