Live data from Hacker News

Ask HN: Does reading code actually make you a better developer?

news.ycombinator.com

21–30 of 30 posts

Re: Ask HN: Does reading code actually make you a better developer?

#21
I read with a specific context/goal in mind.

For a new code base, I start off with a high level design and one feature which touches the important parts. May be there is more knowledgeable with codebase around to ask and also decent documentation.

If I am in a Lisp like editing language, this [1] tracer is fantastic. Otherwise in non-live languages, I am a dead duck in the circus of breakpoints/debugger to step through the code.

You may also have a look at this [2], the author of Coders at Work, Peter Siebel talking about decoding code and from the same book a very interesting discussion on reading code which I have reproduced here.

---

Seibel: I’m still curious about this split between what people say and what they actually do. Everyone says, “People should read code” but few people seem to actually do it. I’d be surprised if I interviewed a novelist and asked them what the last novel they had read was, and they said, “Oh, I haven’t really read a novel since I was in grad school.” Writers actually read other writers but it doesn’t seem that programmers really do, even though we say we should. Abelson: Yeah. You’re right. But remember, a lot of times you crud up a program to make it finally work and do all of the things that you need it to do, so there’s a lot of extraneous stuff around there that isn’t the core idea. Seibel: So basically you’re saying that in the end, most code isn’t worth reading? Abelson: Or it’s built from an initial plan or some kind of pseudocode. A lot of the code in books, they have some very cleaned-up version that doesn’t do all the stuff it needs to make it work. Seibel: I’m thinking of the preface to SICP, where it says, “programs must be written for people to read and only incidentally for machines to execute.” But it seems the reality you just described is that in fact, most programs are written for machines to execute and only incidentally, if at all, for people to read. Abelson: Well, I think they start out for people to read, because there’s some idea there. You explain stuff. That’s a little bit of what we have in the book. There are some fairly significant programs in the book, like the compiler. And that’s partly because we think the easiest way to explain what it’s doing is to express that in code.

---

Overall, I try to read in small pieces with some clear goal. Interestingly enough, I don't know if we can read code from start to end like a book, may be literate programming makes that possible; but yes reading code is hard and that is simply because we don't have good code reading tools, yet in the 21st century!

[1] https://www.cs.cmu.edu/~dst/Lisp/dtrace/dtrace.generic

[2] http://www.gigamonkeys.com/code-reading/

EDIT: link to the code is not literature article

Re: Ask HN: Does reading code actually make you a better developer?

#22
I am a C# (mostly WPF) developer at work. Most of the applications I write communicate with an API written by another developer in PHP. As much as I dread PHP I learned to read his code(which is poorly documentation) and it has helped me learn quite a bit. Reading code that isn't yours opens your mind to a different style of thinking, it's very powerful; I would recommend it.

Re: Ask HN: Does reading code actually make you a better developer?

#25
Very much YES! Being able to read the code is a required skill for working on enterprise applications. Fixing bugs and adding features will have to play nicely with the old code. If you don't understand the old code, your new code will make matters worse. You may accomplish your short term goal, but without the ability to read and understand the old code you will create a very brittle solution.

Re: Ask HN: Does reading code actually make you a better developer?

#26
After learning a language enough to have an intermediate understanding of how it works, both conceptually and syntactically, I'd argue you learn more reading other people's code than you do writing your own.

The way I like to do this is to think through how I would implement something. Then, reference code that does something similar to the problem I was trying to solve. Then, I compare their solution to mine.

Re: Ask HN: Does reading code actually make you a better developer?

#27
For me, reading code, and then trying to implement my own version while resisting the urge to look at it again is the best way. I actually learn by doing, but reading other people's code, either in a blog or at work is a good place to figure out what I want to learn.

Re: Ask HN: Does reading code actually make you a better developer?

#29
Like books: as one reads more one gets to know what is written better. Overtime, reading code has helped me in inculcating good practices of others in my own writing. But having said that, writing code is like playing sport. More we code - better we get atuned to (developer) environment - no amount of reading will help!

Re: Ask HN: Does reading code actually make you a better developer?

#30
Being able to read someone else's code is an essential skill. If enough time has elapsed it can even be a useful skill for code you wrote some time ago. It can make you a more effective developer because, for example, you will be able to read through open source code to understand what it does (since some have poor docs) as well as allow you to contribute fixes and enhancements. You can also find new techniques in code that you can add to your own 'arsenal'. Another reason is it is a great way to learn a new language: you can start reading examples and mapping patterns from languages you know into the new one. So yeah, this is an essential skill.
Post reply on HN