Mindful Code Exercises
Tags: mindfulness
Published: 2017-09-05 14:58:16

---
title: Mindful Code Exercises
published: true
description: "Experiments for practicing mindfulness while writing code."
tags: mindfulness 
---

One of my favorite ways to explore mindfulness is to integrate a mindfulness exercise into an everyday activity—washing dishes, driving a car, eating dinner, sweeping the floor. As the Zen saying goes, "Chop wood, carry water."

Since I spend so much time writing code, I've been experimenting with ways to connect mindfulness exercises to daily activities related to programming.

Besides being a way to have a more mindful day overall, practicing mindfulness in proximity to programming can help with many common situations that arise when coding. Writing code is a complex experience—it often requires a high level of focus, and moments of frustration or confusion can often bring up strong emotions and mental cloudiness.

* Getting stuck for hours with mounting frustration
* Frustration when learning new skills or concepts
* Getting addicted to writing code
* The complications of collaborative projects (distraction, communication)
* Getting bored and losing interest in a project or programming in general

Here are a few of the mindfulness exercises I've experimented with. Many of them are simply ideas to start from, so if you try them please experiment with them and let me know how it goes!

## Meditation bookends

Start each coding session with a few minutes of sitting meditation ([Headspace](http://headspace.com) can help) and end each session with a few minutes of walking meditation.

## Pre- and post-commit breathing

Take three deep breaths before and after each Git commit and Git push.

## Pull request gratitude/loving kindness

When creating or reviewing a pull request, take a few deep breaths and repeat a mantra that is focused on gratitude and kind speech. Here are some ideas that are loosely based on mantras from Thich Nhat Hanh's book, [Work](https://plumvillage.org/news/work-how-to-find-joy-and-meaning-in-each-hour-of-the-day/). I would recommend coming up with your own, formal or informal, to match what you prefer!

When reviewing a pull request:

> Reviewing this code,  
> I am grateful to those that wrote it  
> and for the tools that were used to write it.  
> May this code bring health, peace, and well-being.

When creating a pull request:

> Code can travel thousands of miles and affect many people.  
> I vow to write code mindfully and lovingly.
> May this code create mutual understanding and peace.

## Tab sweeping

When ending your work for the day or switching to a new task, review each open tab in the browser and text editor and close each one that you don't need while taking a breath.

## Naps and Food

Rest when you're tired, eat when you're hungry, drink when you're thirsty.

## Daily writing

I've found that daily writing (such as [750words.com](http://750words.com)) is one of the best mindfulness exercises and maybe helpful to integrate into a daily routine.

---

If I try any other exercises, I'll update the list here. [Let me know on Twitter](http://twitter.com/kev_mcg) if you try any of these and how it goes!

---

_This post was originally [published on my personal site](https://www.kevinmcgillivray.net/code/)._

Did you enjoy this post and want to read more like it? I’d like to invite you to sign up for my [programming education newsletter](https://tinyletter.com/latenightcodeclub)—it’s all about learning and teaching programming. In each newsletter you’ll receive updates about new posts as well as other resources and ideas all about learning programming! It’ll be short, interesting, and encouraging for learners and teachers. See you there!