How we program
I’ve always wondered how we do programming. Code can be so clean and straight-faced, but when you step back and try to think about how you write it, a darkness descends. It’s tempting to think that your brain is working like a computer program, transforming a symbolic problem into a textual answer as sourcecode. But I don’t think that’s what is going on at all — if problems came specified in formal language, then programming would be a very different experience. We instead start with a mess, and try to find all the problems in it through the process of designing and writing code.
There’s a lovely paper called Mental imagery in program design and visual programming by Marian Petre and Alan F. Blackwell, with many great quotes from programmers trying to introspect on their work. Here’s some tasters:
“ … it moves in my head … like dancing symbols … I can see the strings [of symbols] assemble and transform, like luminous characters suspended behind my eyelids … ”
Programming is a dance of symbols behind the eyelids. Write that into a QA standard.
“It buzzes … there are things I know by the sounds, by the textures of sound or the loudness … it’s like I hear the glitches, or I hear the bits that aren’t worked out yet … ”
This programmer is describing re-purposing their sense of hearing to produce computer software. Quick, strap them into an fMRI machine!
“values as graphs in the head … flip into a different domain … transform into a combined graph … (value against time; amplitude against frequency; amplitude against time) … ”
Hmm programming as relationships within abstract spaces, and relating those spaces to one another. A nice model for thought in general, perhaps?
“It’s like describing all the dimensions of a problem in 2D, and in the third dimension you’re putting closeness to a solution.”
Another, rather different spatial approach, where goodness of solution is somehow represented by something like height.
“ … oh, that happens over there … it’s on the horizon, so I can keep an eye on it,but I don’t really need to know … ”
Exasperating, and sums things up nicely. This kind of introspection is just too hard, so much of these thought processes are entirely sub-conscious. For example you try for hours to solve a tricky problem, give up, then the answer pops into your head while you’re cycling home, otherwise thinking about dinner.
That said, while the above evidence is purely anecdotal, it gives some hints about what might be going on. I like to think that programmers tap into a general human ability to organise a messy world into far tidier problem spaces, and find their way around such spaces in much the same way as they do when bumping around in a pitch black room…
I tried this myself and I think what you’re seeing is really a well-trained sense of intuition. Let me expound a little:
Do you remember when you were a child and you saw a toy for the first time — the initial curious reactions are important in training the brain to recognize the toy and then the mechanics of dealing with the toy. Much like when you’re learning a programming language, the initial reaction of the brain is to try to recognize the patterns and then the problems to which certain solutions can be applied to.
So it’s a combination of the curious nature of the human being and the ability to intuitively apply solutions to problems usually iterating through many possible solutions in the process. Programmers seem to have a well trained sense of intuition about problem solving mainly due to training and exposure. Sometimes it also helps to be smart to some degree. 😉
I usually imagine data structures in 3d projections of multiple dimensions, imagine how the transformation from one data structure to another takes place, which points are touched, which are disconnected and which are connected to new places. UML helped me a lot by introducing some order to that madness 🙂
I’ve been thinking a fair bit about the “that happens over there” quote recently – there’s definitely an aspect of the groping around in the dark, though it’s not a pitch black kind of darkness; more a fog, in which you know roughly what is happening in each of the distant areas but maybe not exactly how or why.
The act of coding feels to me like a gradual delineation, an iterative activity of mentally exploring the boundaries between related structures and processes. From past experience, I’m always roughly aware of how various sections will be implemented, but the precise details of that implementation and its hierarchies are something that will only emerge given time (and mental prototypes). It feels a little bit like refactoring, only before the code itself exists…
I remember coming to a new programming language as a child, Dean 🙂 I think the word ‘intuition’ seems a bit of a cop out though. What is intuition?
Interesting that learning UML changed the way you think, Ran. When you talk about data structures, do you include computer programs in that?
Hey Dan, I was thinking of feeling around to build a picture of my surroundings out of pitch darkness, which I think is comparable to looking around in fog. I think that coding is an iterative process for me too, and for me at least it’s a process without a lot of state, besides what’s in the text editor/on scraps of paper around me. I’m often quite surprised when I’ve finished coding up something reasonably complex — I look around for the next thing to do and find the code is finished. I think this means I focus a lot on detail, and although I must be coding according to some kind of plan, don’t have a high level masterplan that says what is complete and what isn’t. Perhaps this is because my memory is terrible, and I’ve worked out ways of coding around that…
The programmer is the first interpreter for the real world language of problems to the language of solving computer algorithms.
It’s all about mapping and translating information and questions to get a result (answers, solutions).
Programmers use all sorts of cognitive intuition as input and start thinking of ways to map this into other fields as part of a relation of the subjects. This requires good memory, good creative skills and an ability to think outside of all the real world boxes.
– Unomi –
I agree but I want to know what cognitive intuition means, how it works. Same with creativity. And what exactly is a box in this context?