Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Why do most programmers work so hard at pretending that they’re not doing math? (richardminerich.com)
53 points by plinkplonk on Jan 14, 2012 | hide | past | favorite | 69 comments


A seductive idea, but ultimately of stunningly limited use in software engineering. By far the most costly defects in software creation are due to incorrect requirements or poor systems design. Knowing with mathematical certainty that your software component does exactly what you have specified it to do helps little when what it does is still the wrong thing.

And that doesn't even touch on the fact that crafting components is but a tiny part of the work required to produce software.


Absolutely. Most of the code being produced around me is of the "When button X is clicked, send an XML message to service Y letting it know the contents of textbox Z."

I'm sure this can be modelled mathematically, but I'm not convinced this would help.


I'm not sure. The OP raise the fact the SQL is modeled after set theory. I happen to have learnt set theory a very long time ago, and to use SQL as much as any web developper around. Then I read a book about foundations of SQL, and found out it can and should be seen as an implementation of the set theory.

And you know what? It was like a revelation to me. It is incredibly helpful. And, by the way, it make me laughing inside each time I query MySQL (because MySQL is sadly /not/ a correct implementation, while PostgreSQL is). The "dots connecting" between set theory and SQL made also much clearer to me the NULL "mess" and why it has to be like that.

So, on this part I'd push the same way as the author, and would go as far as saying that doing correctly a "button X pushed -> notify API Y + persist the action to Z" simple glue code thing /is/ requiring a mental activity that (probably) uses the same parts of your brain as any mathematics and the use them the same way.

However I don't get why the author seem to be ranting against Test Driven Development. In my experience it is unrelated to how you model you data and interactions, except TDD will do exactly as the author is advocating: it will force you to write stateless atomic functions, to make them testable.

NB: From all I have read about mathematics on HN, it seems to me possible that we are not talking about the same thing. Maybe you and many other refer to some "sin a + sin b = cos sin ..." memorization exercise, and some multiple choice questions one have to check as fast as possible in order to get some good enough ranking.

I am talking about a teacher spending around 20 hours a week during several years in front of young people, telling them step by step how the world can be described, analyzed, understood with their brain. It started with: first predicate, there is something, at least one thing. Let's take this thing in your hand, and nothing else: you have a set. In your other hand let's take nothing: you hold now another set, the empty one. Then you have two different things. And on this the teacher built the set theory. (I was educated in France, when math were still on their pedestal).


"""because MySQL is sadly /not/ a correct implementation, while PostgreSQL is"""

Of SQL maybe, but of Relational Algrebra/Set Theory, neither PostgreSQL is.


"""I'm sure this can be modeled mathematically, but I'm not convinced this would help."""

Why would a mathematically modeled system of key-value observing would not help? For one, it would enable one to prove and examine all kinds of assumptions about the model working correctly.


> By far the most costly defects in software creation are due to incorrect requirements or poor systems design.

I'm willing to bet those can be fixed with math. By formalizing the requirement, you're bound to spot any inconsistency, and probably even some other kinds of errors. Same with systems design. "Small is better" and "low coupling is better" for instance, can be formalised and measured.

By the way, you can't escape the fact that ultimately, the final program is supposed to be a formalization of the requirements. Inevitably, the messy ideas in the brain of the customer are bound to be reduced to math. Better use simple math as early as possible, so you can easily check them against the requirements. (Of course it won't happen because most people either won't be able to see the math behind the requirements, or won't bother).


That implies that you can specify all requirements in a mathematical form, which is not the case. How do you specify a usability requirement? Software is for humans, that makes it messy, even down to the requirements level.


> That implies that you can specify all requirements in a mathematical form, which is not the case.

I concede that requirement themselves can't be completely reduced to math. But most of them can. Also, the system itself (excluding human operators) can definitely be reduced to pure math.

What I was proposing was to check the pure math specification against the mostly math requirements. If such math are simple enough, it should be easy enough to make sure the specs match the needs.


"poor system design"

