I could simplify and say, “with experience”, but that’s not the whole story.
Understanding code requires understanding the language, the paradigm, the domain, and the owners. Let’s consider each of these:
- Language - The programming language consists of syntax, libraries, and best practices. The more you’ve worked in a language the easier it gets to understand other code. As you excel in one language though you’ll find you slowly gain the ability to read other languages with less work.
- Paradigm - Above the language are the various programming paradigms used in the software. If it’s a paradigm you’ve not seen before it will be harder to understand. Fortunately there are a limited number of fundamental approaches, so you can learn them all — though there are an unlimited number of variations, but those you can glean from the project itself.
- Domain - Different domains have different approaches to how software is used and written. Video games are quite different than business apps and system libraries. Reading code within a domain you know is obviously easier than one you don’t. In time, as you learn more domains you’ll find it easier to pick up on new ones quickly.
- Owners - This is the human element to the understanding. Projects have a lot of different managerial approaches and personality types, these reflect heavily on how the code looks. As you work with more people you’ll get a better insight into why some decisions are made, and how the software is structured.
The key to understanding code is in variety. Not the amount of experience, but the breadth of your experience, will determine how easy it is to grasp new project.
Taken from my answer to this question at Quora
Top comments (3)
I'm reminded of Brian Kernighan's note about code cleverness:
I think the same concept applies to reading code. Don't just make it possible to read, make it easy to read. Your colleagues and your future self will thank you.
Some time ago I read this quote:
"When I was coding, only God and me knew what I was creating. Now, only God knows..." So, how do you expect to someone will understand somebody's code?
In fact, you'll need experience to make code easy to read. The same applies for life: The easier you say something, the easier will be to understand.
Brief and informative 🙏 answers the question I’ve been thinking about lately