Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: How do you stay focused while programming/working?
83 points by flipfloppity on Dec 11, 2017 | hide | past | web | favorite | 51 comments
I often find myself "needing" to take a mini-break after just a few minutes of concerted effort while coding. In particular, this often occurs after I've made a tiny breakthrough, prompting me to reward myself by checking Twitter or HN. This bad habit quickly derails any momentum. What are some tips to increase focus stamina and avoid distraction?

Find something else to reward yourself with. For example, a drink of flavored water or a sip of coffee/tea. Also, try coding offline. I always do my best programming when offline– pencil and paper is the best.

If you've already implemented a method in pseudocode, you can use StackOverflow/documentation/Google/etc to look up the actual API calls once you're translating the program into code.

Do you have any examples of good pseudocode? I have tried this method but feel as if I am not doing it in an effective manner?

And while writing pseudocode how do you know the level of depth and detail to include.

Not OP and no examples at hand I can share, but I'll try and describe my process:

While not pseudocode per se - my offline coding is predominantly outlining structures and data flows; so how I would structure the application (classes etc - where what code would reside etc). Then I expand from the structure to start moving the data objects themselves around (also giving an overarching structure to the data objects as well), where the flow / control logic starts coming again. Sometimes I'll write a few transformers / mappers there as well if they're needed when sending / fetching data from a few places.

Usually you can speed this up greatly by following the conventions of a framework; for webapps I would design the models/controllers/routes/views, mobile apps would be navigation tree, views (screens), components, and if there's a lot of data, then mappers/reducers etc. So it's usually small descriptions (even one or two words) of what a given class/object/action is doing, where it's coming from and where it's going. I can then expand this to be very specific with fields, routes etc, and what they're all doing.

Having that basic, overall structure done offline means I can approach the coding with purely an implementation mindset and don't have to worry about the "big picture" when doing all the small bits - when you start coding immediately you're on a bit of a discovery path with the big picture, and the implementation details, and changing stuff on the fly etc, which can be rather time consuming / side track into different places and so forth.

Most of what I do is just take data from one place, change it somehow, and present it somewhere else - so it makes the above fairly easy and effective for my work.

This is helpful. Going to try this today!

Learn python. Seriously, I fell in love with python when I noticed it looked just like my psuedo code.

As to your question of depth, I start at the highest level if abstraction I can get away with, assume that some magic function exists and does what you need. If said function isn't in the standard library, implement it if it's simple, implement it, just know that you're getting closer to actual code the more of these functions you flesh out, and some of them are likely to be libraries, you'll want to look up later.

I fell in love too. Fist language that I actually was able to feel I understood. Its been about a year since I started.

Your feedback on depth is really helpful. Thanks!

It's not exactly new and exciting, but I found that listening to calm, instrumental music helps me focus. Mostly Ambient. If you do not like electronic music, Stars Of The Lid or Bohren & Der Club Of Gore are very much worth checking out.

Also, https://mynoise.net/ has worked wonders for me.

In both cases, it seems that unstructured audio input, like, occupies the parts of my mind that would otherwise distract me.

> It's not exactly new and exciting, but I found that listening to calm, instrumental music helps me focus. Mostly Ambient.

