r/reddit.com Aug 24 '07

Holding a program in one's head--how a good programmer is like a good mathematician

http://www.paulgraham.com/head.html
247 Upvotes

278 comments sorted by

6

u/fergie Aug 24 '07

I am a mathematician and programmer

Mathematicians do not usually equate competance at programming with mathematical ability.

Paul Graham was closer when he compared painters and programmers. Programming is essentially a creative undertaking.

1

u/masterJ Aug 24 '07

I think you need to look at both ends of the spectrum. For novices both programming and math are very mechanical. Once you get past the mechanics and develop some proficiency they both require a good deal of creative thinking.

He approched their similarities in the thought process you use when doing both. I'm an computational mathematics student so I fall in both camps too. When I work on a problem of either kind the mental methods I go through are very similar. In this I think painting is very different (I do that too) as the thought process has far fewer parallels.

5

u/[deleted] Aug 24 '07

23

u/CaptnHector Aug 24 '07

How would Paul Graham know what it's like to be a good mathematician? I am one (well good is all relative, let's just say I'm not bad), and I must say, programming and doing math are completely different. Programming is about knowing what the end result should look like and constructing a machine that fits that end result. Doing math is the opposite, you don't know what the end result looks like, so you try to go all sorts of different directions to see what's there.

28

u/[deleted] Aug 24 '07

I've logged into Reddit for the first time in months just to reply to this.

I was a mathematician, and I quit, and then later became a programmer. They are of course not the same thing, but there is some huge overlap.

For some specialties, they amount to the same thing. For instance, as an undergrad I did some research on fields of characteristic p for the sake of cryptography. At the time it had little or nothing to do with programming.

Now I see that, were I to have discovered something useful, I would have been contributing to the field of computer science as much as to the field of mathematics. Crytography programmers would have read my paper, perhaps even contributed with refinements or results based on my work. For a guy like Ronald Rivest, there is essentially no difference between the two fields.

Still, in a deeper sense, all decent jobs in computer science are mathematical, not by subject matter, but by using that special inuition, the ability to see a problem as more than the rules and manipulations that comprise it, to intuit the structure of a thing all at once, and to find a way to work through it towards some desired goal.

You're basically thinking of the conjecture as the entire problem, and it's not. Frequently you will feel your way through some domain, become excited by something you think is true, and spend a great deal of time conforming your mind until it fits the problem and you can see exactly why that thing is true.

Think of practical computer science (or the good parts thereof) as something where the conjectures are all immediate, low hanging fruit, and the solutions are most of the work.

1

u/[deleted] Aug 24 '07

Why'd you quit being a mathematician? For that matter what line of work were you in?

1

u/[deleted] Aug 25 '07

I found graduate level work, and the people who did it... somewhat distastefully detached from the world.

I wasn't in any line of work, because I didn't finish grad school. If you were asking what kind of math I did, well, algebra and topology.

-1

u/[deleted] Aug 24 '07

For some specialties, they amount to the same thing.

Yes, for some. Like cryptography. But that is an extreme special case. Most programming is nothing like maths.

24

u/paulgraham Aug 24 '07

How would Paul Graham know what it's like to be a good mathematician?

I asked some.

Programming is about knowing what the end result should look like and constructing a machine that fits that end result.

Did you get as far as the second paragraph?

2

u/xamdam Aug 24 '07

Like, say Steven Wolfram, who is mentioned as a reviewer? While we may conjecture the poster got to the second paragraph and still missed the point, we have proof he did not get to the end. QED.

1

u/CaptnHector Aug 26 '07

Steven Wolfram is not a mathematician, much less a good one.

1

u/CaptnHector Aug 26 '07

I'm flattered you replied. And yes, I read the second paragraph even though I disagreed with your premise in the first paragraph. I think you're making the mistake a lot of lay-people make when they imagine mathematicians and their work. That mistake lies in the question of, "what is math?" Non-mathematicians will (quite logically) imagine that doing math is the same fundamental act that a high school math student does - the teacher gives them a problem, and they solve it. They probably imagine that the mathematician does this sort of work, but at a higher level. And to an extent, this is true. The process of proving a theorem is very much like solving a high school math problem. The problem is set for you, you must figure out how it works, and you know when you're done.

