2011-01-19

code that will hack your mind

I've been reading an excellent book mind hacks on my kindle recently.

It describes the mind as a collection of parallel sub-processors which work together to form the conscious mind.
For instance there is a part of the brain which identifies shadows, and this processing is done very early in our visual processing. It is an over simplified process which helps to identify possible threats very quickly. A much more accurate process works on shape recognition, but this is also a slower process. This is a rational for people jumping at shadows, but quickly recovering.

The processing is done in parallel, but some results override others. A good experiment (illusion) to show this edge case is the colour and words recognition problem .
One sub-process of our mind is reading the words, (and normally brings the sound of each word into our mind as we read them).
Another part is recognising the actual colour of the text, and converting that colour sensation into a word.
In this case the illusion is caused by the sub-process that is reading the words overriding the colour recognition sub-process.
This collision shows the importance of these automatic processes in how we read and understand text.
There are other sub-processes which can collide with our word recognition, one of which is for recognising shapes. Our mind automatically looks for a meaningful shape in the image, which seems to have a white background and black foreground. It is only when our word recognition sub-process comes in that you can see the white word on black background. Once your mind has locked onto the word, it's difficult to see the amorphous black shape that you originally saw.

Now, we've all seen optical illusions before and it seems hard to believe that any of this affects you in your normal day to day life. These edge cases (illusions) are rarely seen in reality, mostly because when we're reading any substantial body of text (like this blog), it's pretty much always in black and white, and any images are nicely separated from the text. Even the structure of the text, the shape of each line and paragraph is pretty standardised. This ensures that our shape recognition sub-process doesn't interfere with reading, except when scanning through a body of text for a particular section. That's all true for almost all natural language that we encounter.

It is not the case for programming languages though.

This is the real reason that programmers get into so many arguments of tabs-vs-spaces and IDE wars over code auto-formatting, and syntax highlighting. It also explains why different languages are fought over so vehemently when it seems to outsiders like the similarities are greater than the differences between them. I want to show why all of this stuff really does matter.

It's all about hacking our minds.

The following points may seem stupidly obvious, or obviously wrong, but since there hasn't been any research into this that I know of, they're have to be assumptions.
  1. When reading code, the mind uses same processes as when reading natural language.
  2. Some part is trying to recognise whole words, and define the meaning of the word.
  3. Some part of brain is trying to say each word (token) out load, with punctuation either ignored or used to structure the rhythm of the word sounds.
  4. Some part is looking for meaningful shapes in the code, to determine relatedness and structure.
 This has some implications for source code.

2. implies that words (tokens) must have meaningful names, which sounds stupidly obvious; but it's something people still ignore. They must be obvious and simple names that we recognise instantly. Otherwise we work against the automatic word recognition our minds have.
3. implies that our source code should be pronounceable. Actually speak your code out loud. Does it make sense to someone else if you say it out loud? Does it flow properly, or does it have a stunted rhythm.
4. implies that blocks of code should have a meaningful shape. People are aware of this when it's done badly, but it's rarely seen as an image problem. Usually it's treated more like structuring paragraphs, when we should be using the source code and punctuation to show pictorially what the code means.

I would really like to have some code examples here, but that would actually require getting this stuff right. Which means lots of experimentation.

I will,

if I get time,

... later.

No comments:

Post a Comment