Same. Lounge, Ambient, Chillout, Chillstep (https://di.fm has a bunch of great streams. SoundCloud and MixCloud have complete replayable sets, too.)

I've heard that videogame soundtracks are designed to not be distracting; to help focus.

For ambient, I really enjoy Taylor Deupree: https://www.youtube.com/watch?v=v2hh2hAPyc8

My personal favourite for working (or unwinding or cooking or cutting your toenails), though rhythmic & structured electronica, would be Jan Jelinek's Loop Finding Jazz Records: https://www.youtube.com/watch?v=6hIgBEXuQD8

You might also enjoy http://chillingvibes.com

It's playing mostly chillstep and slow electronic music with decent or no vocals.

binaural beats are something similar. They've helped me focus.

I normally leave everything until the last minute which means I have no choice but to be incredibly focused and motivated to deliver on my commitments.

I've always had a reputation for delivering late but this has gotten better over time as I learn to account for unknowns and my definition of "last minute" has gotten more realistic.

Over the years I have tried fruitlessly to make myself more proactive and have consistently failed. I do my best work under pressure and am now focused on embracing who I am and finding a way to make that successful instead of trying to change it. There is a name for this - the Eisenhower method - but it's not a strategy I do deliberately, it's just naturally who I am.

So how do I focus? When there's no time to waste it just comes naturally. I take mini-breaks too, but then my subconscious very quickly kicks me back into gear.

Mini breaks are fine. Just blacklist certain things from your breaks if you find they're bad for you. I find "boring" breaks to be the best - sleep, looking at nature, chatting with a co-worker.

Discipline only goes so far. This doesn't happen if your motivation is high enough as you'd just lock back into the project once you've regenerated.

Treat motivation as a supplement. You might be looking at HN as your mind craves more motivation.

Think of people, not cash rewards. Who will this project help? Users? Stakeholders? If you have to think of cash, think of how you could spend it on making other people happier... donations to the poor, buying mom a gift, taking your child to a theme park.

You might also be motivated by creative impulses. Bookmark projects you admire. It can be roadmaps and devlogs. Open them up again when you're feeling demotivated or need a break.

I go for a smoke :-) But you could walk around the house or block. I get so many good ideas while sitting there smoking for a few minutes, in the backyard gazing into the trees. I think when/if I stop smoking, I'll pick a spot outside to go to and sit for a few minutes. Its pretty amazing, usually the answer to the next problem pops into my head. Probably the vast majority of my good ideas come in those few-minute breaks.

I signed up for brain.fm (http://brain.fm/) after it was posted here a year or so ago. Can absolutely recommend it!

Had a quick look, but don't like that they appear to hide their pricing. I will not sign up just to find out their pricing or "learn more".

Odd :-/ It was pretty transparent at the time. I believe there is a trial period. From memory, they hit the front page of HN, and the founders offered a lifetime membership for anyone linked to them from there for $30 or some such. Extremely good value for money, it turned out. Unfortunately, that means I don't actually know what current other plans cost...

Prescribed stimulants.

A lot of the good stuff is off the shelf. L-Theanine for focus. Creatine monohydrate for more RAM (thinking faster, less brain fog).

About stuff off the shelf: I bought Focus Pep (https://www.amazon.com/Addrena-Stimulants-Boosting-Dietary-S...) a year ago or so off Amazon (I believe they are only sold through Amazon). Well, they helped me tremendously. I would take them minutes after I would wake up and I would then consequently have a want and go for a three mile run every day of the week. Then I would go to several of my classes and be focused to the dot. You could even say, I felt I was in a confident "flow" state when I took them. I ended having an all time best sleep schedule, since I took them in the morning so by nighttime I was so exhausted I would fall asleep early and wake up early. But the period when I took them, I would get sweaty easily, my entire being would be jittery, and I would not feel hungry throughout the day. I eventually got off them because I didn't feel natural and at ease, I always had an anxious need to do something. Though now that I'm not on them, I'm more prone to: being sad, overthinking about things, having trouble falling asleep and getting out of bed, not having a want to exercise, etc.

Interesting formulation.

Try getting your hands on the tyrosine and the bacopa individually. Those two can be very useful. I take both.

The Vitamin B12 is potentially interesting; I have that in a spray form (on my table right here actually) which I'm trying to remember to take in the morning.

The caffeine is likely added as "energy sugar", ie to give the product a noticeable boost. Caffeine does work, but the toll it takes (and its predominantly psychological effect) is well known.

The Guarana seed extract, Bitter Orange Fruit Powder, DMAE, White Willow Bark, and Huperzine-A I can't comment at all about, but have been filed away.

The Carnitine and Choline I can't remember about right now... I think those are interesting, but I haven't properly tested my reaction to those just yet.

I'm guessing the pepper was added to increase absorption (it's supposed to rev the gut up and help digestion, and not in a bad way, but everyone works differently and sometimes this plan backfires).


When it comes to natural health, getting all the compounds individually and then figuring out the doses you need generally has the best effect.

This also means you shard your requirements between a bunch of different suppliers, so when one decides to go switch to a cheaper upstream and a week later you go "hangonaminute" and start suspecting your supplements as the reason your brain felt like it went out to lunch... well you can just switch the single compound. Comparatively, if you shop around different suppliers for a product you don't seem to react great to, you might find you eventually go "wait, what... how..." once you finally find the one supplier that prepares the product such that it _actually works_. (Don't forget these two. They happen to me more often than I would like. :<)