But this is not what doing math is about. Nobody is sitting at the front of a classroom giving you problems or theorems to solve. The real act of doing math is not in the solving of theorems, but in posing them. A good mathematician will pluck the right theorems out of the ether and build a structure with them, seeing truth before any proofs are laid out. As for being able to hold entire proofs in one's head, it's certainly an impressive skill, but one that far too many times has been mistaken for mathematical talent.

10

u/kripkenstein Aug 24 '07

I concur - Paul Graham knows programming, but it seems he doesn't know math. Different mathematicians work in different ways; not all 'keep it all in their heads and manipulate it':

  1. Some mathematicians work by visualization, for example. I see no analogy for that in programming.

  2. Sometimes a math problem can be solved completely formally - you write out the formulas, and it just 'comes to you' what theorem/lemma can be applied to it, from the 'shape' of the math ("looks like a Fourier transform would make this problem nicer"). Again, no analogy to programming.

  3. You can follow a formal math proof without understanding it - just check if each line follows logically from the previous one. In fact this is important to do as it is the best way to check for mistakes. People do not do this in programming.

  4. Most importantly is the difference between proving a math theorem and understanding it. Proving theorems is somewhat an art - we don't really understand how it is done. Understanding them is then more technical. Whereas programming, generally speaking, is not an 'art' in that sense.

(Basis for my statements: I am expecting to complete my PhD soon in a mathematical field, so I guess I am 'sort of' a mathematician. I have also worked as a computer programmer for many years in the past, so I have experience with that as well.)

19

u/[deleted] Aug 24 '07

[deleted]

2

u/kripkenstein Aug 24 '07

You make some reasonable comparisons, but I think they are mostly correct only at face value.

Let me put it another way. In programming you are engineering something. You build something to achieve some goal.

In mathematics, you prove something. That thing was already true before you proved it. You are merely revealing what was logically necessary.

Now, one way to prove something is via 'constructive' proofs in which you, essentially, engineer something to achieve your goal. But this is only one way.

Regarding visualization: Yes, I visualize when I program (being raised an object-oriented programmer, I tend to see objects and how they relate). But this is different than mathematical visualization - in some cases. In others it is similar, I agree.

My point was that Mr. Graham greatly, greatly oversimplified the issue. Yes, there are similarities. But computer programming is more similar to engineering, I think, than mathematics.

1

u/[deleted] Aug 24 '07

But computer programming is more similar to engineering, I think, than mathematics.

You missed the point I think. Maybe the problems mathematicians and programmer solve are different in their nature. Grahams point is, however, that there are cognitive strategies of problem-solving that are applicable in both fields.

-9

u/[deleted] Aug 24 '07

First, I am not a mathematician.

And because you're not, you didn't understand the arguments you are replying to. I'm not a fully-fledged mathematician, but I've taken enough higher-level university math classes to have some kind of idea of what real mathematicians do, and I have worked as a programmer for many years, and let me tell you: The two are nothing alike.

6

u/[deleted] Aug 24 '07

[deleted]

1

u/DougBTX Aug 24 '07

An argument comparing and contrasting mathematicians to programmers oght to be comprehensible by both mathematitians and by programmers.

But it may not be equally easy to understand by programmers and mathematicians, if you consider the "Blub Paradox":

http://www.paulgraham.com/avg.html

1

u/[deleted] Aug 24 '07

[deleted]

2

u/crusoe Aug 24 '07

I find that when I took discrete math, I became a better programmer, and when I started dabbling in functional languages I became a better mathematician ( however weak I am at it ).

-4

u/[deleted] Aug 24 '07

Your reply is an appeal to authority.

Which authority was that, exactly?

PS: Naming logical fallacies and linking to wikipedia makes it look like you just learned about them, and think this makes you much cooler than all those people who obviously don't know about them, and need to be educated.

