Saturday, February 04, 2006

Working Effectively With Legacy Code (notes)

Notes from Michael C. Feathers book.

"Code without test is bad code. It doesn't matter how ell written it is; it doesn't matter how pretty or object oriented or well encapsulated it is. With tests, we can change the behaviour of our code quickly and verifiably. Without them, we really don't know if your code is getting better o worse."

...changes in a system: "Edit and Pray", "Cover and Modify"

A Seam is a place where you can alter behaviour in your program without editing in that place. Every seam has an enabling point, a place where you can make the decision to you one behaviour or another.

# Separate the new code (change) from the old code. Contain the change code in:
- a Sprout Method. Can also be static (static methods viewed as staging)
- a Sproud Class. The source Class, cannot be easily tested, so we isolated our change in another class, where we can test it.

- Wrap Method: Rename the old method and make it private/protected. The new method wraps the old functionality with the new functionality.
- Wrap Class: Extract Implementer/Extract Interface.

"Good design is testable, and design that isn't testable is bad."
"When we depend directly on libraries that are out of our control, we are just asking for trouble."

"There is no decent place to sense what this code does."

"Command/query separation: a command should be a query or a command, but not both. A command is a method that can modify the state of the object but that doesn't return a value. A query is a method returns a value but that does not modify the object"

"Programming is the art of doing one thing at a time"
Pair Programming: "It is a remarkably good way to increase quality and spread knowledge around a team"
"Let's face it, working in legacy code is surgery, and doctors never operate alone."

No comments: