2

Read code more

 2 years ago
source link: https://alexgaynor.net/2019/jul/11/read-code-more/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Read code more

Thu, Jul 11, 2019

As software engineers, we overwhelmingly focus on the skill of writing code. This is clear from how we teach new programmers, how we interview software engineers for jobs, how we encourage engineers to improve their craft, and the kinds of talks you find at conferences. The lack of emphasis on developing code reading as a skill does people a disservice. Reading code is a distinct skill and practicing software engineers should work to improve this skill.

Reading code shows up in many different tasks for a software engineer:

  • Code review: Perhaps the most explicit manifestation of needing to read code as part of your job.
  • Debugging: Debugging is all about identifying the delta between your expectations about how a system works and how it actually works. Being better at reading code can dramatically reduce how long it takes to understand what a system does.
  • Security reviews: These are not a part of every engineer’s responsibility, but ensuring code matches the intent when it was written and does not have vulnerabilities relies on your ability to read code well.
  • Writing code: Writing code itself is easier when you’re good at reading code. Whether it’s identifying undocumented behavior of a third-party library you rely on, or trying to understand how to combine internal APIs, being better at reading code makes writing code easier.

Despite the importance of being able to read code well, we don’t do nearly enough to value it in our industry. Fortunately, there are many things you can do to improve your own code reading abilities:

  • Stop reading the docs. When you’d normally go to the documentation for a third-party library, read the source code instead. Doing this well gives you regular practice as part of your flow in reading foreign code bases quickly.
  • Master your tools. I strongly recommend getting comfortable with a tool like rg or livegrep, which can be invaluable tools in reading code more quickly.
  • Read before you write. When learning a new programming language (really any major tool/framework, but particularly languages) read a non-trivial amount of code in it before you write your first programs in it. Forcing yourself to have an analytical understanding of its behavior, instead of trial-and-error with a compiler/interpreter will dramatically improve your code reading skills.

Reading code is an important part of the job of a software engineer, but far too few people work on improving at it the way they do at writing code. Hopefully I’ve convinced you that practicing reading code is a valuable use of your time, and given you some tools to do so.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK