DEV Community

Cover image for βœ… Easily Write Better Code With 7 Tips to Get in the Zone

βœ… Easily Write Better Code With 7 Tips to Get in the Zone

What's Flow?

Flow has been described as a mental state where you're able to become fully immersed, focused, and enjoy the task at hand.

It's that weightless feeling of humming along with perfect productivity when just doing the work is intrinsically motivating, without the need for additional rewards or using consequences as motivators.


Flow is also described as being β€œin the zone.”


Some of my best code was written in this zen-like state while solving challenging problems. I loved solving last year's Advent of Code, a coding challenge with a puzzle every day in the month of December. I was so deep in concentration that time felt like it came to a stop.

Repetition Is the Enemy of Flow

Unfortunately, the longer we code, the likelier we are to find ourselves working on mundane tasks, solving the same problems over and over again.

When our work becomes repetitive and routine getting in the zone might feel daunting. It might feel difficult to get into and stay in the zone when the challenges of the work we're doing don't align with our skills. This scenario can result in feeling apathetic, bored, or even anxious.

Skill Versus Challenge

Take a look at the guide above. You'll notice that apathy, or a lack of interest in the task at hand, can be caused by a problem that's too easy even for someone inexperienced.

If the problem is too easy for our skill level, we might quickly become bored with it. Or worse, when the problem is too hard than our perceived level of skills and abilities, it might cause a heightened sense of anxiety.


Flow happens at the intersection of challenging work and a high skill level.


Get Back in the Zone

How can we use this knowledge to our advantage?
By adjusting the ratios!

Is the problem is too easy? Move towards flow by increasing the difficulty.

Is the problem is too hard? Move towards flow by leveling up and learning new skills.


We need to be doing challenging work while feeling like we have the skills to achieve it.


Sounds easy, right? Well, unfortunately, chances are that the conditions you find yourself in just aren't ideal for getting in the zone most of the time.

Luckily, while we can't force a state of flow, we can make changes to how we work to increase the likelihood that we'll achieve it.

To understand how we'll review the seven conditions for flow as proposed by Owen Schaffer.

7 Steps to Get Back on Track

1️⃣ Know What to Do

Knowing what to do may seem obvious, but we've all sat down and opened our editor to work on a new feature or to fix a bug without having a clear idea of what we need to do next.

You think you can just wing it, but your goals need to be clear and achievable to help you get in the zone.


πŸ’‘ Tips

  • Identify what success looks like for your working session before you start.
  • Have a specific idea of what you need to accomplish.

2️⃣ Know How to Do It

If you don't know enough to finish the task at hand, you may start worrying. Fear of failure can trigger anxiety.

Success in achieving flow involves making the problem achievable.


πŸ’‘ Tips

  • Increase your skills with reading and research until you feel like you know enough to try solving the problem again.
  • Try breaking down the problem into smaller more manageable pieces.

3️⃣ Know How Well You're Doing

While you're solving a problem, feedback about how well you're doing needs to be both clear and immediate.

Luckily, we can easily set up our development environments to signal success or failure.

Are you a front end developer? Aim to have a working prototype as quickly as possible. Set up auto-refresh to see your work-in-progress. It'll allow you to move the project along in real-time.

Another great way of getting immediate feedback is by writing unit tests or practicing test-driven development (TDD).

You don't have to stick with every rule of test-driven development to see the benefits. Try to write a few unit tests, and run them frequently. If your test suite is fast, you can even have your tests run every time you save a file.

Sea of green for passing tests


πŸ’‘ Tips

  • Work in small increments and test your work frequently.
  • Write and run tests to immediately see immediate feedback on your code.

4️⃣ Know Where to Go

Athletes are more likely to achieve flow where they know where to move next.

The same paradigm is also vital to programming.

Pausing frequently to figure out what to do next can be increasingly distracting.

Before getting started, create a detailed plan of attack for how you plan on solving your problem or implement your feature.

Make sure your tools help you do your job seamlessly and effectively. As a Python developer, I'm a huge fan of the Python Extension for VS Code in combination with iTerm2.

Learn those keyboard shortcuts you've been putting off, adopt more command-line tools if that fits your flow, and dial back on interruptions.


πŸ’‘ Tips

  • Break up tasks into small, clear, concrete actions and create a detailed to-do list.
  • Dial in your tools so they're not a distraction.

5️⃣ High Perceived Challenge

The work that you're doing needs to be sufficiently challenging to keep you interested and engaged.

If you're highly skilled, but the task is too easy, you're likely to slip into boredom, or worse, apathy.

What can you do if you're stuck in this situation? Don't aim to overcomplicate, but figure out ways to teach yourself new things while you work.

