On maths and coding

When I was at school I had a strong interest in learning to code, but I was terrible at maths. My teachers and parents told me I would need strong mathematical abilities to be a good developer and although they didn’t mean it to be, I found this discouraging. I really wasn’t good with numbers and I couldn’t see this changing.

On the one hand I was right, it didn’t change and I’ve only recently learnt to use maths to great effect when coding. On the other hand, although my abilities haven’t changed, my approach and appreciation for maths has.

Another thing I was wrong about was that I hated maths. This turned out to be a symptom of a different problem. For whatever reason, and to this day still, my brain sometimes freaks out when asked to do simple mental arithmetic.

This has been a real issue for me. If you ask me to calculate something in my head, there is a small but very real chance my brain will have a kernel panic. Sometimes it recovers and I get the answer in about the same time as an average 5 year old. On other occasions my brain just shuts down. At this point I have the choice to reboot and start the problem again from the beginning, or I could just run away. It can be embarrassing, so in public I avoid situations where I might be asked to do maths and if stuck try to divert attention from myself. This has led to me avoiding maths in general and downplaying any ability in this area.

It was eventually coding that allowed me to realise that my handicap with mental arithmetic was not an in indication of my overall ability or my capacity to enjoy mathematical problems, and it does not need to be a limiting factor me as a developer.

Obviously there are many different roles that you can choose as a developer. Some of these probably do require a greater affinity for maths. I’m not making physics engines, 3D rendering applications, or sending spacecraft to Mars. If you are doing these things, and I’m just guessing here, maybe my experience doesn’t apply to you.

Primarily, I’m a web developer and I consider myself more of a front-end developer as well. At any level this is still a highly technical role and there is a lot that front-end developers need to be aware of, but for the most part, hard maths is not one of those things.

So for a long time, despite my job as a developer, I successfully avoided thinking about maths in a direct way. This was particularly true early on in my career, but at some point I started to see maths in the things I was doing. Things like animation, colour, layout, typography, almost everywhere actually. Do you know what else I realised? I was actually good at many of these things!

I was confidently tweaking numbers that represent bezier curves to manipulate motion in animation. I was using modular scales and other ratios in my designs. I understood colour theory and contrast.

But whilst I understood the results of what I was doing, initially I didn’t deeply understand the maths behind a lot of these concepts. I wanted to explore this more and in my spare time I started experimenting with creative coding.

This opened my eyes to a lot of maths I already knew. I found I already had a reasonable understanding of how colour transitions worked in different 2D and 3D colour spaces. I was already using triangles and circles to calculate distance like Pythagoras himself. Occasionally, I was even playing with vectors, calculus and trigonometry in HTML canvas to create complex physics based animation.

Experimenting with these things does not require any mental arithmetic. With code it’s easy for me to visualise mathematical concepts and for once I can begin to understand how and why maths work. This was completely different from my attempts at school to understand a black-box with several disconnected, one dimensional experiments.

Suddenly I was not hating maths any more. I looked at the things I was doing with my eyes more open. The more I learnt, the more I discovered mathamatical rules underpin a lot of my work. Daniel Shiffman’s book The Nature of Code and his videos showed me even more examples and formulas I could use. I found new practical applications for mathematical concepts everywhere.

Maths now inspires me as much as it scares and I’m willing to engage with more advanced concepts even those I don’t fully understand. YouTube channels like Numberphile and Standup Maths have shown me it is possible to understand and appreciate mathematics on a higher level while a deeper understanding may be out of reach. I feel proud that can understand concepts, implications, connections and the beauty of complexity, rather than let down that I can’t compute the details. This is the same effect that coding had for me. I never got this inspiration in school.

My brain still crashes sometimes when attempting to do mental arithmetic, but that’s ok. Although you can probably do it 10 times faster than me, it doesn’t count if you’re not solving the right problem. When working on problems I don’t fully understand I no longer feel the pressure to solve them in the same 90 minutes as everyone else. I feel my slower pace sometimes allows me to focus better.

Although I haven’t become great at maths, with more willingness to engage, my ability has gradually improved. Maybe one day I’ll fix whatever bug there is in my brain code, that causes me crash when attempting mental arithmetic.