Is math important to programming?

It depends.

Now that we’ve gotten the short answer out of the way, let’s discuss this further. Recently, Jeff Atwood asked Should Competent Programmers be “Mathematically Inclined”? I don’t get the need for the quotes, but never mind…

The summary of his article is that the problems involving math that most programmers deal with are the “balancing your checkbook” kind. Meaning simple math is required, meaning you don’t need to be a math whiz to solve that problem with programming. And I agree with him.

My work currently puts me in contact with a lot of numbers. As in quantities in the 10 digits range, with values also in the 10 digits range. And the finance and credit departments of my employer are very interested in those numbers…

Anyway, the manipulation of those numbers require very little math, despite their math origins. How hard can it be to sum up figures, do discrete prorating, calculate percentages or find out the price based on existing rates?

The initial reading of Jeff’s article made me feel indignant (goes off to check that I indeed write about math and programming). How dare he view math as frivolous to programming! How dare he reduce math to insignificance! (wipes spittle from mouth)

Then the cold hard truth of my professional programming experience knocked my senses back into place. I had to remember that the work I did back in university just wasn’t… useful (directly) to my present work. I worked with 3D, image rotations and optimising an airflow simulation. Not quite the business related programming I do now.

I still believe math is useful to programmers. Just as you should learn C, even if you don’t use C in your regular work. I’ll tell you how math and C are related in a bit, but first…

Math is elegant

I agree with Steve Yegge. They teach math all wrong in schools. This is despite his American background and my Singaporean background. I guess errant math education has no borders

The earlier parts of math education focus on calculations and memorisations. Oh, there are some proving questions (much to my distaste) alright, but there’s not a lot of them. In university, my math education started to take on a distinct shift; there were fewer numbers in the questions.

I remember there was this linear algebra tutorial. There were only 4 questions in it. I took a grand total of 4 hours to complete it. Even then, I didn’t fully answer the questions. It was proving this, or ransacking notes to find out which theorems were applicable, or wandering into higher dimensional linear spaces (I think I hated the professor at one point during my struggle). I think I even skipped 1 (or 2!) question. That’s how different the questions became.

With this shift, I found math to become more … elegant. Suddenly, plugging in numbers into calculation formulas aren’t important anymore. Even remembering proofs and theorems take backstage. Figuring out which method, proof or theorem to use to solve a question in the simplest manner is paramount.

I started to solve problems elegantly, be they math or programming.

And for me to find elegant solutions, I needed to think more. Much more. Sometimes this fails, and I end up with a less-than-ideal-elegance solution. But that’s ok. If I don’t aim for elegance, I’ll never reach it.

In my earlier stages of education, math was binary. Either my solution was right, or it was wrong. Later on, it was right. And there’s another solution that’s also right, and shorter. Or easier to understand. Math solutions became a little fuzzy.

What I’m saying is that although math isn’t directly useful to my programming, it certainly shaped the way I solve programming problems. Because programming solutions are also a little fuzzy.

Many programming solutions are sub-optimal. And they don’t need to be optimal. They already solve all normal occurring cases, and maybe the edge cases don’t matter that much. Or maybe there isn’t an optimal solution. In which case trying to find the optimal solution is a waste of time. So much for elegance.

So is math really important? I can’t say for you (despite writing an article on it), but C isn’t that important for programmers either.

Learning C makes you think

It’s sometimes hilarious to see Jeff and Joel argue about the importance of learning C. Joel does have a point. Learning C makes you think harder about solving programming problems (pointers and all). It doesn’t mean you’ll ever use any of the solutions (or C for that matter), but it trains your mind to think.

And in this respect, that’s what C and math are to a programmer. Learning both makes you think. You’ll think about just solving the problem. You’ll think about a more elegant solution. Maybe coming up with a less convoluted solution but eminently understandable by your fellow programmers.

But if you never go through the extremes of “slap messy but amazingly it works” and “elegant one liner but takes forever to understand”, then you might find it hard to find a happy in-between state. Because you just don’t know what’s possible.

“So is math important to programming?” an obvious exasperation in your question.

Well … it depends. On you.

Comments

  1. I suppose that the answer to the question, “Is math important to programming?”, depends on what you consider “math”. I would have said that programming was a subset of (applied) math.

    If we restrict “math” to techniques dealing with quantities, then my answer would be “Math may not be necessary to programming, but it is certainly is helpful.” I have encountered a number of programmers in during my career who understand only the small number of software tools which they have learned to use. Knowing little or nothing about computer science, discrete math, etc. can be limiting, and I have seen it hold up big-ticket projects.

    Since learning math takes time and effort, hiring a candidate who has such qualification is more expensive. Do all programmers need such skills? No, but doing without them entirely, in my opinion, only makes the work harder.

    Will Dwinnells last blog post..MATLAB Image Basics

  2. Vincent Tan says:

    “Math may not be necessary to programming, but it is certainly is helpful.”

    That’s the same answer given by Jeff Atwood and Joel Spolsky! Well, Jeff mainly… Now that I’ve worked a bit as a professional programmer, I can safely say, that’s true.

  3. As a hobby programmer with admittedly shocking math ability I can vouch it does make a huge difference, often complex math takes me a lot longer than it ought to and yet other things are sadly beyond my realm of understanding, particularly in DirectX.

    Jamies last blog post..Revenge of the focus rectangle & Black hole tabs – ListView tidbits cont.

  4. Vincent Tan says:

    Hello Jamie, usually when you deal with DirectX, you’re involved with manipulating lots of 3D information. That means *some* math is involved. I’m just glad I know a little bit of why the code looks and works that way…