How Many Software Developers Know How Read Code

The Most Efficient Style to Read Lawmaking Written by Someone Else

How to speed up the struggle of reading others' code in 4 steps?

Sara A. Metwalli

As developers, regardless of our specialty, whether information technology existence data science, front end cease, or back end, we spend more than 75% of our fourth dimension reading code written by others. That task can exist such a demanding job.

That being said, the ability to read others' lawmaking efficiently i s one of the skills that could make ane's chore in software technology much more than pleasant. Unfortunately, it is too a skill that is widely overlooked by schools, bootcamps, and companies. Information technology is one of those skills that everyone assumes you know, or be skilful at, just because you know how to write code.

The matter about writing code is, everyone has their own coding style. Reading code is not like reading a novel or a story; it's not but about reading instructions on the screen. Instead, when yous read code written by someone else, you're not only reading their code. You're trying to get into their thoughts process and what they were thinking when they wrote that code.

Needless to say, that is an extremely challenging chore. Only, it's a task that you can make exponentially easier. In this article, I will walk yous through my 4 steps process of reading and understanding other people's lawmaking.

To explain the different steps, I will go through a code I wrote for a spider web scraping tutorial.

Pace #ane: Run the code and see what it does

Whenever you get a code that you demand to read and empathise, the outset thing — and nearly apparent, I may argue — to exercise is to run the lawmaking and see what information technology does. What does it take as inputs? What are the outputs?

And then, let'south become ahead and run the code in a higher place and explore the results.

Image past the Author (The lawmaking's results screenshot)

Not all codes will event in a nautical chart; some codes' output will be a text output. Regardless of the output blazon, nosotros can explore it to guess — if y'all don't already know — the full general idea of what the code was written to do.

However, this might not give yous a lot of details most the details of the code, or if this code was a function of a bigger project, you might non know how information technology all connects, but yous will learn how to build it and run it. Likewise, you will get to know about the libraries it uses and the frameworks it depends on.

Nevertheless, running the code will requite yous the information you need to understand it better, and to make sure you got every dependency, you demand to kickoff working and expanding it.

Step #2: Find the main office or the beginning betoken

Now that we know what the code does and what the output is/are, we can starting time looking deeper into its details. To exercise that, we need to pinpoint the start of the lawmaking. If you're using a programming language with a must main function, like C, C++, or Java, start from there and walk your way through to the other functions.

If you're using Python, nevertheless, non all codes volition accept a main function, but you can apply the indentations to know where the code starts. For example, in the code above, nosotros accept multiple functions, and then the starting point of the code is on line lxxx .

And then, nosotros can start going through the comments first — if at that place is whatsoever — and go through the entire main department of the code without going into the details of the subfunctions.

Going through the principal function gives you the general flow of the lawmaking, what each subfunction does, not how they work, just what they do.

Pace #3: Run the lawmaking on debugging manner

Once you're washed carefully reading the main role of the code, yous may find it useful to run the code in debugging way. The reason for that is, when you run code in the debugger, it allows you to observe how your code interacts with the retentiveness.

It will show yous how each variable changes with every step in the lawmaking. Doing and so will give you a more in-depth agreement of the inner functionality of the code and its different functions.

Once you lot see how each variable in the lawmaking changes with every line, you lot tin get-go calculation your own comments in the code, explaining to yourself what every line of the code does.

Step #4: Build a mindmap of the connections between different parts of the code

One matter I found to aid tremendously is to build a mindmap of the code connections while I am running it in the debugger mode. The debugger mode shows yous a clear connexion between the different lawmaking items.

Start with the name of the code file in the center of your mindmap and and so branch out with the different functions and how they connect. Try ti encourage the variables in the code into the mindmap likewise, maybe not all of them, merely the ones that have the well-nigh event on the overall results.

Moreover, try to include the inputs and outputs of the lawmaking likewise as their types or expected types. Here'due south the mindmap for the code in a higher place.

Image by the author (made using Mindmeister) A mindmap of the lawmaking above

Building the mindmap will salve you and so much time whenever you collaborate with this codebase. It will assist yous know the connection in case you want to add together or remove whatsoever parts of the code.

Takeaway

Reading code written by other developers can exist such a challenging task; you demand to empathize their logic, their manner, and their specific choices. I have read so many codes written by programmers of unlike levels and ages. Having experienced that, I came with my own 4 steps process to ease up reading, exploring, and agreement codes written by basically someone who is not me.

This iv step process is simple and will save you lot a lot of time and try; all you need to do is:

  1. Run the code and explore the results.
  2. Notice the master function or the start bespeak of the code.
  3. Run the code nether the debugger and fully understand the code's mechanics.
  4. Build a mindmap of the connections between the unlike code elements and use it at whatever fourth dimension you collaborate with the code.

I hope you lot find these steps useful in saving you much time and effort in your side by side code exploration run a risk.

"Indeed, the ratio of fourth dimension spent reading versus writing is well over 10 to 1. We are constantly reading old code every bit role of the try to write new code. …[Therefore,] making it easy to read makes it easier to write."

― Robert C. Martin,

mcginncoutubts.blogspot.com

Source: https://towardsdatascience.com/the-most-efficient-way-to-read-code-written-by-someone-else-cb1a05102b76

0 Response to "How Many Software Developers Know How Read Code"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel