6

There is a popular quote, maybe originated by Robert C. Martin, that says that code is read ten times more than it's written (meaning edited). Goodreads reports it.

As another example the quote is reported in a Microsoft blog.

However I could never find any reason to think this is true.

Is there any research done on the subject? I agree is not possible to answer this question in general but at least a very limited subset of scenarios could be analysed.

gurghet
  • 209
  • 2
  • 6
  • 12
    The last question I looked at on [StackOverflow](https://stackoverflow.com/questions) was a short piece of code, probably written by one person, which had had 25 views at that moment, a ratio of 25 readers to 1 writer, and the question had not even been there very long. – Weather Vane Sep 24 '20 at 21:51
  • 12
    Speaking as a programmer for about 40 years, I see nothing remarkable about the claim, though the variability is so high that it would be pretty much impossible to verify. And note that the quote is about the *time spent* reading vs writing, not the number of times read vs written. – Daniel R Hicks Sep 24 '20 at 22:24
  • 12
    As a programmer, I honestly would be surprised if the number was really so low as 10. – plasticinsect Sep 24 '20 at 22:43
  • 8
    This quote seems to lean heavily on context and definitions. I have worked on projects where my code was read by around 8 code reviewers. I have worked on projects where most of the code was machine-generated and never read by anyone, ever. Arguably, most of my code is read many, many times in the first 30 seconds after typing it. What would a good answer look like? What evidence could be provided? – Oddthinking Sep 25 '20 at 01:12
  • @Oddthinking - Uncle Bob obviously was not talking about autogenerated code. That doesn't count in this context. If it did count, almost all code would be unread by anyone. – David Hammen Sep 25 '20 at 04:10
  • 21
    You are misinterpreting what Robert Martin wrote. He is not claming that every written line of code written is read by ten people, after the fact. He is claiming something even stronger, that in the very process of writing code, the author spends more than ten times as much time looking at existing code than time spent writing new code. (He was apparently referencing maintenance programming.) Code reviews, to which others have alluded, are icing on the cake. Reading sample code, to which others have alluded, are also icing on the cake. – David Hammen Sep 25 '20 at 04:19
  • 2
    One frequent developement activity that involves a lot of code reading, and very little code writing is debugging. I've worked on projects where the time was roughly equally split between developing new features and finding problems in exisiting code. When writing new code, there is still reading of existing code involved - to find the appropriate places to change, and to find parts of the code that might be reused. Code designed with the open-closed principle in mind may reduce the need to actually edit existing code, but does not remove the need to understand (and thus read) it. – Hulk Sep 25 '20 at 07:00
  • A quick search turned up [student project of a business school](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.370.9611&rep=rep1&type=pdf), which comes to similar numbers (roughly 50% of overall effort is maintanance), some more digging might turn up better sources. – Hulk Sep 25 '20 at 07:12
  • 1
    @DavidHammen: My point is that the interpretation of the claim requires a lot of context. I suspect it is going to turn into "If we limit the cases to the type of code that the claimant was talking about - i.e. business code that is written once and frequently read, we can show that it is written once and frequently read." The OP has already tried to classify edits into the "written" column rather than the "read" column. I think the claim is vague - and for the cases where it is true, it is obvious. – Oddthinking Sep 25 '20 at 14:05
  • I'm going to put in the fourth close vote as "not notable", because I think @DavidHammen is right in his comment above. –  Sep 26 '20 at 13:41

1 Answers1

6

The full quote itself (from your source) provides reasons for this being true (emphasis mine):

Indeed, the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. ...[Therefore,] making it easy to read makes it easier to write.

It's very rare that a software application is written once and works perfectly forever, and never needs any new features to be added. Writing code is an iterative process, with each iteration building on the code produced from the last, adding features, fixing bugs etc. In order to do that you need to be able to read the existing code to know how and where to modify it, how to write code that uses the existing code, debug issues in separate but related pieces of code. The number of reasons for reading code far outweigh the number of reasons to write it.

To illustrate this consider the software development lifecycle as shown in the below diagram: software development lifecycle

Only the Development stage really involves writing your business logic code. The testing phase may involve writing tests and maintenance may involve writing bug fixes. In contrast, almost all of these stages will require reading code if the project involves adding features to an existing application. If it's brand new project only initiation and requirements gathering wouldn't necessarily involve reading code, but they may.

ewanc
  • 534
  • 4
  • 11
  • 1
    Even as you're writing the code you spend a lot of time reading it. You need to refresh your memory as to what variables were used, what loop conditions are present, etc. – Daniel R Hicks Sep 25 '20 at 11:37
  • 2
    Welcome to skeptics.SE! While I agree with your logic, answers here should generally include [sources](https://skeptics.meta.stackexchange.com/questions/5/faq-must-all-answers-be-referenced). Your answer doesn't really add any new sources though, but is mostly based on personal opinion. Ideally, a good answer here should include references to studies on the subject. – tim Sep 25 '20 at 13:31
  • 3
    Please [provide some references](http://meta.skeptics.stackexchange.com/q/5) to support your claims. – Oddthinking Sep 25 '20 at 14:00
  • I couldn't find any papers on the subject and many books just restate the claim as fact. Would some references relating to *why* you would read code more suffice? – ewanc Sep 25 '20 at 15:20
  • 5
    @tim, unfortunately, this is one of those "What color is the sky?" questions: the answer is so self-evident that people don't bother writing papers on it. – Mark Sep 26 '20 at 00:37
  • @Mark I added a bit about the software development lifecycle to try to show why it's self-evident – ewanc Sep 28 '20 at 13:29
  • @Oddthinking Is this "provide references" flag really useful for this answer? This is very, very, very basic knowledge about software development, and Ewanc did a good job putting together an answer that explains the situation well. I understand the site has rules and all, but in this case they are working against us more than anything. – T. Sar Sep 28 '20 at 13:44
  • @ewanc: Your change isn't helping. It isn't adding empirical evidence. It is adding more theory. – Oddthinking Sep 28 '20 at 13:58
  • 1
    @T.Sar: This is an argument towards closing the question rather than accepting a theoretical answer. But the answer is closed, so it is moot. – Oddthinking Sep 28 '20 at 14:01
  • @Oddthinking Fair enough, given the very basic level of the question and the fact that it should be self evident to any experienced person in the industry, if this answer isn't acceptable then I don't think it's possible to answer to the standards of this site. Perhaps it would be better asked on Stack Overflow but I imagine it would be closed there too. – ewanc Sep 28 '20 at 14:09
  • @ewanc Maybe it would work better on Software Engineering? I'm not sure if they tackle those questions. – T. Sar Sep 28 '20 at 14:55
  • Potential source of evidence: https://www.researchgate.net/publication/221501127_An_examination_of_software_engineering_work_practices. Although this study didn't track time spent nor measure events on a per-line-of-code basis, it does make a pretty strong argument that editing code is a small minority of engineers' activities on a project. The 10:1 ratio seems really low in light of some of those charts. – Isaac Lyman Jun 02 '22 at 16:28