Should Competent Programmers be "Mathematically Inclined"?

One of the more famous Edsger Dijkstra quotes is from his 1972 Turing award lecture, How do we tell truths that might hurt?


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2009/04/should-competent-programmers-be-mathematically-inclined.html
1 Like

@Kris Wehner - http://www.thinkgeek.com/tshirts-apparel/unisex/frustrations/374d/

That’s not engineering. That’s what I script UML tools to do.

It is not should be inclined, I think they are naturally. There are lot of parallels between maths and computer science. I see programming as a applied mathematics. Both are concrete problem solving. requirement is defined, input is defined and expected output is defined!. Computer Science is simply the math showing its omnipotent glory!

Ever work with a retaional database? Relational databases came out of theories of working with n-tuples in abstract mathematics. If you understand relational databases, that means you have a good working knowledge of at least some of that theory.

Object orientated programming can trace its language and fundamental concepts back to group theory in Modern Algebra. If you are good at object orientated programming that means you a good working knowledge of at least some of that theory.

At the hardware level, the real work of a computer is done by the transistor. The transistor is a physical representation of the boolean NOR operatotrs. I.e. The only actual work being performed by the computer is applying the NOR operator over and over, billions of times oper second. The rest is moving bits around on the bus. The NOR operator lets you build Boolean Algebra which in turn lets you emulate all the other operations on a computer.

Speaking of Boolean Algebra, have you ever written an IF-Then-Else statement or used AND or OR operators to check of build bit-masks? If so you were doing math operations that 99% of the public would consider above their heads.

Have you ever worked with a multi-dimensional array? In mathematics this is called a matrix, and there is an entire branch of mathematics devoted to matrix theory.

My point is that Mathematics covers a wide range of subjects. It does not stop and end with calculus. All programming, by definition,is applied mathematics. Which means good programmers must be, on some level, good applied mathematicians, even if they don’t realize that is what they are doing.

Yep. It’s not what they teach in high school math classes. Or even most college math classes. But it takes a similar mindset.

Actually, it sometimes seems like you need the mindset of a math teacher to be good at programming. You need to break a problem down into simple steps that your student can apply to any of a certain class of problems to get the right answer, and teach those steps. The only difference is, the computer is usually better at following simple instructions, and it’s way faster at it.

You’re missing the point.

Math isn’t about numbers. Arithmetic is about numbers. Math is about logic. Programming is about logic. Being good at one necessarily means being good at the other, and improving in one necessarily improves the other.

For example, proof by induction should be a pretty simple concept for most programmers, but it’s very difficult for a lot of non-programmers to wrap their head around.

I’m a math major, and I hate numbers. Most mathematicians, you’ll find, aren’t that great at doing arithmetic in their head. It’s non-trivial for me to do subtraction on two-digit numbers in my head, for example. But just like programmers, mathematicians don’t have to worry about that.

Every field of mathematics has a few base axioms. They’re like a mathematical assembly language. Then we’ve got theorems and lemmas which are analogous to programming libraries. You don’t need to write your own implementation of arrays every time you want to use them in a new program, and mathematicians wouldn’t try to prove a complicated theorem on the natural numbers by starting all the way at the Peano axioms.

I have defended this position before here, and didn’t get much love them. :slight_smile:

Code is math. Not arithmetic, to be sure, but math.

When you speak of inheritance or interfaces, that’s group theory. You might not know what the heck is group theory, but you are using it intuitively. And, of course, you might incur in errors when intuition fails, or you might reinvent the wheel (and call it Liskov Substitution Principle, for example).

When you use any flow control, that’s automata theory. Again, you might not know the theory, but you are using it. So when something more complex show up, you might spend some hours rewriting your algorithm, or write spaghetti code instead of using a DFA, for example.

There’s logic, which has been mentioned before. If you have seen incorrect usage of , || and !, that’s math (or the lack of it).

There are algorithms, such as those used in linear programming, which might save you (or your user) time for what would have been simple tasks (such as optimizing load).

And so on.

If you write a program, you are actively using math. If you lack math, you waste time. Either your time figuring out how to solve a problem that has been solved before, your successor by writing code unnecessarily complex, or your user by writing code that takes longer to run than needed.

Dijkstra probably meant mathematics in the university sense, as he probably mixed with a lot of university mathematicians. University maths is nothing like the maths you talk about in your article. To have a mathematical inclination in this sense means being able to argue logically etc… and does engage a great deal of creativity. There are other parallels with programming, eg. there is no siuch thing as THE proof, there are just different proofs.

They teach math all wrong in school. Way, WAY wrong. If you teach yourself math the right way, you’ll learn faster, remember it longer, and it’ll be much more valuable to you as a programmer.

This is the enlightening statement for the question you raised. And of course What would be the right way to teach math?. I think the answer is quite obvious from the course of all discussion going on this topic.

Programming is the right method of teaching mathematics!

I will repeat this some more times to emphasis it:

Programming is the right method of teaching mathematics!

Programming is the right method of teaching mathematics!

Programming is the right method of teaching mathematics!

Programming is the right method of teaching mathematics!

I was never interested in math when I was a kid. But I was very interested in computers and programing. I got really interested in maths when I went to university (studying physics). I was just fascinated by the beauty of mathematics and from that time on I consider myself being quite good at maths. What I am beginning to understand as the time goes by is that I learned mathematical concepts incredibly fast. And there is two reasons for that:

  1. I am naturally mathematically inclined.
  2. I studied programming when I was a kid.

