Rewriting Code for Better Understanding (Coding Horror)
- What I cannot create, I do not understand. [Richard Feynman]
- "What I do not create, I do not understand."[Chris]
- "It's easier to understand 600 tables than 100,000 lines of code." [PaulC on comp.databases.theory/2005]
- Create a new project with blocks of code copied from old code. Refactor to reduce "old code smell"
- Start refactoring by adding small tests to better understand code and act as regression tests.
- Just scan through huge amounts of code till it starts making sense - "understand by constant exposure".
- Create a text file to capture your understanding - briefly describe how the component works, realtions to other components, what it persists, its states, and source browsing/debugging tips you found useful.
- Manually reformat a copy of the code - white space, and indented as per your personal style.
- Working Effectively with Legacy Code
- Object Oriented Reengineering Patterns
- Refactoring: Improving the Design of Existing Code
Noble Art of Maintainance Programming (Coding Horror)
- The Daily WTF is "a very enjoyable web site where people relate short stories about the crazy code they've worked with, usually with examples." (http://thedailywtf.com/)
- On taking over foreign code
Tips for Increasing Code Readability (StackOverFlow)
- Top-Down: Look for indicative class names and modules
- Bottom-Up: Navigate to a feature implementation and browse/annotate to build standalone chunks of knowledge.
- Use whitespace for increasing code-readability
- Scan the system packages and classes looking for entities you can identify.
- Code Reading: The Open Source Perspective
- Code Quality: The Open Source Perspective
- Implementation Patterns by Kent Beck
Some tips from StackOverflow
- Debug to understand basic data/control flows in source.
- Add Logging/print statements to source to understand basic data/control flows in source.
- Write unit tests for the code
- Annotate a printout of the source.
- Do code walk-through with someone knows how the code works.
- Code review
- Fixing bugs in source slowly exposes you to small parts of the whole source.
- Going through bug histories will give you background info esp. on the "smelly parts" of source.
- Refactor code to improve code quality and testability esp. regression tests.
- Add annotations to a copy of the code as you push the edges of your ignorance.
- Reverse engineer source to design document (needs heavy manual editing)
- Get familiar with language idioms to quickly understand source code.
- Make a paper Diagram of the application to understand flow and dependencies
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.