Live data from Hacker News

Holding a Program in One's Head (2007)

paulgraham.com

71–80 of 114 posts

Re: Holding a Program in One's Head (2007)

#71
post #13

Earlier quoted context omitted.

Said another way: push interface up and implementation down.

Well said, I’ll be taking that :)

I can't take credit for it; I read it in a C Users Journal article back in the 1990s which I haven't been able to find online.

Re: Holding a Program in One's Head (2007)

#72

I'll call out 7. Don't have multiple people editing the same piece of code. You never understand other people's code as well as your own. No matter how thoroughly you've read it, you've only read it, not written it. So if a piece of code is written by multiple authors, none of them understand it as well as a single author would. On some level it's true but it is also true that most of the world's code is in some sort…

When I’ve had to take over maintenance of code that isn’t mine, and is poorly commented and documented, which is usually the case, I work through the code and comment it. That eventually leads to refactoring, adding unit tests as needed, and so on…and eventually the code that wasn’t mine is now mine.

But there’s no time in the schedule for that? Either that’s not true (the long way round is usually the shortest way home); or it’s time to find another project. And if you’re the sort of person who has the skills Graham describes, that shouldn’t be hard.

Re: Holding a Program in One's Head (2007)

#73
post #42

Earlier quoted context omitted.

Those are called functions.

Sometimes. Sometimes it is one or more programs writing to a queue or topic, and other programs reading from that topic. Or programs writing to and others reading from a Unix pipe. Or programs talking to each other using HTTP. Or Erlang processes communicating concurrently on one machine or across a network. Or different programs sharing one database. Or many objects communicating by passing messages in a small talk…

Or to put it another way…clean architecture is how you arrange the code so that you don’t need to keep ALL of it in your head at once, just the big picture and this bit here.

Re: Holding a Program in One's Head (2007)

#74
post #24

Earlier quoted context omitted.

I think that many, perhaps even most, engineers incorrectly believe that the main purpose of abstraction in code is simply DRY, as if the goal is to save keystrokes or something. In my view, the purpose of abstraction is to compress the concepts of your application into digestible and manueverable chunks, and DRY is just a heuristic for beginners to follow to help point to where appropriate abstraction boundaries may…

I think DRY should be supplemented by "Don't make me read it multiple times". Repeat yourself, by all means, if that makes it so that I don't get all twisted up jumping between so many files that I can't keep the main thread straight while I read your code.

Don’t repeat yourself…but don’t obfuscate the code either.

Re: Holding a Program in One's Head (2007)

#76
> You never understand other people's code as well as your own.

Not only is that often false, but there are times when you can understand another author's code better than that author does. Like to see through it and why it cannot possibly work, while they are laboring toward that.

Re: Holding a Program in One's Head (2007)

#77

Earlier quoted context omitted.

Robert Morris, Peter Norvig and Stephen Wolfram didn't write code? (I don't recognize some of the others.)

Is that what they're famous for or even what they've dedicated most of their time to? From looking at their histories I would not describe them as "coders." Let alone presume that they have anything to offer anyone doing the same in a modern context. "Keep the whole program in your head?" Cool advice for small greenfield projects that you can sell to unsophisticated companies and then move on. Interesting that it com…

yes, writing code is what all three of them are most famous for. especially writing code for vast, significant projects spanning decades, in a way that contributes to something significant. your criticism could hardly be further off target. you dismiss their knowledge at your peril

Re: Holding a Program in One's Head (2007)

#78
post #42

A good way to keep a program in your head: Break it up into a few or several smaller programs that interact through clean interfaces. Then you can keep one smaller, simpler program in your head at a time, then integrate them at the end once all the smaller programs are working.

Those are called functions.

The UNIX way would be to break things down into actual programs, where each one would be doing one thing well - and in such a way that they'd be useful as building blocks for solving other problems also.

Re: Holding a Program in One's Head (2007)

#79
Another PG classic masterpiece - thanks for re-posting, I agree with all eight points, and this should be mandatory reading for people that manage developers particularly if the new manager does not herself/himself have a development background.

Just to elaborate on "start with a simpler subcase": you can even start with a single example and do what your code will be supposed to be doing automatically by hand. After your draft architecture stands, you can even hardwire what each component does for that one example to see if things fit together before implementing the general method for each component, which provides an opportunity for early integration testing that is priceless.

The current essay recommends building bottom-up primitives that serve as primitives or languages (DSLs) for the next levels. This is true, but you can do this upside down. For example, you can write code that looks like pseudo-code because implementations of functions you call do not (or not yet) exist. The code directly reflects how you think, and you worry about the implementation later. A special instance of that is API design, where you design interfaces without implementing them yet; you can then write client code and judge if the hypothetical API would be flexible enough, be easy enough to use, and be feature complete and orthogonal. When designing an architecture in a team with multiple people, you can use paper cards with an example piece of data that you pass from person to person, with each person "performing" a component. They can then check that they have what they need to carry our their task (otherwise there may be bad surprises when integrating components later).

I found that some people are more leaning "top down" and others more "bottom up"; I like to mix both styles, with system architectures designed top down and the core algortihms inside their components often being designed bottom-up, sometimes also top-down.

Ironically, looking only at the headline, one could say that abstraction enables one to solve problems without getting the whole problem in one's head, or problems bigger than what anyone can hold in their head, at least not at the same time, which kind of is the whole point made by SICP.

Re: Holding a Program in One's Head (2007)

#80

> You never understand other people's code as well as your own. No matter how thoroughly you've read it, you've only read it, not written it. There is certainly some truth to this. On the other hand, it's possible to become blinded to defects in code you've written yourself. You see what you intended for the code to do rather than what it actually does. Reading someone else's code, it can be easier to see what's real…

This is true and it's one of the problems I have with code generators and these days, AI generated code.
Post reply on HN