Concluding all I just said in one sentence:

Abstract mathematics is the just the next level of abstraction that a person familiar with algorithms and his native language have to master.

Hell, Algebra I involved creativity. Mainly because I was new to it and had to put the pieces together on tests to get from problem to solution. After I’d been at it a while, I just remembered the steps that I had previously had to re-reason from… well, not first principles, but from as much of the introductory theorems and whatnot as I could manage to remember on test day.

That same process serves me very well when I put code together.

So, I need to know:

  1. Programming wizardry
  2. Hardware mumbo-jumbo
  3. Software Engineering alien language
  4. Network voodoo
    AND
  5. Math magic?

Seriously now, you are asking too much of me.

You either are :

  • a good programmer mathematically inclined
  • a good programmer artistically inclined
  • a good programmer socially inclined (the loud ones Mr. Jeff)
  • all of the above
  • not a good programmer

Conclusion: you can’t be a good programmer withouth beeing good at something else besides programming.

Wow! I can not resist the temptation to write one more post on this subject :slight_smile: Actually this is a kid of proof to my theory that Programming is the right method of teaching mathematics!.

We all very well know that mathematical theory developed very fast after the push in the right direction Newton’s gave to physics. Well I think that what Newton really did is that he wrote a program for the celestial objects to run! I know it might sound silly but that’s exactly what Newton did. Lately this program were to became The law of gravity because strangely lots of objects strictly followed Newton’s program. Nevertheless Newton had no way to know this. It is mere coincidence that nature can be described by some simple programs someone wrote!

Imagine if Newton had learned math in school… Would he have the courage to tell planets how to move :slight_smile:

Math is to arithmetic as programming is to software development?

Surely there’s a big difference in the math skills required to create a compiler in C and a say a database reading script in PHP.

well

set theory is what underlies databases but for comercial programming you dont realy need Maths.

Technical programming you do let me give you an example at my first job we where researching fire sprinkers and I was given part of the task of working our how to locate the droplets in 3dspace.

The companys photographic dept and the electronic shop came up with a way of gett8ing the z dimension used cameras with a very tight depth of filed and two colored flashes to effectively take pictures of a plane through the z dimension. The two flashes had a delay so you got two coloured images of each drop let

We brought an A0 digitizer from Ferranti (this is in 81 ish) I had to write a custom driver that ran in the back ground of the PDP11 then work out how to calibrate the tablet. And then write the software that was used to digitise the drop lets (as this is 1980Ă­s we got a RA to pick out droplet pairs )

ThatĂ­s a case when you do need to understand maths.

oh and I did write the software in FORTRAN

I agree that for most programming tasks higher level maths is not required as libraries are already written for more complex pats. However the shear fact of having this knowledge shows you are more intelligent and makes, your knowledge of the simpler stuff much more embedded.

Learning at a higher level pushes you, once I had done degree level maths I found everything I had done before became easy such as differentiation, integration… Which at the time I found difficult.

I completely disagree on a mastery of ones tongue being important, otherwise how do you explain the high proportion of dyslexic programmers who tend to be very good.

I think that the key word is inclination. It’s not so much that a programmer should be good at math, but he should have an understanding of mathematical thinking.
Think about a program that has nothing to do with math. Imagine you don’t even need to handle sets or relationships, of at most basic math functions. Say the program recieves a list of numbers and adds them all together. It’s true you don’t need to be a mathmagician to do that, but you do need to have a mathematically inclined mind to be able to abstract the problem into a loop. You need an extremely mathematical-like mind to be able to track bugs.
Both Math and Programming do the next: define a series of steps that given something A always give out B.
Both Math and Programming can be wrong, but math has an extremely elaborate system to find out where the problem is. This hasn’t always been so, or the greeks would have realized that irrational numbers HAD to exist much sooner.
I would say that you don’t need to understand set theory or relationships to handle a database, though relational databases are based on this math.
You don’t need knowledge of statistical analisis or probability theory to configure your server, though it’d help in getting the optimal configuartion.
Programmers and mathmathicians think in many similiar kind of problems so it’s obvious that programming uses mathematics as a foundation, mostly because mathematics has thousands of years tweaking and perfecting it’s art, programming has about 100 at most. This is the only reason I can think of why a programmer should have a solid enought understanding of basic math (geometry (and trigonometry), algebra, probability and statistics, and maybe some calculus).

I agree with previous comments that Web programming, like Visual Basic, normally isn’t hard core programming.

Not to diminish it - it is a powerful, useful medium with complexities of its own. But it is hardly low level stuff. Maths is almost essential for low level stuff, when pointers, memory management and optimisation are important. Web programming is higher level and, in a way, no less difficult but much less Maths oriented.

So the mistake is in saying programming and maths, which are both too broad. It’s like saying you need science to be a doctor. Sure they need to know biology and chemistry, but do they really need to know quantum mechanics? For specific programming areas, specific maths skills are required. A security programmer needs to know cryptography but probably doesn’t need to know finance formulas.

Without having read the specific context of Dijkstra’s Turing lecture, I should note that he was an advocate of a highly mathematical style of programming, where the programmer would build up a proof of correctness while writing the code. Each loop that you wrote was supposed to have its own little induction proof, in which you show that the loop maintains its invariant for each iteration, and that the postconditions follow from the loop invariant and the preconditions. I don’t know anyone who actually programs that way, but he did advocate for it in at least one of his books, and the implications of that belief do show up elsewhere in his writing.