Agree, bur if you don't know how that relatest to math, then you will not discover how math fixes "poor system design" and, as a side effect "incorrect requirements"


Here's the devastating truth: people with a half-assed knowledge of CS but with good other skills (project management, communications, customer service, people interaction, etc.) can and will often make unarguably better software than people who just get the fundamentals right.

You can spend all your life building the perfect implementation of a crappy system, but that won't rescue it. Good CS fundamentals (even provably correct algorithms and implementations) has its place in the software craft but that place is a fairly small niche, not the top of the heap.


gathering requirements has more in common with psychology, sociology and communication skills than mathematics. to make good software, you need to know what it needs to do much better than your customer, unless it's a really small thing.


Correct. This does not oppose my original statement.

Math is not just arithmetic or geometry. Is also a way of thinking and a way to sort and structure your analysis. Which helps you to know how to use psychology to ask the right questions, which leads to understand what needs to be done better than the customer.


Imagine if physics was done this way.

But it is...

1) We test theories with experiments to see whether they fail for that particular "input", we don't prove them correct.

2) One of our two best theories (QFT, the other being GR) doesn't even make sense, mathematically.

In fact the great challenge of physics today is that we have neither experiment nor mathematical rigor to stand on: http://groups.google.com/group/sci.physics.research/browse_t...

A theory that gives correct results for a limited range of phenomena but isn't absolutely correct or mathematically consistent is still useful. Same for programs, I would think.


Simple answer - the vast majority programmers rarely see more than rudimentary math on most projects, unless those projects are specifically math orientated (actual sciences, for example).

The rest of us working on our sites, platforms, apps and what-have-you usually only see anything resembling math when dealing with things like UI and Interaction models, or typically soft-math areas like rating systems and segmentation.

Possibly inflammatory, but perhaps a better question would be: why do most programmers work so hard at pretending they're engineers?


I've never regretted missing out on a formal CS education but I bump up against the limits of my math knowledge all the time. This wasn't the case when I was writing CRUD web apps, of course, but over the last year I've been working in DSP and machine learning and getting my head around the math has been much harder than the coding.


I think there's a certain stigma to the word 'programmer' kind of like 'code monkey.'


Most programmers know about SQL statements... But rarely identify it with set theory and that difference has a big impact on how you design and program databases. Being able to get by without that understanding is no excuse.


I think you can learn SQL as SQL, without math background. OTOH just knowing mathematical model of SQL is not enough to write good SQL.

SQL in practice is not a purely mathematical construct: you have to know how to make use of spinning platters, indices, caches, locks, network connections, intricacies of data types and bunch of quirks and bugs of the RDBMS.

I've learned SQL before learning set theory properly. It turned out that I did understand (SQL-related parts of) it, I just didn't know it was called set theory :)


why do most programmers work so hard at pretending they're engineers?