This is generally more expensive (agh, so expensive...) but the results are worth it. I have quite a few issues (anxiety, cognition/problem-solving, mood, memory, stamina, nervous system, ...) and, well, the only reason I'm not 100% on top of my game is because I can't afford to take more than I'm taking right now (which ironically is the reason I don't have the mental consistency to get a job at this point xD). The products do work.

Huh, I've been taking 3-5g of creatine mono every day for ~5 years and have never heard of it having mental benefits until now.

It's a lot like RAM. You notice it when you're not on it. I think the most obvious effect is humor... while on it, I'm quicker to see an opportunity for a joke. I assume it applies for finding breakthroughs faster.

you haven't demonstrated that you need focus, what you have tho is shown that you have a bad habit. Kill the bad habit, you are aware of it. So new Twitter or HN or any win. Replace it with something else, pump your fist. Have a win book, write down your win and move on to the next. If you have a todo list, cross it off. Best of luck.

right on, break the habit and focus will follow.

SelfControl.app is still my favorite Mac app ever. Add a list of sites to block, set a timer, go. I have a huge blacklist. I enable a 24 hour every night. This way I don’t even have a chance to start procrastinating the next morning.

The crazy thing is how many times you’ll try to go to one of your addicting sites even though it’s blocked. SelfControl acts as a great circuit breaker in this case, and can also show how bad the addiction is.

If I want to read HN, I have to do it on my phone. If I’m looking at my phone, I know I’m screwing around, so it doesn’t last long.

I built something just for email. https://dndemail.com keeps your inbox empty and only delivers your new messages on a set schedule. That keeps me out of my inbox and focused on my real to do list.

Could you share your blacklist? I've a very minimal one

It’s pretty personal by its nature. Basically every site I enjoy. Social networks, blogs, news aggregators, etc. One exception is that YouTube is allowed, since I never procrastinate by watching YouTube videos (thankfully it seems I’ve been spared from that particular vice).

Try the pomodoro technique, the concept is 25 minutes of work to 5 minutes of break time.

If anyone's interested in neuroscience and machine learning, we're working on a fun little project to use EEG to track focus and optimize productivity here: https://github.com/neurotechx/neurodoro

As interesting as an idea as this appears, I am hesitant to think that it would do anything other than distract me even more.

I've found FocusAtWill invaluable -- it's music designed specifically to keep you in flow. I use the timed function to ensure I take breaks at proper intervals, and you rate how focused you were during the session. http://ssqt.co/mQbYXSq (this link gives you $20 bucks off your first bill if you decide to sign up after the trial)

paper: https://arxiv.org/abs/1610.04255

"how it works" (with citations): https://www.focusatwill.com/app/pages/science-of-focus-conce...

I use https://www.focalfilter.com/

Its not 100% effective since I can still use my phone, but it helps. Unfortunately I haven't found a good Mac alternative that allows you to update your filter list in bulk.

IMO, the specific situation you're describing (wanting to check in on HN) does not have a 1:1 relationship with the bigger picture you're associating it with (focusing in general).

I've discovered that I also periodically want to check HN, imgur, etc periodically.

