I really like the concept of coming to terms with an author as defined in the book How to Read a Book. In addition to books, this also applies to reading code, as in code reviews, refactoring or fixing code, and reading open source code.
You cannot truly understand a book or code until you have come to terms with the author. Words have ambiguous meanings, so you must identify the important words and also come to understand the meaning intended by the author.
Its risky to fix a bug or refactor code if you have not yet come to terms with the code and its author. You are likely to create new bugs due to misunderstanding the code you are changing.
With a book the author’s intent is all that matters in coming to terms. The author may do a poor job at communicating their intent, but once you have come to terms you understand the information or knowledge they are conveying.
With code, since a computer will interpret it exactly one way, there are two aspects in coming to terms with code. You must come to terms with the author’s intent, and you must also come to terms with what the code actually does.
It is possible that when executed by a computer, the code does something different than the author intended. The author of the code may have failed to come to terms with the language or library they are building their code upon.
Even when the executed code and the author’s intent match, you must come to terms with both prior to making any changes. There may be implicit assumptions in the author’s intent that are only clear when you come to terms with both.
This is why naming is so important when writing code. Naming conveys intent, and makes it easier for future readers of the code (including your future self) to come to terms with the code and the intent.
Understanding the domain of the code can help in coming to terms. This provides context and helps to narrow down the meaning of the terms being used within the code.
If you are having trouble understanding a piece of code, search for the parts that you do understand. Use the parts that you do understand as context for the parts still to be interpreted.