Coding While Fasting Part 2

Read Part 1: General productivity tips for coding during Ramadan

The assumption is that when you’re tired, you’re more likely to lose focus and therefore make mistakes. It is important to combat this tendency by first not blaming your lack of productivity and mistakes on fasting, and second by finding and using productivity tools and techniques. In the previous post, I mentioned 5 tips that can help you with general productivity during Ramadan. In this post, I focus on technical techniques and tools to help you be a more productive coder during Ramadan.

1. Catch errors fast.

Squash 'em before they become a problem

Linting

Sometimes, you want to have a safety net to catch common typos and errors. You can use linting to catch out obvious errors and typos. Think of it as a spell checker for code. Here’s an example showing the use of eslint to lint JavaScript code.

1
var foo = bar;
1
1:5 - 'foo' is defined but never used (no-unused-vars)
1:11 - 'bar' is not defined. (no-undef)

When coding, having such safety nets is useful in general, and when you’re fasting they certainly help you catch common mistakes.

We can attach a linter to a pre-commit hook. This means you won’t be able to commit code if there are any linting issues like above. Here‘s a pre-commit hook that uses eslint.

2. Focus on one thing at a time. Tests.

Tests make you focus!

Test driven development becomes more useful when you’re fasting because of a couple of reasons:

  1. It allows you to focus on one thing at a time.
  2. It allows you to catch errors before you commit them.

I find that it is always useful to write down what you’re doing - it allows you to focus on the task at hand and not get distracted by other things. Writing tests allows you to do this, it gives you a ‘task’ that you must fix before moving on to the next thing.

There are tools to help you with testing. PhantomFlow allows you to write front end user flows. Here’s an example flow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
flow("Get a coffee", () => {
step("Go to the kitchen", goToKitchen);
step("Go to the coffee machine", goToMachine);
decision({
"Wants Latte": () => {
chance({
"There is no milk": () => {
step("Request Latte", requestLatte_fail);
decision({
"Give up": () => {
step("Walk away from the coffee machine", walkAway);
},
"Wants Espresso instead": wantsEspresso
});
},
"There is milk": () => {
step("Request Latte", requestLatte_success);
}
});
},
"Wants Cappuccino": () => {
// ...
},
"Wants Espresso": wantsEspresso
});
});

Now that the user flow is written, even if it is just stubs like above, you have in your head a general plan of what the feature will look like. You can then implement each step and focus on it. For example, you can implement goToMachine. For more details about PhantomFlow, check out the GitHub repo here.

3. Code reviews and pair programming

Pair programming

A good way to keep productive while fasting is to work with someone.

Pair programming is an agile software development technique in which two programmers work together at one workstation. One, the driver, writes code while the other, the observer or navigator, reviews each line of code as it is typed in. The two programmers switch roles frequently.

From Wikipedia

Pair programming and code reviews have many benefits. When fasting, they are extra useful because:

  1. When in the driving seat, they force you to be constantly focussed. Someone else is watching you. Better not make mistakes.
  2. When in the observer seat they allow you to ‘rest’ from actual coding, but still allow you to contribute to the solution.
  3. They catch out problems in your code, and allow you to learn from someone else’s experience.

Conclusion

Ramdan Mubarak!

Ramadan is a month of spirituality, but it is also a month of productivity. It forces you to focus - whether it is on your worship, or on your work. Finding tools and techniques to help you focus during Ramadan is not only good to get you through the month, but the things you learn can be applied throughout the year.