Ask HN: I lost my ability to focus for hours on coding. How to regain?
How to regain my focus and avoid this trap?
How to regain my focus and avoid this trap?
Eat well. Sleep well. Exercise. Dress for success. Socialize, integrate with the team, find the goals that will motivate you - be that helping out your work buddies, or building that sweet new piece of technology.
You want to have energy, health, mood, and motivation. When any of these suffer, your work suffers too.
Don't be afraid to use whatever tools you have at your disposal to cut out distractions and inhibit bad habits, but don't tyrannize yourself either. Working 8 hours straight isn't necessarily your most productive option. Consider scheduling breaks - but use your tools to limit your distractions outside of said breaks. Find a balance that will let you keep your mood up while also getting good work done.
That said, while I've cut back a lot, you can pry my energy drinks out of my cold, dead, caffinated hands.
One of these is not like the others. I can understand emphasis on dressing up in contexts that involve selling -- a product, an idea or even yourself. But what does it have to do with focus?
But if you're showing up to work poorly shaven, wearing stained sweatpants - you're going to be at least a little more self concious, a little less self confident. Nobody's going to lift your mood with "hey, looking sharp!". It's going to reflect in your body language, and the body language in your peers, even if it's largely on a subconcious level.
It's potentially the difference between being ready to walk to lunch, or a meeting, or an interview at a moment's notice - ready to actually tackle the work and the day - vs being ready to go to bed at a moment's notice.
That said, it doesn't need to be a 3 part suit.
Fwiw, I'm in my mid 40s and have less than a year of treating my sleep apnea. I'm pretty sure I've had ADHD my whole life but blamed other things until recently. I'm trying to resist getting medicated, but I think I might it to get me focused enough to work on CBT and meditation.
The thing is, I can focus on stuff I really want to do, but I can't fake the want. So - my personal pet projects are doing fine. As for work, my life has improved tremendously since I sort of gave up careerwise. These days I drive a bus and actually have some mental energy left over for my sparetime. No medication. I don't like the idea.
If you have medical issues - take care of medical issues in the best way possible.
Challenging yourself = denying yourself treatment.
Challenging yourself is not a treatment for something like sleep apnea.
This statement is so out of line I had to chime in. I was diagnosed with ADHD as a child. I was medicated for a few years, before I stopped taking the pills without telling my parents (they were being pressured by the private school I was in to medicate, I was kicked out shortly after they found out I had stopped.)
Those years are a complete empty window in my memory, and left me with physical ticks that _decades_ later I still have to suppress, alongside no actual tools for dealing with the symptoms.
Medication is not a silver bullet. Not all ADHD cases need to be medicated. Find what works for you, whatever the hell that is, and don't listen to dogma. For me that was coping mechanisms combined with a realization that much of the "attention deficit" was because I _didn't want to pay attention to the shit I was supposed to_ and _that's completely reasonable._ To insinuate that I haven't tractably found success ("baseline normal") with a non-medicative approach in my life is frankly insulting.
Parenting is stressful and imposes a powerful incentive to reduce that stress. Consequently, too often in children, mental health treatment focuses on controlling behaviors because the person seeking treatment is the parent.
The first is a person seeking greater agency for themselves over a problem. The latter is a denial of agency of the child. I’m hearing you express your pain at having your agency suppressed and expressing skepticism at the tools used to suppress your agency.
But those same tools also grant some adults an agency they are desperately drowningly seeking for themselves.
Genuinely interested in hearing your story.
2. In large part, reminders. Notes, lists, alarms (calendar/phone alarms for _everything_, watering plants to finishing work shit), behaviorally trained prompts, anything to disrupt the "mental feedback loops" where I can find myself "unconciously" falling into something like tearing at my fingernails, reading HN, playing video games, or really any of the infinite things I'll come up with to not do what I should be doing.
e.g. even right now writing this, I'm being pinged to go back to reading PRs: after years of having automated browser alerts going "hey you shouldn't spend time in this video game/on hn, it's been 20 minutes and you have nothing to show." my brain has picked that up and is able to do it on its own. I found that hard blocking didn't work since I'd just find ways around it, but if I can remind myself this is something I _want_ in any way from pragmatism (mortgage) or emotional (getting wife nice things) whereas the games/Hn are actually _unwanted_ (despite what the dopamine might say) it's easier to force myself to focus on something I don't want, even in bursts. (getting myself to internalize and BELIEVE those facts took years and I still fight with sometimes when willpower is low.)
This was a bit of a ramble, and I'd be remiss to mention that the motivation to use the prompts would be missing without the philosophical context I assign to the things I do. (Disclaimer: I recognize not all people can use this technique, I simply use the fact that I have strong long-term motivations against my bad short-term focus) I mentioned it in passing (mortgage, wife, etc) but really finding things I _WANT_ and using my brain's likelihood to fixate on those, especially in periods of distraction, I can tie those things back to what I SHOULD be doing and create a virtuous cycle. Contrivedly: Distracted looking out a window at garden. Fuck, I can't afford this garden if I don't go back to coding. (Dang, this HN post is getting long. Better get back to work so I don't work late today and can spend time with the wife when she gets home :) )
1) stimulants and narcotics are two very different things, with diametrically opposite effects.
2) Not everyone can improve performance, due to U-shaped response curve. Those that are functioning optimally will actually see their performance decline.
3) ADHD is one of the best understood disorders. Impaired working memory (i.e. ability to concentrate) can be easily diagnosed quite definitively with CPT: https://en.wikipedia.org/wiki/Continuous_performance_task
It is of course personal choice in the end to decide on treatment, but if the ability to concentrate is in the bottom 1-5% - it is going to be painfully obvious to any half-decent paediatrician.
(uk private in my case, though I imagine people in other places would benefit from wider answers.)
CPAP only works on the expiratory valve - which is your soft palate.
If you are having a large number of arousals, despite optimal CPAP pressure, and your respiratory waveform is jagged in certain ways (hard to describe in text) - you are very likely having epiglottic collapses.
However, epiglottic collapse can only be definitively diagnosed by sleep endoscopy.
Epiglottic collapse can only be treated surgicially.
In my experience: its hard to get started, but when I'm in the flow I know that I can do this. Start with simpler tasks (small wins).
There's an occasional crunch where I have to heads down get something done, but in that case there is actual motivation to be heads down and get things done.
I find a due date way more motivating than a mere thought of "I should be working...".
Overall, if I'm not already focused in, it's because it's something not as important as other things in my life.
echo "127.0.0.1 facebook.com twitter.com ycombinator.com youtube.com" >> /etc/hostsecho 127.0.0.1 facebook.com twitter.com ycombinator.com youtube.com>>"%WINDIR%\System32\drivers\etc\hosts"
At least for me, productivity requires momentum and being at a standstill feels like quite a hurdle. So at least at first, work on something you're really excited about. Something that won't feel like work. It could be a small project you couldn't otherwise really justify spending time on, but do it anyway. Visualize the end result, get yourself excited, and finish it.
Once you've gained some speed you should be able to tackle other tasks and projects. Social media will start to seem less compelling than it does now.
But to make any of it to stick I had to stop thinking of my productivity as some intellectual problem and myself as the master of my attention.
You’re not in control of most things. You’re trying to steer an elephant. Accept it, it’s easier and it’s true.
Then — with a slightly more realistic view of yourself set up processes and guardrails to keep your brain in line. Stimulus control sounds like a good first step. Check out StayFocused for Chrome and then delete all other browsers.
Add or remove one thing a week until you’re where you want to be. Good luck.
It's old knowledge but : "A Healthy mind needs a healthy body" stays true.
Things I did to get my focus back:
One is that I introduced sugar/caffeine back into my diet. Drinking a sugary, caffeinated beverage improves my ability to concentrate significantly. While this might not be right for you, you might find that some of your other dietary choices are affecting the supply of glucose to your brain.
Another is routine. If you had the ability before, you can get it back again. One thing that helped me return to my groove was listening to the same music I used to listen to while concentrating. Having an album in the background on repeat can work wonders. Maybe there are some other important concentration triggers that you need to tap into.
Lastly, maybe your work just isn't that interesting. Rediscover what things you actually want to be working on. Get excited about something again.
Some people will claim that is a crutch. Thats a great analogy because crutches help you get things done while you heal.
On Windows, I add websites to the hosts file as others have suggested: HN and Google News are the main ones, I gave up FB long ago.
Doing this still doesn't get you back on track coding / focusing, but it helps. The idea is to break your habit of visiting distracting sites - where these apps help - but also build a habit of work. The more you make it a habit, the easier it becomes over time.
There's no light at the end of the tunnel right now. It's the worst feeling I've ever experienced. I know what I should do but I can't.
Having experienced this myself recently (a few months ago, for about a month acutely), the solution that worked for me is to cut the cycle at the "inability to focus causes stress" part. Just accept it - right now, you can't focus, and that's okay. The second part of my solution was to remove all distraction, and for periods of work I allowed myself to not focus on work, but I also agreed (with myself) to not allow myself to focus on other things, either. Eventually, a combination of stress reduction and simple boredom got me working productively again. :)
I've experienced this before, and last time I used medication (Adderol) to fix it. I think that's a valid way to break the cycle too, although I would recommend the above procedure first.
Note: This is a special application of the more general observation that most suffering comes from feeling bad about feeling bad, not the original feeling bad part. So, if you can stop feel bad about feeling bad, you don't have to worry about the first-order feeling - it will go away on it's own quickly, because feelings naturally decay pretty quickly. Also, if you want to talk to someone you can contact me via my profile.
Electronic music also helps me, but this is counterproductive for some.
My coworkers usually get a slight shock when they learn what kind of music I have in my headphones during work, being a 50 year old guy :)
There may be a free trial, and I think there is a free tier with ads if you can tolerate them.
I write down a list of tasks I want to accomplish that day, and then tick them off as I go. Once I get to the end of the list, I'm done for the day and can have a beer (or go to the gym, depending on the day) :).
Then the next day it's rinse/repeat.
Learn to live without social media -> watch your life improve.
It's as simple as that.
Delete your accounts, including Twitter. Find other ways to stay connected to timely information. Treat it as a good challenge that you _can_ succeed at, as something that will make you stronger and healthier in the end.
You can try and force yourself to focus with tools and mental tricks, but that always seems to make me feel worse. Better to get at the root cause, which is almost always stress or physical exhaustion.
It's kind of like chat roulette (before it got weird) for study buddies. I'll admit the premise is a bit odd butt don't knock it until you've tried it. Essentially, you're paired with a random partner for a 50 minute mostly-silent video chat. You spend the first minute or two saying a quick hello and each definitively stating what you're going to accomplish in the hour and then you get to work (separately - they're very clear it's not for collaboration). When time is up you both report back on whether you did what you set out to do. And while you get to work the corner of your screen has a little live stream of your partner diligently working.
Not only does it help keep me "accountable" and working pretty efficiently for the full 50 minutes but it's also made me so much better/more realistic about estimating what can be accomplished in that time.
When I'm hot on a new video game, I can't wait to fill the most immediate next hours on doing it. What was that for you at some point? I enjoyed QBasic in gradeschool and revisiting after years in the field was really fun.
Whatever that code is, I suggest pursuing it even if it's not
a) something everybody on here says we need to be doing
b) related to your dayjob
c) related to that "big project" that you need to do perfectly
I wish you the best.
P.S. strike perfectionism out of your mind
P.P.S: Practically look into using the Pomodoro Method
P.P.P.S: Either start or stop doing drugs. Or see a board-certified medical professional if you think that would be dope. It is.
edit: formatting as always
In my case, that's a chatty coworker. Every time he yanks me out of my flow, I get the urge to check social networks and have a really hard time going back to deep work.
Quick and dirty hack is change your surroundings. Go to another room, sit at different desk, on different chair, on a different clean computer (with different os?). Don't open any of your usual distractions there. Block them in hosts file (don't even check if you blocked them successfully).
You'll regain bit of your focus. At least till you leatn to slack off there too.
The void feeling is Depression. Youtube distracts from it, but reliance on distractors is only a symptom.
There are many kinds of depression, distinguished first and foremost by what treatment works on each.
That is the reason that "gold standard" double-blind trials fail to find that anti-depressants work. Imagine if you couldn't distinguish a broken arm from a broken leg, a broken humerus from a broken ankle. Trials of a cast on the left lower leg help only a few people, on the right only a few; left upper arm, right forearm, yada yada. "Casts are ineffective!"
Take the wrong meds, nothing happens. Take the right one, miracle!
There is no shame in medicating a problem: "If you can't make enough of your own serotonin, store-bought is fine."
It is entirely possible that losing 50 pounds, or exercising devotedly, or dropping carbohydrates and alcohol from your diet would also fix it. Medicate first, and then see if those help. There is no end of benefits to these other measures, but you need to get your brain working right first, or you set yourself up to fail.
In my case I was fixed up only two days after getting a sufficient dose of the right thing. A smaller dose had no effect, and other meds had no effect. Some kinds take weeks to build up before anything happens. I had five serious side effects (dry mouth, jaw clenching, ears ringing, dizzy spells, one more I don't recall) that passed after a few months.
You can get past this, with help. Get help!
You'll have to find a way past that fear. You can:
1. Be braver - admit you're afraid and do it anyway.
2. Find the root cause of fear. Maybe you've dealt with too many death marches. Maybe you don't feel like you can meet your expectations. Just admitting it can make it go away.
3. Plan it out in a way that nobody can screw it up, not even you.
A family friend of mine used to play violin in a traveling rock band. He slept in the van and loved every minute of it. Later, when he had a family, he settled down and became a contracted fundraiser for non-profits. One day he came across a particular non-profit that he loved, identified with, and felt excited by. He took a 50% pay cut and settled into a permanent position with that company because "it felt like being back in the van again"
If you're the kind of intrinsically-motivated person who can trick their head into being excited about 12 hours of being immersed in a problem, then you'd be an incredible asset to any company that gets you excited.
If you have an idea of what company, industry, or problem that might be (good news: people usually do), pursue it like hell.
See if other "distractions" take their place.
If no, then you're just addicted to social media and hopefully that month will cure you.
If yes, you're probably burnt out and need to move to your next exciting new job, or move house, or go on a road trip for a few weeks or whatever it is people to deal with burn out.
You've essentially developed a habit. Like others have said, this might be caused by various factors, so look at what's lacking in your life and try to fix that, but afterwards you may need to create a plan in writing to correct the behaviors of the habit that has formed, because otherwise, even if you fix the root cause, the habit might still remain.
As for how? That's a good question that I don't yet have the answer to. I'm working on the first part myself. After I fix my root cause, I think I will fix the habit via a combination of lists and daily resets (i.e. no old tabs on the computer the next day).
If you are a writer, and you’re stuck writing a book, you write something else for a while. If you’re a painter, you might try using a new medium.
You’re a programmer, so try tackling a completely different small problem. Maybe take the opportunity to try a totally new (to you) language — don’t be afraid to use something radically different. Ever code in assembly? Why not!
Some people work better when they’re “in the spotlight.” Twitch streamers are often known for entertainment, but actually many coders show up there, too. You could try starting a stream, and see if you are more focused when people might be watching.
Social media and Youtube may be stealing your attention because you simply enjoy them more. If coding was more enjoyable, you'd be doing more coding at the expense of those distractions.
But maybe you just don't enjoy coding your current project. A lot of projects are not intellectually or morally stimulating, and it's hard to stay excited about them, particularly if your work culture is the least bit toxic.
Being a manager means dealing with people, and a lot of experienced coders actually get more out of that than out of JIRA-code-Git-repeat.
It basically boils down to understanding the negative effects of your work and taking responsibility for your mental well being by countering them which is where work life balance come from.
Previous HN discussion here: https://news.ycombinator.com/item?id=1203696
I was having focus issues, because coding is fascinating but not inherently sexy to me. After working on a problem for a while, the enjoyment of the problem would become overshadowed by my sex drive, and I would start to find anything else more interesting. Ended up being my body's way of reminding me that I should make some babies before I died, so I was subconsciously distracting myself away from anything fascinating that wasn't the opposite sex.
Crude, well... to be honest, because of the slang words, eg. 'getting laid' and your argument could have been framed better to be more intellectually stimulating. Taboo, well.. because I don't see anyone else talk about this, yet it's such an important topic of human psychology / sociology.
I definitely could've swapped out "getting laid" with something more elegant sounding, such as "engaging in intercourse" or "stimulating a release of oxytocin", but I assumed that "getting laid" is both socially acceptable and has a well understood definition. Apparently HN disagrees!
I don't consider sex as a subject to be taboo, especially from a health standpoint. People get degrees from major universities that are entirely sex-related. So I guess I'm just a little confused by all responses, especially the one from hi41. Thanks for explaining your reasoning, it's good to hear the process behind these differences in opinion.
https://wiki.nikitavoloboev.xyz/focusing
Mostly it’s about practicing mindfulness throughout the day, setting goals, GTD approach of task management and using tools like Focus for automated Focus sessions throughout the day with breaks in which I am allowed to read news and relax.
Also, might give me some inspiration to make my own wiki ;)
I have no useful tips to add beyond what's already been mentioned here. The only thing I can suggest is to clarify if your _job_ might be the real problem.
And many people do program outside of work. Not necessarily big projects, but things like AoC, ProjectEuler, or just learning a new language/framework.
But yeah - I believe more programmers don't rather than do.
I’m married, above 30 with a lot of things going on in my life. And often my co-workers make joke about me going into ZEN mode when working.
Don’t look for a magic tricks. It is as simple as you hear from everyone. You just need to be patient and stick with them long enough for your brain to get use to it.
I’m careful about eating and sleeping. Having enough fun. I put my phone away while working and resting. I use Pomodoro technique to make sure I have enough short breaks and I have a goal. And I know very basic of meditation breathing technique (learned literally in 30mins). I only drink one cup of coffee on the morning and one cup of tea on the afternoon.
There's something about the phone that just keeps me distracted. So, I just don't bother with it.
You could also try browser extensions, e.g. for Firefox: Mind the Time -- shows stats of internet usage; LeechBlock NG -- blocks sites.
If you spend too much time on facebook, it could be because that is the lowest-effort way to keep up with friends you value. Message 4 of them and schedule a time for a phone call. Better yet, schedule a recurring phone call.
This happens to me at my three-hour university lectures. Some days I am emotionally tortured and cannot focus at all. Some days I am emotionally healthy and can focus through nearly the whole thing.
The best solution is to simply delete all your social media accounts that you don't use professionally (strategically).
Also look into your diet, too many carbs / sugars could make you sleepy and are not good for your concentration skills
The quicker you distance yourself from social media the healthier you will be. There's literally everything to gain by leaving it behind.
Try a side project or some library or module that you’ve always wanted to write.
I started working on something that I cared about.
Slowly, over 3-4 months, I regained it.
TL;DR: Reduce cognitive load.
Rule 1. Make your environment conductive to focus.
If you are in an open office, you have a shit sandwich to start with. So isolate yourself from the cognitive "filth and rabble". Long time ago I worked with a guy who built a cardboard wall and then wired a camo net over his cubicle, but maybe one doesn't have to go to such extremes.
Headphones: Use headphones and music to drown out co-workers talking and other noise. I don't play my absolute all-time favorite tracks on repeat, I play something I merely like: noisy stuff like some desert sludge metal or stoner rock -- I sort of tune out the music and the music drowns out all the noise. You'll need to experiment what music works best for you. I use Spotify and try to improve my playlists with new interesting music.
Tune your programming environment to have a look-and-feel that fades to the background. Nicer and duller colors. Learn all the shortcuts to be effective, and learn a powerful editor which gives you macros and regular expressions and whatnot. The less mouse you need the less mini context switch which is better.
Turn off audio notices, turn off all blinking "hey you have mail".
Rule 2. Coffee/tea in moderation.
Too much of too strong coffee within too short time makes my focus become scattered. My mind starts to get racy. The best thing is to dose coffee such that one doesn't go over the limit. A tea in the morning a few hours after waking up works quite well.
Rule 3. Notes and checklists.
It helps to be a compulsive note-taker. Before I start anything, I make sure to have a vague idea of what to do, then I make a checklist. I write down notes and think of next things to do while waiting for something. I do "self-retrospectives": when I'm done with a few hours work, I go through it and make notes and checklists of next things.
The checklist lives all the time, new things get added and old points get marked as red cross (not done, bad idea, didn't work, etc.) or green tick (done, clear, good idea, etc.). I use a program called Zim but you can do it with any editor.
Rule 4. Train your memory.
I've noticed it becomes easier to suppress problems from tiny context switches that way. One is less likely to forget the context prior to the interruption, and the notes help a lot with this, too.
Rule 5. Rest to recover.
When you're not at work, you're not at work and you should not be thinking about work either. Exercise, read, do something else you like.
Well, don't do it then.
> If I do not do that I feel some void and feeling of losing out
This is a minor discomfort. You need learn to cope. You must be young and healthy now, but the reality is that down the line, you are likely to develop some sort of permanent injury/impairment that you will have to cope with for the rest of your life. Start small, learn to cope with that little bit of discomfort.
Not to belittle, it's actually a major and widespread problem. Avoidance of minor discomforts is literally what keeps people smoking until it kills them. It's what holds people back from achieving the best life they can have because they avoid all the little risks that add up to big opportunities.
You have a will, you're not slave to your whims. Take control of your life and earn some self-respect.