top of page
Search
rupmatchvanningpas

Working Effectively with Legacy Code: Tools and Methods for Sensing and Separation



This book provides programmers with the ability to cost effectively handlecommon legacy code problems without having to go through the hugelyexpensive task of rewriting all existing code. It describes a series of practicalstrategies that developers can employ to bring their existing softwareapplications under control. The author provides useful guidance about how touse these strategies when refactoring or making functional changes to codebases. One of the book's key points is that it teaches developers to write teststhat can be used to make sure they are not unintentionally changing theapplication as they optimize it. Examples are provided in Java, C++, and Csharp,and the book assumes that the reader has some knowledge of UMLnotation. Strategies using UML and code in C++ and Java primarily whilelanguage independent advice will be delivered in side bars and appendices forlanguage specific users.


Legacy software is very hard to modify and extend, as it often relies on obsolete software and hardware, lacks testing, and may have no developers familiar with its complexities.This book gives us hope that we can use targeted, incremental unit testing and refactoring to turn legacy software into better tested, understood, and extensible software while implementing anddelivering new functionality at the same time.




Working Effectively with Legacy Code



Step 1 defines the targeted subset of legacy code that must have tests, which depend on what needs to change, what can be sensed, and where dependencies can be broken.After unit tests that cover the targeted code have been implemented in Step 2, the code should have close to 100% test coverage.Without full coverage, it is difficult to know if existing behavior is preserved.Any refactoring in Step 4 is safe to perform once the targeted code is sufficiently covered with tests.Refactoring is critical to improve the clarity and maintainability of the code.WARNING: The refactoring must not extend outside code that is sufficiently covered by tests!


Identify change points: Find out where in the legacy code you want to make a change or add new code.Targeted changes should be done in small iterations, so this should hopefully just be a single function or a few functions and hopefully only a single class if possible.


Cover legacy code with unit tests: If you have the specification for how the targeted legacy code is supposed to work, then write tests to that specification.Otherwise, write "Characterization Tests" to see what the code actually does under different input scenarios.NOTE: When the official specification differs from the actual observed behavior of the code, go with the actual behavior because that is what users actually depend on.(Differences between specified/desired behavior and actual behavior can be addressed in later iterations if one desires breaking backward compatibility.)


The Legacy Code Change Algorithm is applied in many small iterations over and over again as pieces of the legacy software are changed.Over time, these small incremental refactorings can result in significant improvements to the quality and sustainability of the software and can even perform major (beneficial) architectural changes.In fact, at some point, the software may have improved to the point where there is enough strong testing that it is no longer considered legacy code!


This book is packed with practical examples that show nearly every trick there is for refactoring nasty code to break dependencies and getting code into a unit test harness.After reading this book, you should be convinced of the need for unit testing and TDD.


This book provides programmers with the ability to cost effectively handlecommon legacy code problems without having to go through the hugelyexpensive task of rewriting all existing code. It describes a series of practicalstrategies that developers can employ to bring their existing softwareapplications under control. The author provides useful guidance about how touse these strategies when refactoring or making functional changes to codebases. One of the book's key points is that it teaches developers to write teststhat can be used to make sure they are not unintentionally changing theapplication as they optimize it. Examples are provided in Java, C++, and Csharp, and the book assumes that the reader has some knowledge of UMLnotation. Strategies using UML and code in C++ and Java primarily whilelanguage independent advice will be delivered in side bars and appendices forlanguage specific users. From inside the book if (window['_OC_autoDir']) _OC_autoDir('search_form_input'); What people are saying - Write a reviewUser ratings5 stars104 stars13 stars12 stars01 star0Reviews aren't verified, but Google checks for and removes fake content when it's identifiedLibraryThing ReviewUser Review - thegreatape - LibraryThingIf you write software with other people, for fun or money, you should read this book. It's the best writing on how to get messy, awful software on the road to sanity, step by incremental step. Read full review


You can also use suppressions to create exceptions for your codebase. So, you can essentially dismiss violations in it. You might set your suppressions on specific rules or violations within a particular category.


This book comes highly recommended in programmer circles, but for some reason ittook me a long while to finally get to read it. This colors my impression of itsomewhat, because it's been many years since I had to deal with thekind of projects and code this book describes.


Have you ever had to deal with real legacy code? What do I mean by real?OK, let's recap. Real legacy code is frequently called "spaghetti code"; anothercommon nickname is the big ball of mud pattern. It's code that lackssensible structure and - worst of all - lacks tests. Classes may have had somesingle responsibility a long time ago, but they no longer do. Years ofmaintenance and under-pressure bug fixes left them leaking abstractions left andright, sending ugly dependency tentacles into each other. Touch one characterand the whole house of cards may fall down on you. Unit tests are unheard of.


To reiterate the conclusion I already presented earlier - get this book if youhave to work with old balls of mud; it will be effort well spent. Otherwise,if you're working on one of those new-age continuously integrated codebases witha 2/1 test to code ratio, feel free to skip it.


In my experience, developers who learn and apply dependency injection experience an epiphany in testability. Their code becomes more durable, delaying the time between original authorship and becoming legacy.


I find that the payoff period for adding tests to code is extremely short, on the order of hours. That is to say the time required to add tests is made up for with increased productivity within a matter of hours.


Programmers get excited about refactoring or adding new code and its tempting to start changing a bunch of things. When we change multiple things, it becomes harder to tell what changes are working vs. not.


Is your code easy to change? Can you get nearly instantaneous feedback when you do change it? Do you understand it? If the answer to any of these questions is no, you have legacy code, and it is draining time and money away from your development efforts.


In this book, Michael Feathers offers start-to-finish strategies for working more effectively with large, untested legacy code bases. This book draws on material Michael created for his renowned Object Mentor seminars: techniques Michael has used in mentoring to help hundreds of developers, technical managers, and testers bring their legacy systems under control.


When we talk about legacy code, your first thought might be of old, obsolete code. Yes, it may be written for operating systems that are no longer supported. However, legacy code means code which is:


Sometimes legacy code exists for a reason. It may point to a team with a crazy high turnover, making little effort in their documentation. Or a team of more experienced developers who are comfortable with older languages. A company may keep legacy code due to competitive advantages over other businesses. They may fear that rewriting code may introduce new bugs or remove hidden functionality.


However, legacy code may also operate in a black box that is less accessible to a broader development community, meaning insufficient quality improvement, security, and maintainability. When people leave, it may be hard to find new developers appropriately skilled to work with it. As time goes on, the code may struggle to work with new and emerging apps and hardware. The company risks falling behind and is drowning in technical debt. Do you hate legacy code?


Specifically, their pain points are many, with spaghetti code and fear of breaking something the most common concerns followed by the frustration of sticking to depreciated technology. This survey offers an insight into the complexities of dealing with legacy code and explains some of the reasons developers prioritise other work. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comentários


bottom of page