In my experience, this is a regional thing. For my first ten years in the industry (on the east coast), I never met another programmer who called herself an engineer. We were "analysts," "developers," or "programmers." Then I took a job with a local company with a tech office in SV, and everybody, including some of the testers, were "engineers" (hey, even I'm an engineer now!).


Perhaps we should consider that Programmers its a super class of Scientist, Engineer, Designer, Technician.

And that not everybody should know everything about the subclases.

If you think of yourself as developer(?), and Rick as a mathematician its fine!; the problem comes when Rick think you should behave as a mathematician because you are a programmer or viceversa.


The sort of maths the article is referring to has very little to do with arithmetic computation, and is present in the type systems of those languages you're developing sites and apps in.


We work in an environment where heresay [sic] and taste drive change instead of studies and models. We are stumbling in the dark.

Another way to look at it is that we’re making progress, but with lots of false starts, like most progress. Hearsay and taste are what happen when people are working with imperfect information. Probably not even Knuth has perfect information about all the studies and models that might be relevant to any nontrivial project.

The author’s point seems to be not that programmers should understand the math behind their work, but that they should do work that’s more like math. It’s true this would mean fewer bugs. But there are a lot of problems that people in the real world would rather have mostly solved by a slightly buggy dynamic program with mutation and state hiding than not solved by a formally proven program.

A lot of programming is stuff like simple CRUD web apps. I’d rather do that in Python than Haskell for the moment. If the author wants to argue that Haskell could be made friendlier without giving up its advantages, that’s an essay I would welcome.


I'm writing a bunch of webapps in Scala making heavy use of Scalaz, which is Scala's Haskell-envy library of typeclasses. The typical pattern is to compute everything as a Validation, which you can think of as the Maybe monad, except there is information attached to the failure case. It's a very nice way of coding. Everything composes and at the end of the request handling chain you just convert to a response and you're done.

It took a bit of thinking to get the basic patterns, and there is the occasional bit of head scratching to get the type right. This feels very much like algebra.

Anyway, the point is that this style of programming is both "mathematical" and practical.


For reference, Haskell's version of that is called Either.

You also sometimes use ErrorT which is a way to slap an Either on any other Monad. The T just denotes that it's a monad transformer.

Coincidentally, I agree wholeheartedly about how practical programming like this is--this sort of error handling is at once easier and more explicit than exceptions.


Why is it easier? That's just doing the monad transformation by hand instead of letting a compiler take care of that for you (in the case of EitherT and do-notation the compiler takes care of the intraprocedural transformation for you). It's rather in the same category as Node.js programmers doing CPS transform by hand.


Haskell's advantages lie in being pure. It can't be 'friendlier,' because friendly languages let you hack things up (and are impure) as opposed to the planning required to lay down some Haskell.


I find it hard to believe that Haskell could not be friendlier. And I say that as a fan of Haskell.


Someone should define "friendly" at this point.

Haskell certainly seems friendly enough to me. It catches most of my errors before I even run the program, it let me hack things relatively quickly with very little code. Yes, there is that "purity" discipline, but I mostly think like that anyway.

Now, it certainly won't be friendly to one who routinely writes code like that:

  if (foo)
    if (bar)
      do_something;
  
  if      (foo) {} // OK, do nothing
  else if (bar) {} // OK, do nothing
  else          { do_something; }
(I saw that yesterday in production code!) Those people think too procedurally to be able to understand Haskell, or even ML. You have to fix that flaw first.

(For the few who don't see the code above as utterly ridiculous, here is the better version:)

  if (foo && bar)
    do_something;
  
  if (!foo && !bar) { do_something; }


I find funny how people want languages to be "friendlier"

It is often an egocentric excuse to not lean new tools... As if programming was about making he programmer comfortable, as opposed to producing the best result possible.


I like to think that CS is just a different approach to math.

Of course, I say this as somebody who likes Haskell where the programmers work really hard at pretending to be mathematicians :)

However, even when I'm writing in other language, I think about things in terms of math. Additionally, my CS courses so far have all been heavily influenced by math, except for systems that was much more heavily influenced by EE.

So, at least for me, programming is very much like math. Just shinier. And I do think that more math--or at least mathematical thinking--would help most programmers.

However, the rant against testing is just silly. Tests are not a replacement for math--they augment it. We need tests because, at heart, CS is an engineering discipline: math is just a tool we use very pervasively.

Haskell is one of the more extreme typed functional languages, and yet Haskell programmers are very amenable to testing. In fact, Haskell programmers tend to go above and beyond normal testing: we use property-based testing (QuickCheck). Instead of just having unit tests, we actually generate random tests.

Besides, lets look at physics: they have great mathematical models. However, as soon as you actually apply physics--basically engineering--you need to test everything extensively. There is a reason we have exhaustive crash tests, after all.

So: math is good for programmers. Tests are also good for programmers. The two cannot replace each other.


I tend to think of Haskell as a language designed by mathematicians but not for mathematicians. Not even to say that it's not useful for doing math but simply that it's not structured to explore ideas via proofs. Consider Coq or Mathematica which are definitely designed with that goal in mind.

I think programmers aren't doing math at all, but I think what programmers do is better, more adroitly, done when its guided strongly by math. For that reason I think programmers should learn lots of math, even if they don't spend much time proving things for their own purposes.


The program is a constructive existence proof of the theorem structures embodied in the type system.


I'm aware. I suppose I think of the theorems as less interesting though usually.


Agree with the rest, but not with "math is just a tool".

Math here is not about answering a question like "what are the coordinates of the point in the middle of those two points here". It is not a tool helping to solve a restricted set of computation problems. Math here is the model for the deterministic handling of a data system and its evolution in time. The silliest glue code is still math: "if button.push('a') thing.do_action('a_action')" translates to "For any x in A_Button_Pushes, action = f('a_action')".


Exactly. Let me also add that math isn't so much a tool as it is a way of thinking. Learning (or should I say understanding) more math helps in all sorts of non-obvious ways. From thinking logically, to seeing intuitive shortcuts, to proofs (used nearly every time a program is debugged), to algorithms, programming is one of the greatest concrete implementations of the math abstract.


Yes, I understand that. What I meant is that math is a tool in the same sense a programming language or methodology is a tool--it's something we ultimately use as a means to an end. If our only goal was math, we would actually be mathematicians ;)


Walking is math too, it can be modeled in math, but that doesn't mean all people who walk are mathematicians.

Physics is math too, but the difference is that while Physics uses the same constructs as math, Programming has radically different constructs.

Math and Programming does not require the same mindset, in math you need to find the absolute truth, when programming, 99% is good enough.

Being good at Math does not make you a good programmer instantly, and vice versa.

> This is also why programmers who use typed functional languages frequently brag about their low bug count yet eschew methodologies like test driven development: tests pale in comparison to the power of actual models.

If I brag about something does that make it a fact? I think writing this in math context is silly to say the least. It doesn't matter what you program in, you still need to test most of the time, this has nothing to do with how you program, it's what you program, I highly doubt that you could model a video game, and get it right the first time, without ever testing it.

Overall this article is pretty confusing, it tires to raise some good points, but gets stuck on the details.


Your post reminds me of what xkcd says about it:

http://xkcd.com/435/

There's a truth to it -- CS is just applied math, that doesn't mean you have to understand math to program, but it will be very beneficial.


"This is also why programmers who use typed functional languages frequently brag about their low bug count yet eschew methodologies like test driven development: tests pale in comparison to the power of actual models."

I've written complex systems. Games. Graphics modelling tools. Network game engines. I've seen a lot of code.

I've never seen anything that complex written in a functional language.

Why?

My hunch is that models are powerful, but brittle: they don't stand up against constantly changing requirements. A great quote I read the other day was "If it compiles, it works". Great. Now change the requirements. The "beauty" of imperative languages is that they continue to compile and continue to provide some value of "work" even while they are morphing from one requirement set to the next. Functional languages are cast-iron. Imperative languages are steel.

UPDATE: I should also be clear: I think in models all the time. I just don't have to get it down perfectly on paper for the code to compile. I used to hear, back in the day, C++ programmers opining that we should all use C++ because object-oriented programming is superior. Regardless of whether or not OO is superior, they completely failed to comprehend how one could do object-oriented programming in assembly language, or that we'd been doing it the whole time.

So its entirely possible that there's something I dont get about functional programming that means I don't understand what I'm missing. But its also possible that I understand the theory better than you and so I don't see the distinction you are making because there isn't one. To discern which is true, however, I'm going to need concrete examples, not opinion pieces.


I disagree. Generally I see this problem when trying to program in a functional languaged with an imperative thinking. This is not a weakness of the language, but of the developer.

I think the hunch of the original article is that few programmers understand the correlation between math and software, hence the lack of use.


Then show me a counter example and by that I mean name a specific, complex, in-production project written in a functional language.

Also, can you define "this problem" because I'm not sure which one you are referring to.


Pressed reply instead of the word correction.

Calculus should change the way you understand and perceive the world around, if it didn't, either you got bad teachers and need to ask for your money back, or you were studying only for the test.

And there are a lot of examples, but you can see that AFTER you understand and apply the math behind the concept. Getting by without it is not a proof of its futility, it is only a defense mechanism of the ego.


Ok.

Javascript. It is closer to functional programming than to object oriented. But most developers don't see this and believe that since they can get by shoehorning "classes" into a prototype then they are back to what is familiar. Prototypes are templates, no classes. Once you develop in javascript with a functional mentality, boy it becomes easy and elegant.

Sql and set theory is another example.

On the more abstracted side... Requirements modeling and calculus. Calculus classes should change the way that you percive


If you mean functions are first class and lambdas exist, any project written in Ruby or Javascript.


Do these programs meet the OPs definition of functional programming, or are they, in fact, a whole bunch of imperative code that use closures as a method for scheduling more imperative code?


The problem... Models are brittle. If they are, then they are not complete enough.


I think the point is that there's something intrinsically verifiable about a mathematical model since you're dealing with quantifiable output.

Other cases I can think of are systems where high-throughput or low latency are major requirements but there aren't many of those. Most of what we do is about getting more users or making more profit - good engineering performance and decisions are not directly related to these.


Video games are all about high-throughput and low latency. Nobody writing commercial games in functional languages that I'm aware of.


I believe the Jak and Dexter games were written in a Lisp dialect, although I'm not sure of the success.


Naughty Dog created their own version of lisp called GOAL to control game objects. Scripting languages are common in games, but the "heavy lifting" is done in C/C++, as is the case in Jak and Daxter and Crash Bandicoot. Naughty Dog don't use GOAL any more. Have their games gotten worse?

Also note that the effect on performance and throughput are cited as downsides of using GOAL.[1][2]

I met the Naughty Dog team back then and Crash was an awesome game. Their use of a custom scripting language for so much of a real-time game (as opposed to an RPG) was pioneering. They did other innovative things, like baking in radiance transfer to their models to get the lush levels in the game. But at the end of the day, when the Lisp evangelists left Naughty Dog, they stopped using it almost immediately. Apparently, despite using Lisp, and learning from "one of the best lisp programmers in the world", none of that rubbed off on what appears to be an excellent programming team.

The only explanations are:

a) In 7+ years of working with a foremost Lisp programmer, that knowledge did not transfer, or

