Other than treating what is possibly ADD, what has helped you focus and just get your fingers on the keyboard?
Edit: perhaps I should add, I’m not really distracted by exernal things but perhaps the complexity of the problem / poorly engineered code just adds so much inertia to getting the fingers typing away. I’m a prototyping research scientist so producing well written code is not my strong suit, it’s more like let’s build something new and see if we can get it to work.
A few tricks..
1. An ADHD diagnosis looks at 5 areas, Activation, Effort, Memory, Attention and Affect. I struggle with Activation and Effort.
If I am inactive, I now know enough to say, "Activate!" And this gives me a trigger to change my behavior.
2. ADHD folk oft describe a phenomena where they excel under pressure or when doing tasks for others. There was a recent thread on /r/adhd where people offered to clean other's houses because they recognize they don't do things well for themselves!
As a mental trick, I externalize myself. I create myself as a person I want to do things for. Part of this is recognizing that when we do things for others, like cook a great meal or do a spring clean, we don't expect them to appreciate every detail of our work. We just want to impart a feeling of deliciousness or well-being. Similarly, do not ask your future self to marinate in every detail of your work- the goal is the overall feeling.
3. Thanks to life experiences, medication, and a lifelong infatuation with builder games like Factorio, I know what I am like and what I can do when a project engages me and I give it my full effort. Identify, Organize, Create/Act, Debug, Repeat. I now understand that moments of inspiration, medication, and grit & discipline are different paths to attain this state. Thus I have some control over summoning that state directly.
4. I now understand there is an emotional signal sent by the cerebellum that facilitates executive function- the impulse to get stuff done. Physical exercise, eating well, sleeping well, core things that reduce depressive feelings are correlated with improving executive function. Embrace it, treat your body well.
4. ADHD research & brain scans have identified two key mental states. The first is DMN, a passive-receptive state where memories and stimuli flow more freely. The second is TPN, when we become focused on tasks and the brain inhibits these stimuli. In people with ADHD, the DMN rarely quiets down. So now I can recognize that engaging with memories, good and bad, and various stimuli, are a part of how I function. I can somewhat identify that function, accept that its happening and maybe interfering, and politely ask it to relax.
I hope this helps.