検索 - みる会図書館

検索対象: Working Effectively with Legacy Code

Working Effectively with Legacy Codeから 386件ヒットしました。

Working Effectively with Legacy Code


Working Effectively with Legacy Code

Working Effectively with Legacy Code


Working Effectively with Legacy C0de Michael C. Feathers PRENTICE HALL PTR Prentice Hall Professional Technical Reference Upper Saddle River, NJ 07458 www.phptr.com

Working Effectively with Legacy Code


Software Engineering Get mo out Of yourlegacy systems: more performance, functionality, reliability, and manageability 区 your code easy tO change? Can you get nearly instantaneous feedback when you do change it? DO you understand it? げ the answer tO any Of these questions is no, you have legacy code, and it is draining time and money away from your development e 幵 0 . 旧 this bOOk, Michael Feathers offers start-to-finish strategies for working more effectively with large, untested legacy code bases. This book draws on material MichaeIcreated fo 「 his renowned Object Mentor seminars: techniques Michael has used in mentoring to help hundreds Of developers, technical managers, and testers bring theirlegacy systems under control. The topics covered include Understanding the mechanics of software change: adding features, fixing bugs, improving design, optimizing performance Getting legacy code intO a test harness Writing tests that protect you against introducing new problems Techniques that can be used with anylanguage 0 「 platform—with examples in Java, C + + , C, and C# Accurately identifying where code changes need to be made Coping with legacy systems that aren't object-oriented HandIing applications that don't seem tO have any structure This book a 区 0 includes a catalog of twenty-four dependency-breaking techniques that help you work with program elements in isolation and make safer changes. MICHAEL (. FEATHERS works fo 「 Object Mentor, 旧 (. , one of the world's top providers of mentoring, skill development, knowledge transfer, and leadership services in software development. He currently provides worldwide training and mentoring in Test-Driven DeveIopment (TDD) ′ Refactoring, 00 Design,Java, C#, C + + , and Extreme Programming (XP). Michael is the originalauthor 0f CppUnit, a C + + po は Of the JUnit testing framework, and FitCpp, a C + + po 0f the FIT integrated-testing framework. A member of ACM and IEEE ′ he has chaired CodeFest at three OOPSLA conferences. CoverImage: CharIes Babbage/ Time & Life Pictures / Getty lmages, lnc. www.prenhallprofessional.com ・ ・ P R E NTI ロ E H A L L ・ ・ P EA R S ロ N E D 凵 ロ AT ー ロ N 旧 BN -13 : 978-0-13-117705-5 旧 BN -10 : 0-13-117705-2 9 7 8 0 1 3 1 1 7 7 0 5 5 $ 54.99 US $ 68.99 CANADA 5 5 4 9 9

Working Effectively with Legacy Code


EXTRACT METHOD refactoring t001 , it is even easier. AII you have tO dO is select a portron of a method and make a menu selection. The t001 checks to see if that code can be extracted as a method and prompts you for the new method's name. E ェ な 4 は M 舫 0d is a core technique for working with legacy code. You can use it tO extract duplication, separate responsibilities, and break down long methods. 419 Extract Method

Working Effectively with Legacy Code


20 The Legacy COde Change Algorithm WORKING WITH FEEDBACK Make Changes and Refactor I advocate using test-driven development (TDD) t0 add features in legacy code. There is a description of TDD and some Other feature addition techniques ln Chapter 8 , Ho ル DO ー Add 4 4 After making changes in legacy code, we Often are better versed with its problems, and the tests we've written tO add fea- tures Often give us some cover tO dO some refactoring. Chapter 20 , T わ な Class な 肪 0 Big 4 〃 d ー Do 〃 7 Wa 厩 〃 Get ハ 〃 ア Bigger; Chapter 22 , ー Need C わ 4 〃 g ビ 4 Mo 〃 催 M ビ 舫 od 4 〃 d ー C の 物 W s な ん な and Chapter 21 , l'm C わ 4 〃 g - ing 舫 立 川 ビ C0de All 〇 レ the P / 4 cover many 0f the techniques you can use tO start tO move your legacy COde toward better structure. Remember that the things I describe in these chapters are 、 'baby steps. ' ' They don't show you how to make your design ideal, clean, or pattern-enriched. Plenty 0f b00ks show how tO dO those things, and when you have the opportunity tO use those tech- niques, I encourage you tO dO SO. These chapters show you hOW tO make design better, where 。 。 better" is context dependent and Often simply a few steps 1 れ ore maintainable than the design was before. But don't discount this work. Often the simplest things, such as breaking down a large class just tO make it easier tO work with, can make a significant difference in applications, despite being somewhat mechanical. The Rest of This Book The rest of this book shows you how to make changes in legacy code. The next tWO chapters contaln some background material about three critical concepts ln legacy work: sensmg, separatlon, and seams.

Working Effectively with Legacy Code


VII CONTENTS Contents Foreword by Robert C. Martin. Preface lntroduction . PART I: The Mechanics of Change.. Chapter 1 : Changing Software . Four Reasons to Change Software Risky Change . Chapter 2 : Working with Feedback What ls Unit Testing? Higher-LeveI Testing . Test Coverings The Legacy Code Change AIgorithm Chapter 3 : Sensing and Separation . Faking Collaborators Chapter 4 : The Seam Model. A Huge Sheet of Text Seams Seam Types . Chapter 5 : TooIs. Automated Refactoring T001S Mock Objects . Unit-Testing Harnesses General Test Harnesses . ・ 1 1 っ 0 4 「 / 9- っ 4 4 4 8 1 っ 0 9 一 9- 0 っ 0 - ) - ) 「 / 8 っ 0 イ