b) It did transfer, and the other programmers did not see a net advantage.

The OP would like us to believe that the answer is (a). Subsequent games from Naughty Dog would suggest that it is (b).

[1] http://c2.com/cgi/wiki?LispInJakAndDaxter

[2] http://www.gamasutra.com/view/feature/2985/postmortem_naught...


"""Other cases I can think of are systems where high-throughput or low latency are major requirements but there aren't many of those."""

Actually, I haven't met many cases of systems were high-throughput or low latency are NOT major requirements.

Sure, you can wait for your admin script to do something for half an hour, if it means you get to write it in, say, Python, over some faster language. But you don't want to wait for most things, including most end user software. Here's a list people complain all the time about the slowness of:

1) text editors, programmer editors etc. 2) spreadsheets 3) media players 4) compile times 5) image editing programs 6) web pages/apps 7) mobile apps 8) games 9) file managers 10) IDEs 11) video/multimedia editing 12) sound editing 13) word processors 14) window management 15) databases 16) ftp 17) file management 18) asset management 19) browsers

If there's a program for something, there are people complaining it's slow/bloated.


Well observed, but I think we need to tell apart cases where performance is mandatory and where it is optional. People wouldn't just complain if it was mandatory, it simply wouldn't be a viable product.


Many modern web apps where many programmers are employed are simply IO glue (request in, database in/out, web page response out) and don't involve many algorithms other than sorting and using hashtables and trees.


