Technical debt là gì

Technical debt – tạm dịch là “Khoản nợ kỹ thuật” được dùng các vào Software Engineering. Theo Henrik Kniberg, hầu hết số tiền nợ kỹ thuật là bất cứ vật dụng gì vào việc viết mã khiến các bạn lắng dịu về dài lâu. Ví dụ như thể mã khó khăn phát âm, thiếu thốn (hoặc ko có) kiểm test tự động, mã đụng hàng, hoặc sự link nhùng nhằng thân lớp, mô-đun… (Think of technical debt as anything about your code that slows you down over the long term. Hard-to-read code, lachồng of kiểm tra automation, duplication, tangled dependencies, etc. Henrik Kniberg).

Bạn đang xem: Technical debt là gì

10 bí kíp để startup và FinTech startup thành công bất chợt phá
Cách thay đổi một MarTech Developer vào 2021


TDD sẽ cạnh tranh, TDD đến legacy system còn cạnh tranh gấp bội. Bài viết tiếp sau đây của Mark Levison bàn về việc đa số vụ việc chạm chán nên khi vận dụng TDD vào Legacy System, qua đó trích dẫn 1 số cách thức của Keith Ray – XP Coach để gia công Việc với legacy code nhằm giảm (paying down) đầy đủ khoản technical debt, dựa vào gốc rễ cơ bản là viết mã sạch, tái kết cấu mã mối cung cấp với quăng quật túi SOLID principles.

Xin trích dẫn nguyên văn nội dung bài viết bởi Mark Levison từ

Allan Baljeu was trying to TDD with a legacy C++ code base, he was running inkhổng lồ trouble because:

we kết thúc up with classes that don’t fully implement the functionality that’s eventually needed, & when others come around to use those classes, & eventually fuller implementations are required, then it turns out that the original design is not adequate, a new kiến thiết is required, some expectations (tests) need to lớn change and previous uses of the class need khổng lồ be updated.

He wondered if Big Design Up Front would help solve the problem. George Dinwiddie, Agile Coach, suggested that Alan’s thiết kế was trying khổng lồ tell hyên ổn something. You have sầu lớn pay attention lớn the fundamentals of clean code. You can look at basic coupling & cohesion (i.e. SOLID).

Mike “Geepaw” Hill, Agile Coach, says that in his years of coaching agile teams, one of the following has been at the root of these problems:

team is not yet up lớn tốc độ on refactoring, so your classes aren’t reallyminimalteam is not yet skilled at simplicity, so dittoteam doesn’t know how lớn handle cross-team or company-to-public dependencies, e.g. shipping api’steam neither pairing nor open workspacing, dramatically slowing team-wide likely has no jiggle-less buildteam could be using tools from the ’40s

Keith Ray, XPhường Coach, suggests that with legacy code (i.e. systems with high technical debt) the cost of repaying technical debt dominates the cost of implementing a story. He goes on khổng lồ offer an approach:

To make the code more well-factored (paying down the technical debt), whenever you need lớn integrate a new feature inkhổng lồ it, you should pay cđại bại attention to lớn code smells in both the new code và the old code và consider refactoring to khuyễn mãi giảm giá with each smell as you recognize it.

You can vì chưng refactorings in small safe steps (even in C++) manually. Very closely follow the instructions in Fowler’s book on Refactoring until you learn them by heart. Eclipse with gcc has a few refactorings that actually work: Extract Method & Rename. Rename understands scope, so it is safer than search-and-replace. Extract Method và the other refactorings in Ecipse might be buggy, so be careful when you use them. For things lượt thích changing a function signature, “lean on the compiler” to show where changes have sầu khổng lồ be made.

Xem thêm: Cách Nhận Biết Con Trai Cong Là Gì ? Công Là Gì? Đặc Điểm Nhận Dạng

You also need tests to make sure the refactorings are not damaging the existing features. Feather’s book on working with legacy code has lots of techniques for adding tests lớn legacy code. On a higher cấp độ, code smells are violations of good design principles. For example, the Single Responsibility Principle (SRP) says there should one purpose for every class / method / module. There are principles about coupling and cohesion và managing dependencies, etc. It’s often easier lớn detect a code smell than it is to apply these abstract principles. “Large Class” và “Large Method” are remedied by “Extract Class” và “Extract Method/Move Method”, though knowing SRP. helps in deciding what parts of a class or method should be extracted.

Perhaps the most important design principle is “Tell, don’t ask”: keep functionality & data together…. bad code often has the functionality in one place, và gets the data it needs from other places, creating problems with dependencies and lack of locality — symptomized by “adding a new feature requires changing lots of code”. The code smells “Shotgun Surgery”, “Feature Envy”, “Long Parameter List” are applicable here.

Getting fast feedback will allow more refactoring, which will (eventually) allow faster development of new features. Try to get parallel builds happening (distributed compilation). Try lớn get smaller source files & smaller header files. Reduce the complexity of header files – use forward declarations, avoid inline code, try to lớn keep only one class per header tệp tin / source file. Using the “pimpl” idiom widely can decrease compile time by 10%, but it can also disguise the “Large Class” and “Feature Envy” code smells.

The advantage of refactoring instead of rewriting, is that you always have working code. If your manual và automated tests are good, then you should be able to ship the code, even if it is a half-way state between a bad thiết kế & a good kiến thiết.

Xem thêm: Tìm Hiểu Về Kinh Tuyến, Vĩ Tuyến Là Gì ? Vĩ Tuyến Là Gì? Câu Hỏi 19428

Keith also wrote “Refactoring: Small Steps Guaranteed khổng lồ Help You Clean Up Your Code” an article on refactoring C++ code in Better Software Magazine.

Previously on InfoQ: Dealing with Legacy Code, Uncle Bob On The Applicability Of TDD andMaking TDD Stick: Problems & Solutions for Adopters

Chuyên mục: Định Nghĩa