Chapter 70. Read Code
WE PROGRAMMERS ARE WEIRD CREATURES. We love writing code. But when it comes to reading it, we usually shy away. After all, writing code is so much more fun, and reading code is hardâsometimes almost impossible. Reading other peopleâs code is particularly hard. Not necessarily because other peopleâs code is bad, but because they probably think and solve problems in a different way than you. But did you ever consider that reading someone elseâs code could improve your own?
The next time you read some code, stop and think for a moment. Is the code easy or hard to read? If it is hard to read, why is that? Is the formatting poor? Is naming inconsistent or illogical? Are several concerns mixed together in the same piece of code? Perhaps the choice of language prohibits the code from being readable. Try to learn from other peopleâs mistakes, so that your code wonât contain the same ones. You may receive a few surprises. For example, dependency-breaking techniques may be good for low coupling, but they can sometimes also make code harder to read. And what some people call elegant code, others call unreadable.
If the code is easy to read, stop to see if there is something useful you can learn from it. Maybe thereâs a design pattern in use that you donât know about, or had previously struggled to implement. Perhaps the methods are shorter and ...
Get 97 Things Every Programmer Should Know now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.