In my circle of friends those who know how to code really well often also master one or two musical instruments really well. I don't know of any other profession where there are so many good musicians. What do you think is the reason for that. How does good code relate to good music?
Both require the learning and manipulation of abstract symbols whilst performing 'in the zone'. Programmers and musicians both learn to weave these abstractions into a larger, continuous tapestry. Musicians stream notes into music, as coders stream logic into a program.<p>However you'll also find it usual for excellent people to excel in many areas, so the real question here is - How many professions do you have in your circle of friends? I would expect there to be similar correlation of musicians in any other occupations which require timing, dexterity and creativity.
Musical ability has long been known to cooccur with mathematical ability. If you rephrase this question as "why are great coders often also great at math?", you might find it less surprising.