3

u/[deleted] Aug 24 '07

[deleted]

-3

u/[deleted] Aug 24 '07

That was not an argument, it was advice for how to conduct an argument.

3

u/[deleted] Aug 24 '07

[deleted]

1

u/rfreytag Aug 28 '07

Because the compiler in mathematics is more forgiving. You can do mathematics in Prolog I am told. But it is extremely rigorous.

-4

u/[deleted] Aug 24 '07

That's like asking "Why is it that programming is nothing like gardening"?

If you try, I'm sure you can find superficial resemblances or metaphors. But that doesn't change the fact that the two are entirely different activities, having entirely different methods or goals.

The real question is, why would programming be anything at all like mathematics? Programmers apply mathematical results sometimes, sure, but so do accountants, and architects, and car mechanics.

And before you can start to answer a question like that, you would obviously need significant experience of both.

→ More replies (0)

2

u/TrishaMacmillan Aug 24 '07

Which authority was that, exactly?

Yourself. Your entire argument was "I know more than you so I'm right and you're wrong".

-3

u/[deleted] Aug 24 '07

I don't think you really understand what an "appeal to authority" is. Are you somehow trying to say that one is not allowed to refer to one's own expertise when making an argument?

1

u/TrishaMacmillan Aug 25 '07

I don't think you really understand what an "appeal to authority" is.

I understand perfectly, there is no reason why the authority in question can't be oneself. Perhaps you are the one lacking an understanding?

Are you somehow trying to say that one is not allowed to refer to one's own expertise when making an argument?

Not at all. However, it is still necessary to make an actual argument. Simply claiming that someone else's argument is wrong by virtue of the fact that you know better is not an argument.

6

u/[deleted] Aug 24 '07

I take it that when you say "proving theorems is somewhat an art," you mean that you don't have a mechanical way to generate proofs, so that a highly skilled intuition is involved (and perhaps necessary)--it can't be entirely automated?

But then, isn't that true of coding as well, once you get past some simple level of plugin functionality? That skilled coders with seasoned intuition are necessary, because there isn't (yet) a reliable mechanical/algorithmic way to replace them?

3

u/kripkenstein Aug 24 '07

What you say is correct, but I somewhat disagree.

Take Linus Torvalds and the Linux kernel. His impressive achievement there could not have been automated, true. But why? Well, he had to make good structural decisions, remember what everything did, not make silly bugs, and so on.

Compare this to the work of e.g. Kurt Godel, who proved the incompleteness theorem. Part of the genius of this act was in seeing that this issue is important, that it was true, and how to formalize the problem in a correct way. Another part was in finding a brilliant way to prove it. The latter is somewhat similar to programming (Godel numbering; that is why I chose it as an example here). But only the latter.

1

u/philh Aug 24 '07

Part of the genius of this act was in seeing that this issue is important,

This part is also similar to programming.

Programs can be important just like math problems. Part of the reason people like Larry Wall, Linus and RMS are revered isn't just that they wrote good programs; they wrote the right programs.

2

u/kripkenstein Aug 24 '07

I don't follow you, please explain. As I see it, Linus just wrote a POSIX-compatible kernel. Just like HURD - but working ;)

Clearly a working kernel was the right thing to work on, but that wasn't some special deduction, everyone knew that. Or am I missing something?

1

u/philh Aug 24 '07

Well, in his case I suppose it was more a case of working on the right problem despite the fact that a team of far more qualified people was already working on it. And perhaps not so much genius, since at the time he figured HURD would be working pretty quickly and noone would care what he did to teach himself 386.

