ai artificialintelligence code development

Learning to think in code

After I posted my thinking in code post, I had an interesting discussion over on my Google+ page.

It’s a difficult mindset to cultivate. When you get it and are in the zone, it’s effortless in a way that is hard to explain. It basically feels no different than writing in proper English.
When you don’t have it, it’s like trying to speak in a different language. Which makes sense, but it isn’t quite exact.

I’ve been coding for so long, thinking in code is second nature, but I liken it to when I learned to drive. At first I was very bad, I made a lot of mistakes and it really knocked my confidence, but I stuck at it because I lived in the country and had no choice, I was still nervous after passing my test, and it took about another 2 years before I got to the point where I wasn’t consciously thinking about the mechanics of driving, the meaning of each marking and road sign, and how to react to different conditions.

A lot of people I’ve mentored get scared when they lose confidence, but that’s an important step, and it always takes a long time to get past the conscious thinking stage, where they’re switching between the customer domain and the coding domain rather than thinking in the customer domain and writing in the coding domain.

Switching to Haskell got me back to newb mode again. It’s less like programming and more like magic. I can see how it works, and it does things as expected, but intuition tells me it shouldn’t work.

That’s how I felt when I started with node.js – first time I’ve really dug into the guts of JavaScript. I’ve done first-order functions and callbacks in other languages, but the way JavaScript does it, compared to C# or Python, forces me to think about what I’m doing.

I know some of the problems are addressed in ES6, but prototypes rather than the OO I’ve used elsewhere is a massive shift for me, and I definitely don’t think in JavaScript yet.

And then I read Code rant: Learn To Code, It’s Harder Than You Think, and it got me thinking about the AI Gods, and how unnatural it is to think in code. And that’s important. When you talk to users and customers, and when you talk to managers, they look at all the information saying coding is easy and then ask why it’s taking so long, or why you can’t just put that number there, and then switch off when you try to explain. Indeed, you can end up in a meeting like this one:

The expert :

So it’s important for people to understand that code is hard, and it is a specialist skill, whilst still trying to encourage people to take up software, because we need a new generation of AI gods, and they need the time, and the inclination to grok coding.

I grew up in the 8-bit days, with the MSX, and coding was an integrated part of the experience. The command line was the programming language, and all the magazines has type-ins, so there was a lot of opportunity to practice typing, as well as coding, which is a valuable subsidiary skill. There’s a similar modern experience with the Raspberry Pi, but the industry as a whole has moved on so much, that the days of spending a few hours typing to get something that has the same surface quality as the games in the shops, are mainly behind us, at least as far as the big box games, rather than the casual field. And it will be about games, because who is going to write a tax auditing application for fun?

How do I learn?

So if you’re just starting out, and you want to write software, or you want to be the next AI God, what do you need?

Here’s what I think is most important:

  • Teach yourself. Attend classes if it helps, but if you’re not self-motivated to learn and keep up to date, you will quickly fall behind.
  • Crave simplicity. Challenge yourself to cut complexity, to streamline. The less code you have to write, the easier it is to work with. Always seek new ways to simplify what you do.
  • Practice the basics. Use the many programming exercises to capture branching, modularisation, testing. Find examples you like, either smaller exercises, or complex Mandelbrot calculations and keep reworking them to understand new languages, or to challenge yourself to understand that basics. Can you write a program without if statements, or can you throw away the tests and rewrite the code?
  • Practice often. Spend 20 hours writing code. Then reflect, understand what you know, and write more. The more you write, the more you’ll understand what you don’t know.
  • Read code. And think about it. Just because it exists, doesn’t necessarily mean it’s good, but think about how you would solve the same problem. Understand what decisions were made and why.
  • Understand principles deeply, technologies less so. Know what it means to be Object Oriented, or Event Driven, or Functional. Understand what they are and how to use them. It doesn’t matter whether you’re using C# or Python or VB or Java or Haskell or The Next Big Thing. If you understand the principles, you can apply them with whatever syntax your current language provides, and you can understand what to use when.
  • Think in code, but talk in human. If you can’t explain what you’re doing to your users or your manager, you don’t understand it enough. Crave simplicity in your communication as well as your code.
  • Talk publicly. Present, blog, chat. Find a local user group and connect. If you’re enthusiastic, you’ll be welcome. If you’re shy, everyone will understand. We’ve all been there.
  • Simplicity doesn’t mean brevity. Be as brief as possible, but don’t lose context, or nuance. Be clear.

For those of you with experience, what else would you add?

2 replies on “Learning to think in code”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.