How many minutes/hours do you really sit to write code at a particular moment?

I'm not saying the total summation of hours you code a day. When you really sit down to write a code for a particular task at a moment, how many minutes/hours (at worst case) do you normally sit down before you get tired? I know some take break, some say it depends on the task or the individual, I would love to hear them all, and what you do to keep your brain refreshed before getting back to coding. Thanks...

Tommy Hodgins's photo

That's a great question!

I used to work in-office either as an employee or as a contractor, and I would regularly sit for 4 hours at a time bashing away at the keyboard, with small moments where I get up to get a drink or go to the bathroom, but I'd consider my 'session' length as half a day, split by lunch.

Then when I began freelancing I think It would get even longer. Sometimes I would work through the night, sometimes I could challenge myself and take a 12-hour block and see how much I could get done, so I know sometimes I was sitting doing the same thing for 4+ hours, maybe even double that regularly. But that's not healthy or sustainable.

I think now I spend a lot more time working, but I have much shorter sessions - 15 minutes, 30 minutes, 40 minutes, and hour or two. But rarely do I have a 'session' of work longer than 3 hours without being split up either by travelling, doing chores or running errands, meals, etc. And I feel more productive (overall) than when I used to sit and work for longer sessions.

My personal theory is that creativity is like a well full of water, and it replenishes slowly when you are inspired. So if you're building and creating things that takes energy out of you, and it takes time for you to recover before you can do that again. When I was doing those long sessions it felt like I was super productive, but I wasn't super productive like that every day, especially not after a big day.

Get up, move around every now and then, and try to let your work sessions be punctuated by little breaks so you can keep agood momentum overall :D

David Kamer's photo

CEO of UniWrighte Inc.

I used to break up my sessions a lot more, but lately I've been trying to stay focused on a single task for longer periods of time after reading something by Epictetus (a greek stoic philosopher) about how even a small amount of lost focus can hinder your over all ability to focus quite drastically. I don't think this definitively means or requires sitting and bashing out code for a long time, however I think it means that you should stay focused on the problem and method when you are trying to accomplish something. This goes for everything and especially coding. Here is the quote:

“When you have remitted your attention for a short time, do not imagine this, that you will recover it when you choose; but let this thought be present to you, that in consequence of the fault committed to-day your affairs must be in a worse condition for all that follows. For first, and what causes most trouble, a habit of not attending is formed in you; then a habit of deferring your attention. And continually from time to time you drive away, by deferring it, the happiness of life, proper behavior, the being and living conformably to nature.”

I don't think it matters what you're actually focused on if you consider it this way, just don't get into a habit of breaking your focus on the problem too much and then your sessions can be as long or short as is comfortable.

James Kibirige's photo

Software Developer

Try established productivity techniques like Pomodoro, they feature working intensely and in a focused manner with breaks after each focused stretch...

Xingheng Wang's photo

If you mean absolutely no breaks whatsoever as one session, then on average probably 30 min to 1 hour. If in the flow, sometimes longer. Usually small breaks can be good also, especially when nature calls or coffee cup is empty.

Hipkiss's photo

Co-Founder, Founder, Entrepreneur & Problem Solver

I tend to get a cup of tea every hour lol.

Anuj Sharma's photo

Depend on Bug. ;) XD

Jos Fabre's photo

I divide my time in a natural way. Your coding project is always a stack of short classes/elements/parts/scripts/features/task/... so everytime I completed a specific part I at least stand up to grab a glass of water.

Most of the time these moments are the same moments I commit changes to git, because a new feature is implemented. And most of the time these moments take anything in between10 minutes and one hour.

Vikrant Singh Chauhan's photo

Maximum of three hours. I usually spend a lot of time preparing, reading, and planning. After completely understanding what needs to be done, I start writing code. Before starting my day, I think about what needs to be done today. Then after exercising, refreshing, eating breakfast, I start preparing for the project. At 12:00 pm I start writing code and after lunch, I take a nap. A power nap makes me refreshed but I don't write code afterward. I just read and write till dinner.

jimoh hadi's photo

Software Engineer

Very interesting. Thanks.

Ritwik Sahoo's photo

Typically if I am in a groove and really want to finish up the work, I can sit down for 2-3 hours straight. But sometimes, it is not more than 30 minutes of coding and then taking break to rethink.

Samwel Opiyo's photo

It depends, when something works, I am usually excited and take a break of five to ten minutes. Before that I can code continuously even for up to 7 hours continuously. There are days I used to wake up and after washing up, get directly to work even without preparing a meal. I would then code up to very late in the evening without even a single meal.

jimoh hadi's photo

Software Engineer

Interesting. I have tried your method once, and it never really made me productive as I want. Nice seeing someone it's working for.

Vijay Thirugnanam's photo

I work between 1-2 hours without a break. And do that 3-4 times a day. Pretty long day for an engineer working in India. My recommendation is for people to work only 30 hours per week with 3-4 sessions of 90 minutes work per day. Keeps you productive and makes coding fun. And since I prefer to code till the age of 70, I can do this for long term.

Ingmars Lazdins's photo

Hi Jimoh,

I truly believe, that it depends on how much you really love the current task. I get mentally tired quickly (~2 h), when I need to implement a yet another "contact form", but I can get carried away and can easily work 12 h non stop on my hobby projects or other interesting opportunities. Regular breaks are mandatory though - for me it is a cigarette.