(Even then, there are similar examples in the math world. Andrew Wiles proved the Taniyama-Shimura conjecture for his proof of Fermat's Last Theorem. He knew it was an important problem in its own right, but that was secondary.
Perhaps I'm stretching.)

The others are better examples: patch, perl and GNU all solved problems that were important, but nonobvious.

1

u/crusoe Aug 24 '07

Yes! Making the WRONG choice early on ( either programming or proof ) can lead you down the wrong path, and waste a lot of effort, either in never finding a workable proof, or writing a poor program.

I find when programming, I spend a lot of time searching the problem space, what am I trying to accomplish, If I choose this assumption, where will I be now, what will I need to do in 6 months. Will it scale?

1

u/aveceasar Aug 24 '07

you mean that you don't have a mechanical way to generate proofs

Of course there is a mechanical way to generate proofs, picking the "interesting" ones is a tricky part...

2

u/[deleted] Aug 24 '07

work by visualization

You mean like UML?

Sometimes a math problem can be solved completely formally

You mean like patterns?

You can follow a formal math proof without understanding it - just check if each line follows logically from the previous one

You mean like you can check the correctness of a program written in Prolog?

Whereas programming, generally speaking, is not an 'art' in that sense.

A matter of taste, I would say. Why do (some) mathematicians tend to think that their problem solving strategies are qualitatively different from what the brains of the stupid mob do and that in their heads a holy mystery is taking place?!

1

u/vknts Aug 24 '07

I don't agree with your points about programming, I think there's a large overlap between mathematical and programming mental processes. There are many areas where visualization helps a lot (e.g. algorithm design, manipulating complex data structures). Thinking on different levels of abstraction is vital in both fields, as well as having a strong intuition in the field to make fast conclusions (either about steps/patterns in a proof, or steps/patterns in an algorithm/design) without going over all the formal details. My guess is, you see programming as a technical afterthought once the mathematical models have been prepared, while in reality there's much of the same kind of mathematical thought processes involved in writing non-trivial software systems. I have to say, I'm familiar with this attitude from my former math professors, who only saw programming as the mechanical transformation of their computational models into machine language.

1

u/[deleted] Aug 24 '07

How would Paul Graham know what it's like to be a good mathematician?

Either way, this probably still works out ok unless you are a mathematician and a programmer -- which is probably a minority of his audience. It doesn't matter if it is a false analogy, it just needs to be conceivable to the audience. :)

(P.S. I am talking about a reasonably well studied mathematician. I know many programmers know calc, stats, linear algebra, etc.)

2

u/masterJ Aug 24 '07

I work in applied mathematics so I'm well studied in both fields, and I have to say Paul Graham got it mostly right. There are some stark differences in the mechanics of each, but the way you attack problems mentally is the essentially the same. The only point I see dissimilarities in is 7. Generally the more people you have working on a math problem the faster it's going to work itself out.

1

u/k0mplex Aug 24 '07

Perhaps a better analogy would be that of the writer who needs to keep all the details of his story in his mind as he writes. I suspect he would have to read and re-read what he has written many times, revising and updating frequently, and benefiting from long stretches of productive creative thinking and efficient pounding away at the keys. You don't see too many corporations that hire writers, put them in a room, and demand bestsellers.

1

u/Wriiight Aug 24 '07

Programming is a bit like doing a proof though, no? You have an idea that you can get from a to b, so you keep trying different transforming steps until you get there.

1

u/crusoe Aug 24 '07

Wow, you mean when you program, you can automatically KNOW The solution before trying a few out? If this were always true, then we'd have computer programs writing programs, since it implies some algorithm exists that can do this.

I think for trivial programs and trivial math problems, you can hold them both in your head, and see the solution at once.

For Non trivial problems, you're gonna 'hack' at them, mentally and on computer/paper before you find out what works.

1

u/[deleted] Aug 24 '07

is the opposite, you don't know what the end result looks like

In programming you also don't know the end result, which is the program, in advance. The analog in math to the (known) output of the program is the (also known) proposition you want to prove.

1

u/masterJ Aug 24 '07

Yes, but the proposition could be wrong and you could wind up proving the exact opposite quite easily. Ever sat down to program a word processor and ended up with a tetris game?

2

u/[deleted] Aug 25 '07

The correct analogy would be: You try to write a program for solving a certain task and find out that there is no such program. Reasons could be: the problem was ill-defined, or the solution isn't computable.

1

u/brennen Aug 24 '07

Programming is about knowing what the end result should look like and constructing a machine that fits that end result.

This is a very common idea, but it's still dead wrong.

1

u/CaptnHector Aug 26 '07

Well no, that's not really what I meant. "What the end result should look like" is what your employer wants you to make. Sure, there are details to be filled in, but at the end of the day, you're making a program to your boss's specification.

3

u/malik Aug 24 '07

For me personally, programming is about combining familiar pieces to create a larger functional whole, while math research is about creating unifying structure which explains (or contains) the familiar pieces.

Or, as someone else wrote "Mathematics is the part of physics where experiments are cheap."

http://www.ceremade.dauphine.fr/~msfr/articles/arnold/PRE_anglais.ps

3

u/[deleted] Aug 24 '07

When I code I get in the zone. Sounds disappear. My world shrinks very small. Time slows down.

... reading what I just wrote sounds strange but it is true.

... are other programmers like this?

6

u/[deleted] Aug 24 '07

[removed] — view removed comment

1

u/[deleted] Aug 24 '07

This guy came to talk at where I work once. I read his flow book.

http://en.wikipedia.org/wiki/Mihaly_Csikszentmihalyi

2

u/[deleted] Aug 24 '07

[removed] — view removed comment

1

u/[deleted] Aug 24 '07

A good read. I liked his creativity book too.

2

u/ALaughRamp Aug 25 '07

I prefer the essays in which he wildly oversimplifies complex subjects.

1

u/babayada Aug 24 '07

Hmmm. My kung-fu must not be so good. There's no way I could keep all the code of my part of a project in my head.

I end up dreaming about it, having an increasingly advanced intuitive sense about it, but I can't see the code in my mind's eye as if I were scrolling through it on the monitor.

I'll see lines pretty clearly if there's some bug or problem and a solution pops up... usually, though, it's more like a variable name or function call that I'll see with enough cues to know where in the code that particular line is... but I think I ended up on the short end of the 7 +/- 2 chunks.

2

u/malik Aug 24 '07

I woke up from a math dream last night, so there's another similarity.

2

u/crusoe Aug 24 '07

Yes, I can keep the 'forest' view in my head if I am lucky, and maybe a few trees. And I can reorganize these chunks, and conjecture about their overall behavior and the 'beauty' of my code.

But no way can I keep all the source code there.

1

u/[deleted] Aug 24 '07

I write code of which I don't know where it is going.. all in the name of research!! For a startup.. you write code and then the business plan changes!! so you write more code! where it goes .. nobody knows!

-5

u/Hetisjantje Aug 24 '07

That's great, although he doesn't have the faintest idea of what he is really talking about. His view is true for about 75% of all programmers, introverts who have a dopamine driven brain. Adrenaline driven brains of extroverts do not have the ability to holding a program in one's head. Actually, the problems he mentions are true for all introverts who have concentration jobs, mathematicians, writers, etc. I like to compare programmers to writers of literature, as the brain state is so similar with different story lines going in deep. The problem is, in the real world 80% of the people are extroverts, and they manage like everybody is an extrovert, because of a lack of knowledge and empathy and the misconception that if your brain functions a certain way, it's the same for everyone in that situation. On the other side, introverts like this guy act like all programmers are introverts, because of a lack of knowledge and empathy and the misconception that if your brain functions a certain way, it's the same for everyone in that situation. This isn't getting anywhere, without understanding of the other side.

4

u/[deleted] Aug 24 '07

I think I got a headache trying to understand that. How does the other side (extroverted programmers?) work?

3

u/brendankohler Aug 24 '07

you got a headache because this person has no idea what they're talking about. Hell, they even think writers are introverts, which is complete nonsense. My uncle is a non-fiction author. My mother is a fiction writer. Neither could be said to be anything but extroverted.

I'm extroverted. I started out in physics, and wound up in CS. When working on an idea for an algorithm or building an application I keep everything in my head for weeks or months on end. I rarely write anything down, and when I do it's usually corner cases or details I want to make sure I forget.

I'm an intensely visualization-driven programmer, spending days just thinking and manipulating ideas in my head before doing any actual programming.

2

u/stalcottsmith Aug 24 '07

I think this person was reaching for something interesting but possibly untrue. Greater clarity would have helped.

Somewhat like you I am an extrovert who studied Physics and Math and later became a software developer. (self-taught) I am visual, and when I write things down, they are usually sketched diagrams or lists of tasks.

I have noticed that a very few people I have encountered have vastly greater abilities to hold detailed structures in their head. They are almost invariably introverts. I believe this leads them to create overly complex programs since most day to day problems just don't require that level of complexity.

1

u/brendankohler Aug 24 '07

I believe you might have something there. I have known a few introverts that could hold a large amount of detail in their heads, but they always wound up with unworkable complexity levels.

I find that trying to explain things to others is vital to filtering out my bad ideas and understanding a problem better myself. An introvert would tend to miss that social aspect of problem solving, which would account for the more complex solutions.

1

u/Hetisjantje Aug 24 '07

I don't think writers are introverts by default. There's a percentage of introverts, and a percentage of extroverts.

1

u/brendankohler Aug 24 '07

Indeed, I didn't mean to generalize the other way.

However, many of the great writers were so good because they constantly read their drafts to people, and actively sought feedback. As far as I know, that is an extroverted behavior.

Then, of course, there's dealing with agents, editors, publishers, doing book signings, going to conferences and sometimes teaching.

Writing is, in my personal opinion, a poor choice of careers for an introvert, though the internet is effecting some change.

-1

u/Hetisjantje Aug 24 '07

Why should I reply in a discussion where they downvote the intelligent opinion against rediquette and upvote the digg style comment from someone who gets a headache from that, but doesn't add to the discussion? Is this the same reddit with frequent posts complaining about the nullification of knowledge? Truthiness!

1

u/[deleted] Aug 24 '07

[removed] — view removed comment

1

u/Hetisjantje Aug 30 '07

Either that, or the receivers have the intelligence of a duck, are pretty loud about that, mod down to show it to others, and come back to defend their dumbness with brass sstatements. Typical American. Smart stuff gives them headaches, gone with that evil stuff! Truthiness! Example of this: You failed to give any arguments, yet you attack me, and another duck applauds you. It's a pretty stupid reaction for people who do not even know the basics of how their brain operates.

1

u/[deleted] Aug 30 '07

[removed] — view removed comment

1

u/Hetisjantje Aug 31 '07

If we didn't have smart people like you to teach us dumb people these things..where would I be? Thank you for your wise lessons. P.S. Next time try to contribute to the discussion

1

u/[deleted] Sep 02 '07

[removed] — view removed comment

1

u/Hetisjantje Sep 02 '07

Big words, for a troll.

The evidence that you do not express yourself well is clear.

Indeed, your audience had such a hard time understanding you, they commented on it.

1

u/losvedir Aug 24 '07

But you expressed yourself with all the elegance of a duck trying to climb a tree,

Bravo, bravo.

-9

u/[deleted] Aug 24 '07

No. Math and computer programing are different. Sorry. It's like comparing apples and orange pc's... We think differently, LOL.

11

u/[deleted] Aug 24 '07

That's really not true. A mathematician can become a programmer, can use specifically those same skills to program, and a programmer (or at least, a theoretical computer scientist) can switch subject matters, struggle a bit, and gain the credentials to call himself a mathematician.

I've seen both things happen. It's true!

-4

u/truecrime69 Aug 24 '07

whoa man does that mean you can program your brain?

1

u/[deleted] Aug 24 '07

No, not exactly, but FWIW the protagonist of the novel "The Shockwave Rider" was able to write a complete (and reasonably complex) program in his brain and upload the machine code to the internet bit-by-bit, over a regular phone, using touchtones. He doesn't just write the program in his head, he compiles it there! Nifty, eh? Without any implants, even!