If I have ADHD, how can I focus on programming task for hours? Already in 9 years, I was identified as ADHD child. I was quite obviously weird.

I can observe many known symptoms of ADHD even now.


I'm unable to focus on stereotypic tasks which results in many failures in work, where I'm usually supposed to assemble electrical devices.
I often just stop listening what somebody is talking directly to me. This happens so often that I stopped pretending anything what's so ever. I just say "Sorry, I wasn't listening. Could you repeat it?". Friends just repeat it, other people are usually so shocked that they repeat it too.
In school, I always used to draw stuff al over my notebooks instead of paying attention. But I think even totally normal people do this. Maybe just not as much.


Now while this all happens, when I have an interesting programming project I can focus on it for hours. Yes, it's true that I often distract myself with various details instead of doing the main task, but generally I'm still concentrated on some intellectual task without losing train of thoughts.

So where does my problem disappear?
If you don't focus, then your efficiency easily drops to 50% of other people. But if the task is truly engaging you, you work 200% compared to other people and you forget everything else.

This has a name: Hyperfocus!


  Like distractibility, hyperfocus is thought to result from abnormally low levels of dopamine, a neurotransmitter that is particularly active in the brain's frontal lobes. This dopamine deficiency makes it hard to "shift gears" to take up boring-but-necessary tasks.
  
  "Children and adults with ADD have difficulty shifting attention from one thing to another," says Russell Barkley, Ph.D., a research professor of psychiatry at SUNY Upstate Medical University in Syracuse, New York. "If they're doing something they enjoy or find psychologically rewarding, they'll tend to persist in this behavior after others would normally move on to other things. The brains of people with ADD are drawn to activities that give instant feedback." http://www.additudemag.com/adhd/article/612.html
  
  Hyperfocus is an intense form of mental concentration or visualization that focuses consciousness on a subject, topic, or task. In some individuals, some subjects or topics may also tend toward including daydreams, concepts, fiction, the imagination, and other objects of the mind. Hyperfocus on a certain subject can cause side-tracking away from assigned or important tasks.
  
  Hyperfocus may bear a relationship to the concept of flow.[1] In some circumstances both flow and hyperfocus can be an aid to achievement, but in other circumstance or situations, the same focus and behavior could be a liability, distracting from the task at hand. However, unlike hyperfocus, "flow" is often described in more glowing terms, suggesting they are not two sides of the same condition under contrasting circumstance or intellect.
  http://en.wikipedia.org/wiki/Hyperfocus


On a more personal note:

I've been doing programming since I was about 16 y.o, I was diagnosed with ADHD at about 24, and I have now been working as an in-house hired developer for a year.

I personally experience that when I work on a topic that honestly interests me and engages me, I will be more focused and have more energy than everyone around me. I've been told by friends etc several times "God, how do you have time for all that? How are you able to do all that?"
At the same time I can be incredibly inefficient with my time on less interesting tasks. Often I don't even understand what I've spent all my time on, because I haven't really done anything.