Hacker’s Brain – The Psychology of Programming

By on November 21, 2015

First things first, everyone should learn to program. As we’ll see in this article, programming is an excellent tool for training your brain but even if you ignore that, it’s just an incredible useful tool that allows you to accomplish pretty much anything more efficiently than you otherwise could.

Basically, when you find yourself faced with any lengthy task that involves a computer, you can normally create a program to do it for you. You might never release that piece of software, but instead it’s just something that you need right then to save time and work more efficiently (in business this is called a force multiplier). I was once hired to write descriptions for over 300 websites, so I wrote a script to do it for me. Each description had to have the same elements so it was just a case of randomising the phrasing and referencing the file names. I wrote the script in 15 minutes and it earned me $600 – as I was being paid by the word.

Nice, right?

Sometimes though, you’ll write that program you need and then it will come in handy for someone else. That’s what happened when I wanted to be able to write on my phone while looking at a web page as a reference. This became Multiscreen Multitasking and it has gone on to sell well over 10,000 copies and is even pre-installed on some Indian mobile phones.

The point is, when you know how to code, you can create solutions as you work and this almost becomes an extension of your own brain power – an exocortex.

Then there’s the fact that coding is useful for such a large number of jobs. And the fact that it’s so much fun. Programming is a highly rewarding process that allows you to come up with an idea and then turn that idea into a reality. I’m creating a computer game at the moment and it’s just so great being able to design traps and then see my friends killed by them. This is probably due to some issues that I need to work out…

Behold, the mighty MELDON!!

Behold, the mighty MELDON!!

But coding also trains you to think in a certain way and to use your brain in a certain way. As Steve Jobs put it: coding ‘teaches you how to think’.

Everybody in this country should learn to program a computer… because it teaches you how to think.

This is the part I’m interested in look at today: how your brain handles code and how a coder might think differently to a non-coder.

Maths VS English

Non-programmers tend to assume that coding involves a lot of maths. While it’s true that programming does share some stuff in common with mathematics though, the reality is that the two activities are broadly quite different. Rarely will you have to perform a ‘sum’ and if you do, you can just use a calculator – or even the programming language itself.

This may be why brain imaging of programmers shows that programming relies more heavily on the language centres of the brain versus the areas associated with maths. Programmers will rely on the ventral lateral prefrontal cortex, alongside their working memory.

This has led some people to suggest that learning to program may have similar cognitive benefits to becoming bilingual. I personally find this unlikely however, as the number of commands and lines of code that you use as a programmer are far smaller and most of them sound like English anyway: things like ‘IF’ and ‘THEN’ are pretty straightforward…

There’s a whole lot less ‘vocabulary’ to learn as a programmer and far less syntax. And anything you can’t remember, you can just copy and paste… It makes sense that the language areas light up, only because programmers have to access their lexicon to read and write code. This isn’t where the ‘magic happens’ so to speak.

Cognitive Simulation

For a while now, I’ve been very interested in the brain’s ability to ‘simulate’ what will happen if we take a certain action. I wrote about this in my article on movement.

This, I think, is where the really impressive stuff is happening when you program. And what you’ll find is that you tend to ‘program’ in your head even when you’re nowhere near a computer. To do this, you think of what you want to achieve and then how you might achieve it using what you know.

When I was making Multiscreen Multitasking, I wanted users to be able to drag windows around the screen with their finger. I worked out how to do this on a day out in London with my sister and once I’d solved the problem in my head, I couldn’t wait to get home and try it out.

inthecode

I’m going to share my thought process here, so you can see it how it works. I already had a system where the browser and notepad were covering the screen 50/50 but I wanted a way to be able to drag windows around the screen and resize them. The solution started with ‘what if’?

What you would need, would be an invisible panel that would cover the whole screen. When you touched the tile (On_Touch), you would then grab the X and Y coordinates of that touch.

We have the X and Y coordinates, as well as the width and height of the window. So if TouchX > WindowX AND TouchY is > WindowY AND TouchX < WindowX + WindowWith AND TouchY < WindowY + WindowHeight, that then means that the user touched the screen within the bounds of the window. Only we wouldn’t use the window but rather the bar along the top of the window. That’s what you use to drag windows around. So if the user were to touch the window itself then you’d tell the panel to pass the touch event through to the panels underneath it, such as the webview. In programming-speak this means it doesn’t ‘consume’ the touch event.

Still with me?

Now we simply move WindowBarX and WindowBarY to TouchX and TouchY, right? But wait – that doesn’t work, instead it causes the window to jump so that the bar is central to where the user touched. That’s not very smooth or very elegant!

Instead, we need to work out the offset. OffsetX would be TouchX – WindowBarX (remember, you go along the corridor and down the stairs when using coordinates). OffsetY would be TouchY – WindowsBarY. That’s how far to the right and from the top the finer is touching the bar.

Now we just make sure that the bar stays at TouchX – OffsetX and TouchY – OffsetY to move it nicely in the middle. We can use similar logic for resizing.

