Writing software well (or even reading well existing software ... which is a must, when someone needs to learn, or just maintain old code), seems to require a combination of cognitive skills.
That combination can be detected, even when a person has no previous programming experience: http://www.eis.mdx.ac.uk/research/PhDArea/saeed/
.
From the linked homepage:
>> We (Saeed Dehnadi, Richard Bornat) have discovered a test
>> which divides programming sheep from non-programming goats.
>> This test predicts ability to program with very high accuracy
>> before the subjects have ever seen a program or a programming language.
From the linked homepage:
Edit: added the note about reading software.