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

Coding While Fasting

Update: Read some more technical tips in part 2

Some say you can’t be productive in Ramadan. I disagree. You can be more* productive while fasting, and it can help you stay focused. Here’s how I do it.

*Coding while fasting made me a really fast coder. Ok that was terrible.

1. Ease off the coffee

pro·gram·mer (n) An organism capable of converting caffeine into code.

As true as the definition above may seem, you can still be a programmer without drinking coffee. I promise. Coffee can help you concentrate, but a lot of the time it’s our perception of this than its true effects. So, to increase focus during Ramadan, I decided to slowly reduce my caffeine intake as Ramadan got closer. This means I’m less dependent on coffee to stay awake (e.g. on Monday mornings), and I can reduce the withdrawal symptoms during the month.

2. Fast Mondays and Thursdays

Intermittent fasting has health benefits and immense reward. On the run up to Ramadan this gives you the extra benefit of getting your body prepared for the long fasts. Once the month starts, you’re already used to it and are able to spend your energy on other ibadaat.

3. Go out for no lunch

Instead of sitting at your desk for very long periods, go out. Even better, go for a walk to the local Masjid, pray Duhr, and stay there for a while. You might not be feeding your body but you’re nourishing your soul ;)

4. Stop thinking about food and think about the ajr

Do as you're told!'

I know it’s hard, especially when you get those emails from people coming back from holidays with different types of sweets from all over the world. So instead, every time you think about food, think about the reward you’ll get inshaAllah.

Whoever observes fasts during the month of Ramadan out of sincere faith, and hoping to attain Allah’s rewards, then all his past sins will be forgiven. (Al-Bukhari and Muslim)

5. Stop blaming it on the fasting

You always hear people doing silly mistakes and saying “sorry, I’m fasting today”. This will only make you believe that fasting will decrease your performance. Take a positive outlook on the fasting. If you keep telling yourself it’s affecting you negatively, it will. If you tell yourself it improves your productivity, which imho it does, it will.

More on Ramadan productivity

Productive Muslim has a lot of practical tips for making the most of Ramadan and being super productive!

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×