Working Effectively with Legacy Code
by Michael Feathers 2020-05-14 20:53:30
image1
Preface Do you remember the first program you wrote? I remember mine. It was a little graphics program I wrote on an early PC. I started programming later than most of my friends. Sure, I d seen computers when I was a kid. I remember being really imp... Read more
Preface Do you remember the first program you wrote? I remember mine. It was a little graphics program I wrote on an early PC. I started programming later than most of my friends. Sure, I d seen computers when I was a kid. I remember being really impressed by a minicomputer I once saw in an office, but for years I never had a chance to even sit at a computer. Later, when I was a teenager, some friends of mine bought a couple of the first TRS-80s. I was interested, but I was actually a bit apprehensive, too. I knew that if I started to play with computers, I d get sucked into it. It just looked too cool. I don t know why I knew myself so well, but I held back. Later, in college, a roommate of mine had a computer, and I bought a C compiler so that I could teach myself programming. Then it began. I stayed up night after night trying things out, poring through the source code of the emacs editor that came with the compiler. It was addictive, it was challenging, and I loved it. I hope you ve had experiences like thismdjust the raw joy of making things work on a computer. Nearly every programmer I ask has. That joy is part of what got us into this work, but where is it day to day? A few years ago, I gave my friend Erik Meade a call after I d finished work one night. I knew that Erik had just started a consulting gig with a new team, so I asked him, "How are they doing?" He said, "They re writing legacy code, man." That was one of the few times in my life when I was sucker-punched by a coworker s statement. I felt it right in my gut. Erik had given words to the precise feeling that I often get when I visit teams for the first time. They are trying very hard, but at the end of the day, because of schedule pressure, the weight of history, or a lack of any better code to compare their efforts to, many people are writing legacy code. What is legacy code? I ve used the term without defining it. Let s look at the strict definition: Legacy code is code that we ve gotten from someone else. Maybe our company acquired code from another company; maybe people on the original team moved on to other projects. Legacy code is somebody else s code. But in programmer-speak, the term means much more than that. The term legacy codehas taken on more shades of meaning and more weight over time. What do you think about when you hear the term legacy code? If you are at all like me, you think of tangled, unintelligible structure, code that you have to change but don t really understand. You think of sleepless nights trying to add in features that should be easy to add, and you think of demoralization, the sense that everyone on the team is so sick of a code base that it seems beyond care, the sort of code that you just wish would die. Part of you feels bad for even thinking about making it better. It seems unworthy of your efforts. That definition of legacy code has nothing to do with who wrote it. Code can degrade in many ways, and many of them have nothing to do with whether the code came from another team. In the industry, legacy codeis often used as a slang term for difficult-to-change code that we don t understand. But over years of working with teams, helping them get past serious code problems, I ve arrived at a different definition. To me, legacy codeis simply code without tests. I ve gotten some grief for this definition. What do tests have to do with whether code is bad? To me, the answer is straightforward, and it is a point that I elaborate throughout the book: Code without tests is bad code. It doesn t matter how well written it is; it doesn t matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don t know if our code is getting better or worse. You might think that this is severe. What about clean code? If a code base is very clean and well structured, isn t that enough? Well, make no mistake. I love clean code. I love it more than most people I know, but while clean code is good, it s not enough. Teams take serious chances when they try to make large changes without tests. It is like doing aerial gymnastics without a net. It requires incredible skill and a clear understanding of what can happen at every step. Knowing precisely what will happen if you change a couple of variables is often like knowing whether another gymnast is going to catch your arms after you come out of a somersault. If you are on a team with code that clear, you are in a better position than most programmers. In my work, I ve noticed that teams with that degree of clarity in all of their code are rare. They seem like a statistical anomaly. And, you know what? If they don t have supporting tests, their code changes still appear to be slower than those of teams that do. Yes, teams do get better and start to write clearer code, but it takes a long time for older code to get clearer. In many cases, it will never happen completel Less
  • File size
  • Print pages
  • Publisher
  • Publication date
  • Language
  • ISBN
  • 9.1x6.9x1inches
  • 464
  • Pearson
  • September 1, 2004
  • eng
  • 9780132931748
MICHAEL C. FEATHERS works for Object Mentor, Inc., one of the world's top providers of mentoring, skill development, knowledge transfer, and leadership services in software development. He currently p...
Compare Prices
image
Paperback
Available Discount
12 % OFF
12% off Academic Book Titles (ebooks.com)

See More Details

Description: Back to School Promotion at eBooks.com. 12% off Academic book titles. Landing page is on our academics category page. Static image.

10 % OFF
Save 10% OFF on Student Text Books (ebooks.com)

See More Details

Description: Purchase textbooks at student discounts!

20 % OFF
20% Off on selected Categories

See More Details

Description: 20% Off these Categories- Body Mind & Spirit, Family & Relationships, Foreign Language Study, History, Sports & Recreation. Offer Lasts all through January.

Related Books