Fundamentally, this is because I really (really...) need to setup an intelligent social tracking system that tells me about interesting things that I will probably want to intervene in RIGHT NOW, whether inconvenient or not, because of some ascribed value (for example being able to comment on a relevant discussion, reach out to someone in the context of some opportunity, etc). I primarily check in on HN for this reason; "is there relevant discussion happening right now." While I don't have the system I just described, I'm trying to be it myself.

Of course this doesn't really scale or work, but it's incredibly fun to pretend I'm competently keeping up with everything because the activity of "just making sure" is one of those simple, predictable activities that has statistically low chance of disappointment (or concrete negativity/malice) and statistically high chance of low-effort reward (except for those 183 times where it was boring, which I ignore those because superstition is powerful), and... oh hey, there goes my day.

When I realized this recently I was able to at least stare the problem in the face. Now I can work on swinging in the direction of closure for this whole... thing of "keeping up" that I've deliberately been cultivating lack of closure of, for the sake of addiction, and hopefully get myself focused and back on track.

I guess the "one level up" scope/domain from this would be "online distraction", rather than focusing in general. I said a few related things on the subject a couple months ago: https://news.ycombinator.com/item?id=15418671#15423170

And I commented on the value of supplements in this thread over here: https://news.ycombinator.com/item?id=15904764

12 minutes of meditation* before starting work. Keeps me laser-focused for longer periods. (*=sit comfortably, eyes closed, focus on breath, gently resist mind wandering)

Nobody else goes for a nice sativa?

Do try to get evaluated for medical conditions; stuff like sleep apnea, ADD, smoking, depression etc. can all affect this. If you are suffering from something beyond bad habits that's very important to know. And I know several of these are cpnsidered to be overdiagnosed so try to see a serious therapist who will see you over multiple longer sessions before coming up with a diagnosis to get rid of you.

I've actually had a bit of luck with:

"brew install sbagen"

"sbagen /usr/local/share/sbagen/examples/focus/focus-03-a.sbg"

(Linux packages exist too.)

Don't expect anything huge, but the effect that I see with simple binaural beats is a slight calming and improved focus. It seems to quiet the urge to goof off and compulsively check sites like this. No it's not on right now.

Disclaimer - I wrote this https://betterself.io to help me out here. It's helped me get much better, but certainly isn't perfect. It's open-sourced at https://github.com/jeffshek/betterself/.

Someone posted this quote a while back, and it stuck with me. "Think of your mind every morning as a clean desk, and every time you get distracted via social, game, etc, you put something on it. It then gets progressively harder to do work with a messier desk. The best way is to just always have a clean desk."

I logged habits and supplements for over a year. Things that were effective were having a lot of strong routines that pull you in the right direction.

So things that helped were

X) Have some type of metric you are measuring to. For me it was RescueTime and WakaTime. How productive was I for this week compared to last?

1A) Have your phone on DnD or Airplane Mode.

1) Start the day off with SelfControl app. Add the timer to lock out all disractions until X PM every day.

2) Use a cold shower to wake up

3) Meditate

4) Eat the same foods that won't make you groggy / crap. This sounds masochastic in some way, but it's much easier than it sounds once you get used to it. For instance, the same oatmeal for breakfast is a great way to set a routine.

5) Track what supplements and food you were taking that improved productivity.

6) Inversely, see what supplements or diets you might be taking that does the opposite.

7) Set up a sleep routine. Melatonin at 3mg is a sweet spot. Getting six hours of sleep every night is the perfect amount for me. Everyone varies. The point is don't take "one size fits all advice" for something so crucial to your life. Less than 5 and I was easily distracted. More than 7 and I was groggy. There's a lot of information about how to sleep better. The point is to find a way to maximize sleep quality ... six hours in a city is going to be very different from six hours of sleep in a quiet area.

8) I've tried a lot of supplements. The most effective ones on productivity were ones that helped me with anxiety (so the opposite of caffeine). I eliminated a lot that didn't do anything.

