Working Effectively with Legacy Code
Rate it:
Open Preview
2%
Flag icon
Designs that cannot tolerate changing requirements are poor designs to begin with.
2%
Flag icon
nearly every system ever produced suffers from slow, debilitating rot.
2%
Flag icon
Prevention is imperfect. Even the most disciplined development team, knowing the best principles, using the best patterns, and following the best practices will create messes from time to time. The rot still accumulates.
2%
Flag icon
It’s not enough to try to prevent the rot—you have to be able to reverse it.
2%
Flag icon
reversing rot is not easy, and it’s not quick.
2%
Flag icon
this book describes a set of disciplines, concepts, and attitudes that you will carry with you for the rest of your career and that will help you to turn systems that gradually degrade into systems that gradually improve.
4%
Flag icon
There is a big difference between adding new behavior and changing old behavior.
4%
Flag icon
Behavior is the most important thing about software. It is what users depend on. Users like it when we add behavior (provided it is what they really wanted), but if we change or remove behavior they depend on (introduce bugs), they stop trusting us.
4%
Flag icon
Adding a method doesn’t change behavior unless the method is called somehow.
4%
Flag icon
It seems nearly impossible to add behavior without changing it to some degree.
4%
Flag icon
One of the main reasons why many programmers don’t attempt to improve design often is because it is relatively easy to lose behavior or create bad behavior in the process of doing it.
4%
Flag icon
The act of improving design without changing its behavior is called refactoring.
4%
Flag icon
write tests to make sure that existing behavior doesn’t change
5%
Flag icon
The key thing about refactoring from a change point of view is that there aren’t supposed to be any functional changes when you refactor
5%
Flag icon
Optimization is like refactoring, but when we do it, we have a different goal.
5%
Flag icon
In optimization, the “something else” is some resource used by the program, usually time or memory.
5%
Flag icon
In all four cases, we want to change some functionality, some behavior, but we want to preserve much more
5%
Flag icon
We have to figure out how to preserve the rest of the behavior.
5%
Flag icon
we often don’t know how much of that behavior is at risk when we make our changes.
5%
Flag icon
The difference between good systems and bad ones is that, in the good ones, you feel pretty calm after you’ve done that learning, and you are confident in the change you are about to make. In poorly structured code, the move from figuring things out to making changes feels like jumping off a cliff to avoid a tiger. You hesitate and hesitate. “Am I ready to do it? Well, I guess I have to.”
5%
Flag icon
Often they aren’t aware of how much fear they have until they learn better techniques and the fear starts to fade away.
5%
Flag icon
Edit and Pray is pretty much the industry standard.
5%
Flag icon
When you make your changes, you are hoping and praying that you’ll get them right, and you take extra time when you are done to make sure that you did.
5%
Flag icon
The idea behind it is that it is possible to work with a safety net when we change software.
5%
Flag icon
When we have a good set of tests around a piece of code, we can make changes and find out very quickly whether the effects were good or bad.
5%
Flag icon
Traditionally, tests are written and executed after development.
5%
Flag icon
they act as a software vise.
6%
Flag icon
regression testing has traditionally been seen as an application-level testing style.
6%
Flag icon
The tests won’t catch everything,
6%
Flag icon
After every little change that we make, we run that little suite of unit tests.
6%
Flag icon
Unit testing is one of the most important components in legacy code work.
6%
Flag icon
Testing in isolation is an important part of the definition of a unit test,
6%
Flag icon
Here are qualities of good unit tests: 1. They run fast. 2. They help us localize problems.
6%
Flag icon
A test is not a unit test if: 1. It talks to a database. 2. It communicates across a network. 3. It touches the file system. 4. You have to do special things to your environment (such as editing configuration files) to run it.
7%
Flag icon
Tests that do these things aren’t bad. Often they are worth writing, and you generally will write them in unit test harnesses.
7%
Flag icon
However, it is important to be able to separate them from true unit tests so that you can keep a set of tests that you can ...
This highlight has been truncated due to consecutive passage length restrictions.