Is it possible to try a new design pattern or apply a different architecture to this problem? Can you use an unfamiliar feature in a programming language you know? Would it make sense to learn an entirely new programming language to achieve your goals easier?

It can be challenging to raise the perceived difficulty of boring, mundane work. If you can find a way to make your work more challenging, you'll be rewarded with a higher chance of slipping into the zone.


πŸ’‘ Tips

  • If the task is too easy, find new ways to learn while you work.

6️⃣ High Perceived Skills

You've already learned that if you're too highly skilled for the task at hand, you're likely to become bored with it. If you're not experienced enough, you might feel anxiety or a fear of failure.

But what if you do have the skills, but you just don't know it? That's imposter syndrome, and it's a common issue affecting developers of all levels.

In the tech industry, it can feel like there's always someone, better, smarter, more confident, and more eloquent than you. It can make you feel smaller, like a failure, or that you'll never live up to your own expectations.

Getting lost in the whirlpool of comparing yourself to others is a sure-fire way to cause doubts and feel bad about yourself. Try to take an honest inventory of your skills, and celebrate the things you do know instead of feeling bad about the things you don't.

If you know more than enough to get the job done, but if you don't have confidence in yourself, you'll have a much harder time getting in the zone. You'll need to believe that you're skilled enough to tackle the challenge.


πŸ’‘ Tips


7️⃣ Freedom from Distractions

In today's world full of notifications vying for our attention, freedom from distractions may feel like an impossible goal.

Unfortunately, you're making it harder to get in the zone by constantly checking your phone, social media, or other distracting websites (*cough* reddit, YouTube, hacker news *cough*) while you're trying to work.

Avoid distractions by blocking sites, keeping your phone in another room or in a drawer, or even turning it off completely. Thankfully, there are amazing free tools to help!

  • For the web: browser plugins block distracting websites, such as StayFocused for Chrome and Leechhblock for Firefox.
  • On mobile: there's a mobile app for iOS and Android called Forest that helps you train your attention.
  • On desktop: a favorite for blocking distracting websites on my Mac is the SelfControl App.

Screenshot of the self control app


πŸ’‘ Tips

  • Minimize distractions to achieve a productive work session.

Write Better Code in the Zone

Research has shown that working in the zone has tremendous benefits. It can increase your sense of achievement and overall satisfaction. It can make mundane tasks seem more fun, and more importantly -- it can get you more excited about solving challenges.

While there's no guaranteed way to force yourself into being in the zone, the tips above should help you achieve that ever-elusive state of flow to help you do your best work.

If you have thoughts on working in flow, please discuss below or reach out to me on Twitter at @nnja.


Note: a version of this article was originally published on The Pastry Box Project.


Lastly, if you'd like to know more about the topic, make sure to watch the seminal TED talk by MihΓ‘ly CsΓ­kszentmihΓ‘lyi.

YouTube:

Top comments (5)

Collapse
 
katylava profile image
katy lavallee

This is great advice. I’ve saved it to refer to it in the future. I usually get stuck because of lack of clarity. What helps is to open a blank file in my editor and just start writing what I’m thinking. Usually that leads to researching things on the internet and copying and pasting code snippets and links into my brainstorming file for later. I often forget to just open up that blank file though! I even have an alias, unstuck, that will open it for me and I still forget to use it.

The only thing I would caution further on is #5. I think I’ve worked with some people who’ve used that technique to get into the flow state, and they end up creating something that nobody else can maintain because nobody else has time to learn the new language, or framework, or whatever. Often times the best tool for the job is the one everybody already knows. It’s kind of sad but it helps us build things quickly and reliably. You might increase productivity of your whole team by being bored in that case.

Another thing to be careful of when you are in flow state is writing readable code. In flow I think your working memory is in top form and you can hold more in your head at once than the person who is going to be reviewing your code later.

Also it’s pretty easy to get into flow state by going down a rabbit hole β€” getting side-tracked trying to solve a problem that’s not important to solve at this time and can limit the options for your future self β€” so watch out for that!

In short, flow is great, but it’s okay to not be in flow too. It’s okay to only be in flow a couple hours each day.

Collapse
 
jasperhorn profile image
JasperHorn

While the tips didn't help me improve things directly, the rest of your article helped me understand myself a bit better. Thanks!

Collapse
 
mateusz__be profile image
Mateusz BeΕ‚czowski

I'm just reading the "Flow: The Psychology of Optimal Experience" and I'm really loving it :)

Collapse
 
nnja profile image
π™½πš’πš—πšŠ πš‰πšŠπš”πš‘πšŠπš›πšŽπš—πš”πš˜ πŸ’œπŸ

That's awesome! If you get the chance to, come back and share your highlights once you're done with the book.

Collapse
 
makampos profile image
Matheus de Campos

wuoo great article.

I need check to read later when I having more time!
thanks, thanks!