There's interesting maths to be around proving the IO glue correct, though. Opa is an fun take on that problem.


Indeed. And you could go even further to say hashtables and trees too, are not necessary in most apps.


"We work in an environment where hearsay and taste drive change instead of studies and models. We are stumbling in the dark."

I completely agree. Programming became a lot less fun once I entered industry and realised most decisions are driven by fashion and office politics. It's not so bad when it's you and a couple of friends hacking all night on a project because you likely have closely aligned interests. Being an employee, however, means you're a slave to other people's ideals.

I suppose this is why most of us are interested in startups.

You may also be interested in this post by Zed Shaw: http://zedshaw.com/essays/programmer_stats.html

~~~

Surely the first person to write an algorithm wasn't Babbage or Lovelace, but more likely to have been the middle-eastern mathematician the word was named after? http://en.wikipedia.org/wiki/Mu%E1%B8%A5ammad_ibn_M%C5%ABs%C...


> In the early days programming was considered a subdiscipline of mathematics

But then the Electrical Engineering guys come and conquer, then CS evolve closer to EE than to Math.

And these days, well... your boss always look at you and say that does not want to now about math or performance, he want to know about accomplished deadlines and nice UIs.


I just began work on a new project that was half modeled. I initially tried to understand the existing model and wasted quite a few weeks for understanding that incomplete model. My problem is had i spent that time understanding the system...testing it as i would test a black box, i believe i could have constructed a better model..Ofcourse, this doesn't say anything about pros or cons of either approach..

