DEV Community

Kevin McGillivray
Kevin McGillivray

Posted on • Updated on

Mindful Code Exercises

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 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. 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) 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 if you try any of these and how it goes!


This post was originally published on my personal site.

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—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!

Top comments (15)

Collapse
 
chakzefir profile image
chakzefir

Kevin, thank you so much for Headspace service. I have already started today, and I feel so

collected, that's great !

Collapse
 
sublimegeek profile image
Jonathan Irvin • Edited

Mindfulness wasn't my goal, but perhaps a byproduct of starting to write more on DEV. My goal was to create an app I can use to help manage my personal finances and for all intents and purposes, it's coming along nicely.

Throughout my journey, I've started blogging about my wins, my struggles, and general "here's what's going on" updates to whoever will listen. As a result, it's been nice so far. DEV is a very welcoming community and supportive for what I'm trying to accomplish.

Ben even gave me mod rights to a tag I was using so I had better control over how the tag looked! Talk about support!

Collapse
 
szklarca profile image
szklarca

I've been learning web development for the last year and a half, so I am just a beginner. In addition to a different perspective, I have a deep brain science background and I've been practicing Mind&Body systems with ever increasing awareness. For me at least, coding requires this special state of Mind that is the best described as Mindful. If, for various reasons such as bad night sleep, heavy breakfast, heat wave, stress, I loose this state, coding is just an unproductive struggle and pain. I just realized that coding in itself maybe a pure and true Mindfulness practice, or better say, the easiness and smoothness of your coding work is an indicator of Mindful state.

Collapse
 
itzsaga profile image
Seth

Great suggestions Kevin. Thanks for this.

Collapse
 
jaredprice profile image
Jared Price • Edited

Awesome to see you make it on the top reads of the week.

Collapse
 
kev_mcg profile image
Kevin McGillivray

Jared! What a small dev world...

Collapse
 
mattwillis profile image
Matt Willis

First off, I love this! After reading your post, I bought Thich Nhat Hanh's book and I am devouring it.

I have been including the Git breathing exercises and mantras in my workflow and it has been really helpful in my endeavor to be more mindful in my daily life. I have been playing around with creating global git hook templates that will help remind me to practice these suggestions. I can share a Github gist when finished if people are interested.

Collapse
 
tangtang08 profile image
Tangy F.

@kevin Great article!!! There are great points! Meditation is very important.

Collapse
 
anthdotlee profile image
Anthony Lee

Pardon my ignorance, but what exactly is mindfulness?

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

Mindfulness is the quality or state of being conscious or aware of something.

Collapse
 
juiiocesar profile image
Julio Guzman

I needed to read this. Thank you.

Collapse
 
codingmindfully profile image
Daragh Byrne

Kevin! I've been trawling through dev looking for other folks who write about mindfulness and code. And I found this. I loved the pull request mantras!

Collapse
 
codingmindfully profile image
Daragh Byrne • Edited

I just stumbled across this! I write about exactly this at my blog CodingMindfully.com.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
chakzefir profile image
chakzefir

Kevin, thank you so much for Headspace service. I have already started today, and I feel so collected, that's great !