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.

10
  • 12
    The last question I looked at on StackOverflow 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. Sep 24, 2020 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. Sep 24, 2020 at 22:24
  • 12
    As a programmer, I honestly would be surprised if the number was really so low as 10. Sep 24, 2020 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, 2020 at 1:12
  • 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. Sep 25, 2020 at 4:19

1 Answer 1

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.

12
  • 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. Sep 25, 2020 at 11:37
  • 2
    Welcome to skeptics.SE! While I agree with your logic, answers here should generally include sources. 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, 2020 at 13:31
  • 3
    Please provide some references to support your claims.
    – Oddthinking
    Sep 25, 2020 at 14:00
  • 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, 2020 at 0:37
  • 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, 2020 at 14:01

Not the answer you're looking for? Browse other questions tagged .