Search code examples
javadesign-patterns

What should I take note of when reading others' source code?


If you read other people's source code, how do you approach the code? What patterns are you looking for (datatypes, loops, use of control flow, ...)? How long can you read other people's code without getting bored? What is the most exciting patterns that you have discovered so far?


Solution

  • Aside from the obvious "work from the top down" general approach, it depends on why I'm reading it: code review, trying to understand a bit of avaialable code to adapt for my own use, trying to learn a new technique, etc.

    It also depends heavily on the language. If it is an OOPL, I'll probably do something like this:

    1. Look first for the primary class relationships and try to understand the primary responsibility of each class.
    2. Look at the interactions between classes to see how they collaborate.
    3. Look at the interfaces of the key classes to see what "services" they offer their collaborators.
    4. Look inside the non-trivial methods if it's important to understand how they are working instead of what they are responsible for.