9) Have a track / music that you listen to that starts you in a groove. For instance, I have a EDM Mixtape that I've probably listened to over a thousand times this year. You'll find that a lot of high throughout writers do something similar. The music helps build a habit of "okay, it's time to do work now"

10) Find the right setting / environment that makes you productive. Face a wall. Accept the fact if you can't work from home, then don't.

11) Go for walks when you're bored. Admit to yourself when you're not being productive and you're just spinning your wheels.

12) Exercise. Missing gym workouts (even though it was like 1-2 hours) was a sharp drop in total productivity.

13) Pomodoros. Start with 25 minutes and keep on going up (I average hour long Pomodoros now). When you get distracted in a Pomodoro, have a note card called "Distractions" and write what you want to to do there. That way your mind can stop obsessing about "New Avengers Trailer" if it knows it's going to get there after the break.

When you first start with Pomodoros, have a notebook of how many Pomodoros you did. Make it a goal to do just five pomodoros a day. You'll be impressed how hard that is initially.

14) No lying to yourself. Everytime I've said "this time is different for a YouTube video about anything mildy interesting", I've regretted it.

15) Plan for a social night at least once a week. You do need some rest. Self flagellation about not having earned it is almost a recipe of more anxiety and procrastination. (I'm not great at following this yet)

16) Have a deadline to finish something.

To give some backdrop, this has made me really productive throughout the last year without burning out. I've worked 60+ hours before at startups and just BURNED out, whereas now I can definitely push that easily without hitting that same wall. I integrated all these habits one by one when I was certain through quantitive evidence it was working.

Can't say much about helping social life though. This definitely takes a hit when you try to maximize productivity and flow at the expense of social life.

At work, I put on Moby for a few hours. At home, I just keep telling myself I'm not a millionaire yet, keep going.

Take on a more challenging project with deadlines, hopefully with a project manager that calls you at odd hours asking for updates. Your desire for twitter and hn will vaporize :)

I wish that's all it took, but there are some severe procrastinators for which that's not enough.

For others, yes, some people you have to remind to eat :)

Found a new job. Went from funding it hard to work 3-4 hours a day to 60 hour weeks being easy. Don't recommend that long as family everything.

Spotify. Some of the playlists are really good for focus(Deep focus, Mellow beats etc). I generally listen to ambient/postrock.

Use Pomodoro timer to help, give some short break after a long-time focusing.

I don't know if this will help you at all, but perhaps it will.

First off, I think there's a myth about productivity. That you are only productive when you are writing code. That's not true.

The way I work is that I need to have a fully formed idea of the solution to a problem before I start writing code. That doesn't mean it's the correct solution. But I have to start with an idea of how I'm going to solve the problem.

Sometimes that takes 10 seconds, if it's a new feature. Sometimes it takes 10 days if it's a bug I don't understand. Sometimes it's 10 hours for a totally new project. Could be anything. But I always start with documenting things in my way: offline. Your notebook and a good pen are your friends.

I do my best thinking at this state away from the computer and away from code. I do it best walking around. Once I think I know how to solve the problem (usually wrong for larger projects and bugs; usually right for new features in an existing project), write down what you intend to do on paper. I know Project Management tools exist for this task, but they don't have the same connection for me as physically writing something down.

As I'm doing that writing, I'll realize a lot of things that are bad about this approach and correct myself. And then my brain will start to organize tasks and group them. While I'm going through this exercise, I will set checkpoints for myself. If it's a ticket for a bug that needs to get fixed today, well, maybe I'll get lucky, and it's one and done. Other times, not so much.

I also try to organize my work segments vs. my thinking segments around my meeting schedules. Because even when my day is broken up by meetings, I'm still probably thinking about my problem.

Building in your checkpoints by planning your work this way has been very helpful for me, not because I need to check facebook or twitter or HN, but because it represents tangible progress.

But if you actually look at my workflow, it's a constant iteration of think a lot, followed by pounding out some code for a few minutes. Sometimes that ratio is very small on the code side, and sometimes it's quite large on the code side.