All this happened in my head. When I got home, I simply wrote out the code, copy and pasted some parts I couldn’t remember and ironed out the bugs until it worked smoothly. The actual hard part happened away from the computer in this case. You even ‘run’ the programs in your brain by following the logic through step by step to see if it would work – you can this way flag up bugs (gotta’ catch ‘em all!) before actually creating the code. If I was being particularly self-congratulatory I’d say it’s like having a compiler in my head too…

The Hacker’s Mind

Really, coding tends to amount to problem solving and this in turn amounts to ‘hacking’. The seasoned coder is someone who looks for shortcut ways to achieve tasks and who is resourceful enough to find unconventional solutions to problems. This requires you to first learn the system or the context you’re working in and then to find exploits within it. Sometimes this is referred to as ‘systems thinking’.

And of course this is what Steve Jobs was talking about; you can hack the way you work out too, or the way you earn money. A smart business model is just like a coding solution.

When I’ve worked with clients and partners, they’ll often ask me to do something that I tell them is impossible. Then I walk away, think about it for a bit and solve the problem anyway. Remember: there’s no such thing as a lack of resources, only a lack of resourcefulness!

The best way to train this specific type of resourcefulness? To practice using it – to program.

The Working Memory and Abstraction

This also explains the role of the working memory, which is essentially the brain’s RAM. We use our working memory to store information, so when you’re imaging what a line of code does, you have to store the variables and the ideas you’re testing out, there. So when you’re thinking of a sequence of events, you need to keep the line of logical reasoning held in your working memory – which is where the similarity to math comes in.

This is crucial for ‘abstraction’. Abstraction is the process of going from a bottom up, to top down approach to manipulating data; of using abstract symbols and ideas to convey higher level concepts. As soon as ‘6’ people become, ‘N’ you’ve added a ‘layer of abstraction’.

Programing itself is a form of abstraction: it represents changes to computer circuitry in an abstract terminology that we can understand. The UI, or the game graphics that you use code to build is an additional layer of abstraction on top of that.

Here’s also where things get more interesting still: because the brain areas involved with abstract thought are actually the same as those associated with verbal semantic processing (1). But then of course it does – language represents ideas just as code represents logic. Speaking of which, this article is getting into some pretty high levels of abstraction itself!

C#, Java, or my personal favourite, BASIC, all give you a language to manipulate certain types of ideas. This makes it easier to store those ideas in a compressed format and to test them out in your brain’s in-built simulator.

Coding and Dopamine – Nootropics for Programmers

So the coder’s brain is good at abstraction, language and short term memory – at least in theory. It should be creative at problem solving and resourceful.

How about attention?

Actually, this is something I have very little problem with when programming and I’d say that most coders I’ve met feel the same way. Concentrating on coding isn’t the problem: it’s stopping that’s hard! It’s incredibly easy to get into a flow state when coding, to think ‘just one more compile’, and to end up staying up all night. When I’m writing on the other hand, I have to work much harder to hold my attention.

wired-in

“Don’t disturb him! He’s wired in.”

Why is this? It’s probably down to the very immediate feedback loop that coding provides: the ability to test what you’ve written and immediately see the results is incredibly gratifying. Dopamine is the neurotransmitter that our brain releases in anticipation of reward and I’d argue coders have got dopamine to spare. This is the definition of ‘the work being its own reward’.

This is something that could be worked into a lot of other workflows. How could I work a feedback loop into my writing? And so comes the idea for a new app. You see how this works?

This also explains why coding and coffee/tea go so well together. Unfortunately, it’s also why a lot of coders will work themselves to the point of burnout. Coding is almost addictive and some managers will take advantage of this by setting impossible deadlines and mad working hours. Coding in a large team by the way is an entirely different kettle of fish compared with building something on your own.

If you’re looking for the best nootropics for programmers, I’d say any dopaminergics. I’m not a massive fan of discriminating neurotransmitters but I think the classic caffeine + l-theanine is a safe enough bet. I also like CILTeP which is said to stack very well with caffeine (it grows on me the more I use it) and of course anything that will give you more energy is also going to help.

Modafinil? That also seems to increase dopamine and it certainly enhances that focus even further but I find it too hardcore for me. That coder burnout is a real thing and modafinil certainly won’t help.

Brain training wise? The best thing you can do is just to code more. And challenge yourself to make programs that actually test your skills. If you’re just debugging all day then you aren’t really learning. If you want to specifically train your working memory meanwhile, you can do this using the N-back test, which has been proven effective in this capacity.

The best cognitive aid for programming is instead just some decent EDM (Electronic Dance Music, all the kids are doing it). Schiller is awesome. Also any synthwave is brilliant – try the Kung Fury soundtrack. Putting a short album on loop also helps me find my groove.

And there’s something about creating the right atmosphere too. Put on some electronic music, get yourself a cup of coffee and work into the night…

 

About Adam Sinicki

Adam Sinicki, AKA The Bioneer, is a writer, personal trainer, author, entrepreneur, and web developer. I've been writing about health, psychology, and fitness for the past 10+ years and have a fascination with the limits of human performance. When I'm not running my online businesses or training, I love sandwiches, computer games, comics, and hanging out with my family.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!