Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
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.
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.
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.
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?
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.
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:
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.
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.
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, 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.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.