Without making comments as some other people have about medical or mental problems, I would suggest this: that there's a lot to be gained from working in very small chunks and that if you're worried about momentum, perhaps that's the problem you should be trying to address. Momentum is a tremendously overloaded word, and you shouldn't be trying to evaluate yourself based on your ability to obtain or maintain it.

I have a fairly similar pattern to what you are talking about. Solve a thing; then think about the next thing; then solve that. No one has ever complained about my productivity. On the contrary, people sometimes wonder how I can get so much done when I spend so little time "working."

Different people work in different ways, and I don't think that's a thing to worry about. I've really never very much experienced what people call the zone in programming. I certainly do as a musician when I'm practicing my violin. My girlfriend hates when I practice violin because I absolutely cannot be taken out of that mental space.

As a developer, I don't care about the context switch or the momentum or focus. I can go back and forth. No big deal. So I can understand why this can be problematic. But it might not be.

Questions to ask: are you being told that you aren't productive enough? Are you feeling like you aren't doing good enough work? Or enough good work? Where is this criticism coming from? Is it external or internal? Why do you want to change your patterns?

One of the things that technology companies need to realize is that there are more ways to be productive than just by being in your chair.

I'm my most productive when I'm not writing code. I'm my most productive when I'm solving the problem. And then the code is just a translation of what I've figured out.

When I follow this path, I find that my thoughts are more often wrong than right, and I don't have to worry about getting up and thinking or rewarding until I've fixed my thinking about the problem and proven it to myself through code and tests. And when I get into that mindset, I can't stop until I've corrected myself and crossed everything off the list in my notebook.

Take that for what's it's worth. I'm just one person. And I could be wrong about all of this. But I think I understand a little of what you're talking about, and this is how I deal with it.

A short walk and breath of fresh air is one of the more consistently serendipitous things that help creative work. Music helps too, though silence can help too - it depends on your emotive response at the time I guess.

"Brain dumps" - the act of transferring mental information to another medium can itself be a great mental relief. eg.:

- drawing diagrams w/ pencil and paper. things are more complicated than we first imagine them, often... remember, "the right perspective is worth 80 IQ points" - alan kay

- debugging by talking to yourself out loud

- post-it note reminders everywhere -> your short-term/working memory doesn't feel cramped

It is possible, maybe, that you are a bit concerned about enjoying programming/working to the fullest extent.. because you expected it to be more enjoyable. All that said... good focus is not just maximum momentum -- what you are really asking about, imo, sounds like a question of laminar vs turbulent flow :) To go "down the rabbit hole" with great momentum, versus a fragmented mind pulled apart in every direction with equal momentum :P Well, we all know how time flies when you're having fun, or enjoying good company, right? Yet it almost seems you are asking for tips on how to make time fly when it shouldn't, hypothetically kinda like this:

>"if -- while I am working on something difficult -- I had the capacity to just make time fly quicker, then I'd have no problems with stamina or keeping focused, by design. Furthermore, it would be a momentary-enough challenge to /become fun/. So how do I hasten the passage of time when work is hard?"

The answer to this is: unimpeded flow = mastery. Extrinsic obstacles are easy to spot but one's intrinsic obstacles take much longer to become aware of..

Only after intuition replaces the tendency to hesitant deliberation will deliberate action come easily. As you gain experience, you subvocalize less and operate 'fluidly' at the right mental level of semantics.. With mastery comes the use of "the voice as an object that can be seen as the lever of thought" [0]. Just think of the last time you were amazed by a display of talent or performance by someone that left you so amazed you wished for a few minutes more of their time.

imo, to solve your problems, you have a few options:

- you could improve to the point that coding gains a new and desiring appeal.

- you could find something (or somebody) with exceptionally inspiring talents to code with

- or, you could look deeper into yourself, and see if the focuslessness is really just a desirelessness

[0] https://mitpress.mit.edu/books/voice-and-nothing-more


I don't stay focused. I'm a human not a code robot.

Pomodoros, and brain.fm

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact