Percentage of Time We Spend Reading Code
You spend much more time reading code than writing code.
I like my code to be in order. I like my code to be piece of cake to read and easy to understand. And I'm willing to go the extra mile to brand my code adhere to those standards. But is it worth information technology? Is writing clean code a good investment?
When discussing this with colleagues I usually get i of two reactions: Either they intendance a lot about writing readable code, or the readability of code is not important to them at all. But what'south far more than interesting is that usually, they have a actually hard time explaining why they feel ane fashion or another.
Specially on new teams or later major personnel changes on existing teams I've seen this topic existence discussed more than often. Simply I've likewise seen that this discussion oftentimes lacks objective arguments and metrics. My primary argument in those discussions is usually quoting Bob Martin.
"Indeed, the ratio of fourth dimension spent reading versus writing is well over 10 to ane. …[Therefore,] making it piece of cake to read makes it easier to write." .
On the one hand, I dear the idea of simply comparing time spent reading and time spent writing code. On the other manus, I grew more and more than curious, because I felt this ratio for me is mode higher than 10 to 1. Also if we could make this metric more objective — potentially even let individual engineers compute this metric for themselves — information technology would be much easier to argue for or confronting spending time to make code more than readable.
Fourth dimension spent writing code
That being said nosotros'd showtime need to compute the fourth dimension spent writing lawmaking per day. Pay attending here: it'southward purely about the time spent writing code rather than fourth dimension spent "coding", because if nosotros talk about "coding" it ofttimes involves reading other code and to effigy out how or where to apply a change.
This could leave the states with the post-obit formula:
Lines of Code: For good reasons it's really hard to discover good sources for how many lines of lawmaking a developer writes. There are two sources that have collected contributed lines of code per developer over multiple projects reporting an average between 325–750 and 209–470 per month. This leaves the states between 10–37 lines of code per working day — if y'all calculate with xx working days per calendar month.
Characters per Line: If you look at successful open source projects this could give usa an indicator on this metric. AngularJS for example has an average of 39 characters per line on all Typescript files. A similar value tin be institute on GCC where lines have an boilerplate of 29 characters. Both include whitespaces.
Typing Speed: Based on this survey almost programmers can type between 30 and 70 words per minute. With an average word length of 4.8 chars per word, this ways most developers should be able to type between 144 and 336 chars per minute.
On average, an engineer would spend between 1 minute and 10 minutes writing code per twenty-four hours
Time spent reading code:
We could try to reverse engineer this metric. If nosotros would know how much time an engineer spends fourth dimension on "coding" we could subtract the time he spends writing code as well as the fourth dimension he spends thinking about the problem without reading other code
Coding Time: Based on the following ii surveys we can assume that engineers spend betwixt 3–5 hours per 24-hour interval or effectually 19.5 hours per week "coding"
Writing Lawmaking: As computed above this is around 1 to 10 minutes per day.
Thinking time: This value relates to time spent where you would think about the problem within the time you would allocate every bit "coding time", just without reading existing lawmaking. I have to admit, this is the vaguest value of all. I causeless this could somehow be related to the time required to write the code — although I'grand not super happy with this metric I think information technology could give u.s.a. a ballpark figure. So I presume information technology's effectually 5 to 10 times the time required to write the code.
On boilerplate, an engineer would spend between lxx and 294 minutes reading code per twenty-four hour period
Given the calculations above it would mean that you spend significantly more fourth dimension reading code than writing code. If you put those 2 metrics in relation the ratio of fourth dimension spent reading versus time spent writing is betwixt 7 to 1 and 200+ to 1.
The ratio of fourth dimension spent reading versus writing is between 7 to one and 200+ to one
To answer our initial question — is writing readable lawmaking a good investment? Hypothetically: Given an engineer has a ratio of reading versus writing time of most l to i. If this engineer would spend twice as much fourth dimension writing code including thinking almost it) equally before and in the procedure brand the code ten per centum more readable it would even out.
And those numbers also enhance an interesting question. Could this have an touch on personal learning goals? Would it make sense to focus on getting better at reading and agreement code? Could it make sense to rather larn a new shortcut to navigate inside your IDE or highlight usages of functions or variables instead of a new shortcut to make writing code easier?
I don't claim that those numbers are hard facts. Just I've tried to be transparent about how they are computed — which should give you the chance to decide for yourself how relevant they are for you lot. So please treat this as food for idea — best example those numbers are in the back of your head next time you lot need to make up one's mind whether to spend time on making code more readable or not.
Source: https://bayrhammer-klaus.medium.com/you-spend-much-more-time-reading-code-than-writing-code-bc953376fe19
0 Response to "Percentage of Time We Spend Reading Code"
ارسال یک نظر