And am beginning to get annoyed at the boiler plate generated by OOPS style programming.

But, to be honest, creating a model without looking at data first doesn't appeal to me either. I guess models will have evolve in sync with tests.. i.e: generate model/hypothesis,test, refine model/hypothesis test, repeat.


Yet another instance of content not set up to handle traffic. Anybody got the copypasta?


>>> 1.1+2.2 == 3.3 False

Requesting the database with some SQL inner join should get you less lines than both tables ? No ! It gets you a deadlock exception because some other program locks you...

Doing a DNS query to get IP address of an host ? Getting an IP ? Yes ? Everything ok ? No because some bit flipped somewhere and caused the result to be the IP address of foogle.com

So yes you are using maths but you are not doing maths.


There are a lot of famous people in programming that produce world-class output without using typed functional languages. Therefore I am going to interpret this as : typed functional languages are cool to work with, but not necessary to produce excellent software. And producing excellent software is probably the only thing that matters.


An article is needed, On why programming is not mathematics.


On everyday reality job, you often work to change a system, this is some kind of science besides the other common cs math fields.


Because they're not doing math?

Seriously - what is the useful model for a router or malloc?

Oh, and Babbage was not the first person to write an algorithm.


Routing is heavily based in graph theory, as far as I know, and so is actually fairly mathematical.

Memory management can also require a good bit of math. A perfect example would be taking an existing algorithm and optimizing it to use fewer memory accesses. We covered this sort of optimization in my recent algorithms class (for some algorithms) and it figuring out how to do required a good bit of math.

Really, the issue is that a programmer who doesn't use math is much less likely to see how math would be applicable to any particular situation. This is just like the programmer who does not know about, say, hash maps--he would not realize what he is missing.


> Routing is heavily based in graph theory, as far as I know, and so is actually fairly mathematical

I didn't write routing, I wrote router. Routing, figuring out what to send where, is just one part of what a router does.

> Memory management can also require a good bit of math.

Yes, but that part isn't the whole of the problem. It isn't even a large part of the problem. (Note that you quickly switched to a completely different problem from malloc to argue for a mathematical basis.)

Math is cool and important, but it often isn't the big problem.


Modern IP networking relies extensively on graph theory. The Spanning Tree Protocol is a prime example of this.


Graph theory is a very complex, and broad field of mathematics. The routing algorithms are an absolutely trivial application of it in a minuscule amount. Anybody, without formal training in mathematics can understand routing algorithms, because they are so simple and easy.


Yes, that is true. But, how those algorithms happen, is based in graph theory; is what I meant. If you saw Jamis Buck's "Algorithms" talk, I believe there's a reference to a "spanning tree" graph in there.

That said, I do agree with your point.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: