4 ms·
Programming is deeply and inextricably mathematical. However, most programmers don't actually know mathematics, so it's difficult to see that. This is further
by jerf 12y ago
Programming is deeply and inextricably mathematical.
However, most programmers don't actually know mathematics, so it's difficult to see that. This is further exacerbated by the fact that people creating APIs and libraries also don't know math, so they don't see it, and consequently design APIs and libraries that don't show mathematical characteristics. (This is not because they are "better"... it just means that mathematically these libraries and APIs are mind-bogglingly large and complicated objects, instead of simpler and more powerful ones.)
Schools don't teach much math. Non-zero, but not much. Even a computer science bachelors degree teaches only a smidge of math, and not enough to learn how to correctly apply it to real code.
If you're not doing proofs in school, you aren't doing math in school. I do not mean that all math is proofs or that only proofs are math; I mean literally what I said... if you are not doing proofs in school, you are not doing math in school. (If you get up to post-grad this can change a bit, but pretty much all that is available to bachelors students are in these courses.) You can use this as a yardstick to see how much math you actually know; if your proof experience was confined to just one or two classes where you begrudgingly wrote a few proofs, you don't really know math, and, well, probably shouldn't be arguing about whether programming is or is not this other thing that you don't even know. Memorizing a series of legal transformations of equations with perfunctory walkthroughs of their validity by a disinterested professor is not math. It's calculation. If you've observed to yourself that a computer could well do that... well, yes, they could. Computers remain fairly bad at math but they've got us creamed on computation, even symbolically. The calculation you learned is not math.
Math is about building systems of axioms, building on those axioms, learning what you can and can not guarantee, how to maintain those guarantees, how to build big things based on those guarantees. Safely refactoring code while maintaining its behavior is math. Building an API with simple primitives that can be safely combined to obtain various useful effects is math. Compilers are big piles of math about graphs and nodes. And I could go on and on. Pretty much every program I write is a simultaneous exploration of what the simplest primitives are that I can write and the operations for safely combining them, and this includes even brutally practical systems like process monitoring or memory pools.
To the extent that the average developer's refactoring is generally not safe, that indeed the language itself probably doesn't even permit truly safe refactoring, that most APIs are not built around simple, powerful, safe primitives, that most "compiler"-y code is a big pile of hacks, and so on, that doesn't show programming isn't about math. It shows that most programmers are bad at the relevant math, often to the point of complete ignorance that math is even involved, indeed often not even knowing the relevant words for the basic things. Consequently, yeah, they argue that programming isn't math. It is. They just don't realize it because they lack the skills.
This is not targeted specifically at the original author, BTW. "Programming is not math" is a widely shared opinion.
- ivanmaeder 12y agoI might be one of those people that don't realise that programming is math because I don't know enough math. I know about the classic algorithms, but I've never had to code any for real. And I haven't had to write a compiler. I know enough about graphs and trees to know when to use them, but don't ask me about all the different ways to traverse them, or the differences between red and black trees, and balancing trees, etc. But I'm an applications programmer. Most of the time I move things in and out of databases, and I use third-party libraries and APIs. I'm curious: do you think it would help applications programmers to know algebra a bit better, or trigonometry? Or anything else from the standard math curriculum? In all honesty, for me the biggest difficulties in programming are making clear, concise and cleanly structured programs. And that for me isn't math, maybe simply because I didn't study math, I studied philosophy. And in philosophy what we had to do was write clear, concise and cleanly structured arguments. So do you think it's really a case of regular everyday programmers not being better because they don't know math?
- jerf 12y ago"So do you think it's really a case of regular everyday programmers not being better because they don't know math?" Causation is a strong claim, and I lack the evidence to back it up. For an application programmer moving things in and out of databases, here's an example of the sort of thing you are dealing with all the time and may not realize how deeply mathematical it all is: 1. There exists a set of Operations on the database. 2. Each Operation has some characteristics: a. Atomic b. Consistent c. Isolated d. Durable and each of those statements itself carries mathematical content (for instance, almost all databases ship with ways of choosing what Isolation means). 3. Operations may be composed into Transactions, which depending on how they are manipulated may or may not violate the properties of the isolation itself. 4. For each such Transaction, it may either Succeed, Fail, or do something probably-horrifying in between. As you go to use the database, you need to understand these properties, how they work together, how to harness them best in your code and how to deal with when they break down (for instance, migrations often break transactions). As you write code that ties together database operations, you're doing mathematical work composing together various atomic operations to obtain the result you want. This is particularly obvious if you've ever written code that manages transactions yourself, but has to involve other various client-code function calls within the transaction; you rapidly get into the world of "recursive transactions" in one form or another. How do we recognize a "mathematical" API? A more "mathematical" database will work to minimize the "do something probably-horrifying in between" cases. More of the compositions will be legal without breaking the Transaction promise, i.e., perhaps you will be able to roll back a schema change. The properties will be clearly spelled out for each operation, and the transaction will do a better job of maintaining them. Care will be taken to ensure that any data conversions are as "isomorphic" (for now, read "reversible") as possible, and will generally refuse to "guess" what something means. By contrast, a less mathematical database will contain more operations that break the guarantees. The documentation of what properties are maintained by which operation will be lacking. Transactions will frequently be broken because it's "no big deal in practice". Data that doesn't fit the hole it is being put into will just be hit with a hammer until it fits, and you will not necessarily be able to figure out what it started as. ("This date is 0000-00-00... where did that come from?" three days later "Oh, crap, I inserted someone's name as their birthdate...") Basically, PostgreSQL vs. MySQL, to put names on these two styles, especially older-school MySQL... because, you see, over the years MySQL has been forced to get more mathematical, because otherwise it loses data and is generally a pain to work with. PostgreSQL's heritage is far more "mathematical" than MySQL, and it manifests in a better product. If this just sounds like "good API design", well, yeah, good API design encompasses having a strong mathematical focus, but being "mathematically-aware" code goes beyond that. Few programmers really know math, but even fewer really get how to translate that into practical code. It's a hard discipline to learn.