Working Effectively with Legacy Code


The Legacy COde Change Algorithm ・ WORKING WITH FEEDBACK but it depends upon how much risk is involved. When errors are a big deal, and they usually are, it pays tO be conservative. When you break dependencies in legacy code, you Often have t0 suspend your sense of aesthetics a bit. Some dependencies break cleanly; others end up looking less than ideal from a design point 0f view. They are like the incision points ⅲ surgery: There might be a scar left ⅲ your code after your work' but everything beneath it can get better,. If you can cover code around the point where you broke dependencies lateg you can heal that scar, t00 ・ The Legacy Code Change Algorithm When you have to make a change in a legacy code base, here is an algorithm YOLI can use. 1. ldentify change points. 2. Find test points ・ 3. Break dependencies. 4.Write tests. 5. Make changes and refactor. The day-to-day goal in legacy code is t0 make changes, but not Just any changes. We want t0 make functional changes that deliver value while bringing more Of the system under test. At the end Of each programming episode, we should be able tO point not only tO code that provides some new feature, but alSO its tests. Over time, tested areas Of the COde base surface like islands rising out Of the ocean. work in these islands becomes much easier. Over time, the islands become large landmasses. Eventually, you'll be able t0 work in conti- nents Of test-covered COde. Let's 100k at each of these steps and how his book will help you with them. ldentify Change Points The places where you need t0 make your changes depend sensitively on your architecture. If you don't know your design well enough t0 feel that you are making changes in the right place, take a 100k at Chapter 16 , ー DO れ Under- stand the Co Ⅳ ビ 〃 E 〃 0 〃 g わ Change 〃 , and Chapter 17 , My A 々 々 4 〃 0 れ Has NO S な 〃 c ル 尾 .

Working Effectively with Legacy Code


VII CONTENTS Contents Foreword by Robert C. Martin. Preface lntroduction . PART I: The Mechanics of Change.. Chapter 1 : Changing Software . Four Reasons to Change Software Risky Change . Chapter 2 : Working with Feedback What ls Unit Testing? Higher-LeveI Testing . Test Coverings The Legacy Code Change AIgorithm Chapter 3 : Sensing and Separation . Faking Collaborators Chapter 4 : The Seam Model. A Huge Sheet of Text Seams Seam Types . Chapter 5 : TooIs. Automated Refactoring T001S Mock Objects . Unit-Testing Harnesses General Test Harnesses . ・ 1 1 っ 0 4 「 / 9- っ 4 4 4 8 1 っ 0 9 一 9- 0 っ 0 - ) - ) 「 / 8 っ 0 イ

Working Effectively with Legacy Code


XVI PREFACE What do you think about when you hear the term g40 じ 0d2 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 t0 add in features that should be easy t0 add, and you think 0f 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. lt seems unworthy Of your efforts. That definition of legacy code has nothing t0 d0 with who wrote it. Code can degrade in many ways, and many 0f them have nothing t0 d0 with whether the COde came from another team. ln the industry, g40 じ 0 施 is 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, l've arrived at a different definition. TO me, ル g40 code is simply code without tests. l'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. lt doesn't matter hOW well written it is; it doesn't mat- ter 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. lt is like dOing aerial gymnastics without a net. lt requires incredible skill and a clear understanding 0f what can happen at every step. Knowing precisely what will happen if you change a couple 0f 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 ln a better posltion than most programmers. ln 1 れ y work, l've noticed that teams with that degree 0f clarity in all 0f 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 t0 be slower than those 0f teams that d0. Yes, teams dO get better and start tO write clearer code, but it takes a long time for Older COde tO get clearer. ln many cases, it will never happen com- pletely. Because 0f this, I have no problem defining legacy code as code without tests. lt is a good working definition, and it points tO a solution. l've been talking about tests quite a bit SO far, but this bOOk iS not about test- ing. This b00k is about being able t0 confidently make changes in any code

Working Effectively with Legacy Code


Chapter 15 My Application ls AII API Calls Build, buy, or borrow. lt's a choice we all have to make when we develop soft- 199 or add methods to classes to make them available to different parts of the code. we could rename interfaces, classes, and methods tO make things clearer for us, that API-intensive systems are difficult is that we don't own the API. If we did, thing that would've been a hint at a design JLISt isn't there. The second reason how t0 make the structure better because all you can see are the API calls. Any- grown systems, many respects. The first reason is that it is Often hard tO see Systems that are littered with library calls are harder t0 deal with than home- are uncertain; we didn't write all Of the COde, but we have tO maintarn it. right back in the central dilemma of the legacy system programmer. Changes every time we change something tO make sure that it still works, and we are embedded in a patchwork of untestable code. We have to run the application might still be able to see areas of code that don't touch an API, but they are grows and grows, and things aren't quite as simple anymore. Over time, we Many legacy proJects have started from those humble beginnings. The code there, and our code is simple. lt's really simple. What can go wrong? we aren't really doing anything significant; we're just calling a method here and The immediate temptation is to say that we don't really need tests. After all, in code like that? nothing but repeated calls t0 someone else's library. How do we make changes left with another problem. We end up with applications that 100k like they are is tO use. And, when we dO finally decide tO use someone else's COde, we're Often easily. ・ We have tO know how stable it is, whether it is sufficient, and how easy it different things tO consider when choosing tO integrate code we can't change that come bundled with our platform (J2EE, . NET, and so on ). There are many some open source, or even JLISt using significant ChunkS Of C()de from libraries can save ourselves some time and effort by buying some vendor library, using ware. Many times when we re working on an application, we suspect that we My Application AII API Calls