維護舊項目
Believe it or not, some organizations still rely on legacy software to carry out operations even though newer and more versatile options are available. We know that “old is gold”, but legacy applications cannot glitter forever. As such, these old and outdated programs have become hard to maintain.
信不信由你,即使有較新的和更通用的選項可用,一些組織仍然依靠舊版軟件來執行操作。 我們知道“古老就是黃金”,但是舊版應用程序無法永遠閃爍。 因此,這些舊的和過時的程序已變得難以維護。
Recently, the U.S. Government Accountability Office (GAO) gave a report that pointed out the most critical federal legacy systems that need to be modernized. This is because they are based on antiquated programming languages, are prone to security loopholes, and are difficult to maintain.
最近,美國政府問責局(GAO)發表了一份報告 ,指出了需要現代化的最關鍵的聯邦遺留系統。 這是因為它們基于過時的編程語言,容易出現安全漏洞,并且難以維護。
Are you in the same shoes?
你穿同一雙鞋嗎?
In this article, I’m going to talk frankly about the challenges you'll face when maintaining legacy software applications, and how you can overcome them.
在本文中,我將坦誠地談論維護舊版軟件應用程序時將面臨的挑戰,以及如何克服這些挑戰。
舊版系統效率低下 (Legacy systems are inefficient)
Software maintenance is important – it helps enhance the efficiency of the product and narrows the margin for error. Without sufficient maintenance, an application can become inefficient and difficult to operate.
軟件維護很重要–它有助于提高產品效率并縮小錯誤余地。 沒有足夠的維護,應用程序可能會變得效率低下且難以操作。
First of all, maintaining a legacy system can be difficult because the code used is old when compared to the code used in any modern software. Old code usually tends to be bulky, lengthy, and incompatible with most modern systems.
首先,維護遺留系統可能很困難,因為與任何現代軟件中使用的代碼相比,所使用的代碼是舊的。 舊代碼通常趨于龐大,冗長,并且與大多數現代系統不兼容。
For example, JavaScript arrow functions, which were introduced in ES6 in 2015, offer developers a way to write shorter and cleaner function syntax, which is easier to maintain.
例如,2015年ES6中引入JavaScript箭頭函數為開發人員提供了一種編寫更簡短的函數語法的方法,該語法更易于維護。
let total = (x, y) => x + y;/* This arrow function is a shorter form of:
let total = function(x, y) {return x + y;
};
*/console.log(total(5, 2) );
// 7
維護費用高 (High maintenance costs)
Another challenge facing most legacy systems is the high cost of maintenance, which may be out of reach for most enterprises.
大多數傳統系統面臨的另一個挑戰是維護成本高昂,這對于大多數企業而言可能是無法承受的。
For example, according to the GAO report mentioned above, the U.S. government planned to spend more than $90 billion in 2019 on IT services, most of which went towards maintaining aging systems.
例如,根據上述GAO報告,美國政府計劃在2019年在IT服務上花費超過900億美元,其中大部分用于維護老化的系統。
Furthermore, as technology is evolving, compliance is becoming a major issue for the protection of consumer-facing applications. Achieving compliance with legacy systems is time-consuming and expensive. It will not happen as quickly compared to new applications who are often compliant by default. It also requires a lot of testing to ensure a legacy infrastructure is compliant with the given regulations.
此外,隨著技術的發展,合規性已成為保護面向消費者的應用程序的主要問題。 實現與舊系統的合規性既耗時又昂貴。 與通常默認情況下兼容的新應用程序相比,它不會那么快發生。 它還需要進行大量測試,以確保舊式基礎結構符合給定的法規。
The cost of maintaining a legacy system often increases with time, as it slowly becomes obsolete due to technological enhancements. Also, modification of an existing system is a risky venture, which requires a lot of time and resources.
維護遺留系統的成本通常會隨著時間的流逝而增加,因為隨著技術的增強,它逐漸變得過時。 另外,修改現有系統是冒險的,需要大量時間和資源。
缺乏足夠的技能 (Lack of sufficient skill sets)
For legacy software to be maintained, you need a developer conversant with its operations. However, most developers are future-proofing their applications with new technologies. So, getting someone who can work with an old system can be a challenge.
為了維護舊版軟件,您需要一個熟悉其操作的開發人員。 但是,大多數開發人員正在使用新技術對應用程序進行過時的驗證。 因此,找到可以使用舊系統的人可能是一個挑戰。
In some cases, you might need to re-train developers on how the legacy system works, which increases a company’s operating costs.
在某些情況下,您可能需要對開發人員進行有關舊系統如何工作的培訓,這會增加公司的運營成本。
Furthermore, managing and controlling changes occurring in the software can be difficult. A lot of time and effort is required to keep the systems operational, which is expensive and time-consuming.
此外,管理和控制軟件中發生的更改可能很困難。 要使系統保持運行需要大量時間和精力,這既昂貴又費時。
與其他IT解決方案不兼容 (Incompatibility with other IT solutions)
Currently, there are modern tools that can be used to enable fast and smooth maintenance of software. However, most legacy IT infrastructure is incompatible with such solutions, which complicates their maintenance.
當前,有現代工具可用于實現軟件的快速平穩維護。 但是,大多數舊版IT基礎架構與此類解決方案不兼容,這使它們的維護復雜化。
If the features in a legacy system are not compatible with those of new IT solutions, developers may find it difficult to integrate them into their environments.
如果舊系統中的功能與新IT解決方案的功能不兼容,則開發人員可能會發現很難將其集成到他們的環境中。
The difficulty of introducing new features to legacy systems also adds to the challenges in their maintenance. Since most legacy systems break easily, trying to restructure and make them more maintainable may not work as expected.
向舊系統中引入新功能的困難也增加了其維護方面的挑戰。 由于大多數遺留系統很容易損壞,因此嘗試進行重組并使其更易于維護可能無法按預期進行。
應對挑戰 (Solutions to the challenges)
To compete favorably in today’s dynamic IT landscape, legacy technologies need modernization. Updated legacy applications lead to more user productivity, reduced maintenance costs, and more helpful experiences.
為了在當今瞬息萬變的IT環境中贏得有利的競爭,傳統技術需要進行現代化。 更新的舊版應用程序可提高用戶的工作效率,降低維護成本,并提供更多有用的體驗。
According to recent research by Avanade, modernizing IT systems can lead to a revenue growth of about 14%. Therefore, choosing different software modernization options could lead to significant benefits to your business.
根據Avanade的最新研究,現代化的IT系統可以帶來大約14%的收入增長。 因此,選擇不同的軟件現代化選項可能會為您的業務帶來重大利益。
It’s important to note that software should not be declared obsolete just because it’s old. Some of the ‘old’ software may still contain rich features, which can be useful to the optimal functioning of an application.
重要的是要注意,不應僅因為軟件過舊就宣布其過時。 某些“舊”軟件可能仍包含豐富的功能,這些功能可能有助于優化應用程序的功能。
Therefore, to overcome the challenges of maintaining aging software, developers can opt to refactor the source code of the system. This way, they can use clean and modern code that is reusable and easy to debug.
因此,為了克服維護老化軟件的挑戰,開發人員可以選擇重構系統的源代碼。 這樣,他們可以使用可重復使用且易于調試的干凈現代代碼。
In refactoring, you alter your software system to enhance its internal structure. But you don't interfere with the external behavior of the code. This way, the features of the software are optimized due to the code's internal improvements.
在重構中,您可以更改軟件系統以增強其內部結構。 但是您不會干擾代碼的外部行為。 這樣,由于代碼的內部改進,軟件的功能得以優化。
When refactoring legacy code, updates and modifications should be sufficiently tested to avoid breakages and poor functioning of the application. For example, regression tests can be done to ensure that everything is working as desired.
重構遺留代碼時,應充分測試更新和修改,以避免應用程序損壞和運行不佳。 例如,可以進行回歸測試以確保一切正常。
Additionally, where resources permit, developers can opt to rewrite the entire source code of the software, while employing modern programming approaches.
此外,在資源允許的情況下,開發人員可以選擇重寫軟件的整個源代碼,同時采用現代編程方法。
If you want to continue maintaining your legacy code without breaking it, you can use any of the following three methods:
如果要繼續維護舊代碼而不破壞它,則可以使用以下三種方法之一:
- Identifying change points in the code 識別代碼中的變更點
- Isolating your code 隔離您的代碼
- Wrapping the code 包裝代碼
Let's talk about each of the methods.
讓我們談談每種方法。
識別代碼中的變更點 (Identify change points in the code)
As pointed out earlier, maintaining legacy code can be challenging. Sometimes the issue can be caused by a section that has been poorly programmed. Therefore, you can overcome this by identifying a location that can allow you to change the application's behavior without altering the source code.
如前所述,維護遺留代碼可能具有挑戰性。 有時,該問題可能是由于某個程序段的編程不正確引起的。 因此,您可以通過確定一個可以在不更改源代碼的情況下更改應用程序行為的位置來克服這一問題。
For example, let's say you have the following JavaScript code in a legacy application that connects to a database:
例如,假設您在連接數據庫的舊版應用程序中具有以下JavaScript代碼:
export class DataConnection {//some code hereconnector() {// some code to connect to database}
}
If you want to run some tests on the above code but the the connector() method is causing problems, you can identify where to modify the code behavior without affecting the source code.
如果要對上面的代碼運行一些測試,但是connector()方法引起了問題,則可以確定在不影響源代碼的情況下修改代碼行為的位置。
In this case, you can extend the DataConnection class and stop it from establishing a connection to an actual database:
在這種情況下,您可以擴展DataConnection類,并阻止其建立與實際數據庫的連接:
class FakeConnection extends DataConnection {connector() {// solve the issues of making calls to DBconsole.log("Establishing a connection")}
}
Consequently, after modifying the code behavior without affecting the source code, you can run tests on the code and maintain it without any problems.
因此,在修改代碼行為而不影響源代碼之后,您可以在代碼上運行測試并對其進行維護,而不會出現任何問題。
隔離您的代碼 (Isolate your code)
Another technique that can allow you to maintain your legacy code easily is to isolate and make any changes on a different environment. You just need to identify an insertion point where you can call that changed code from the existing legacy code.
可以使您輕松維護遺留代碼的另一種技術是隔離并在不同的環境上進行任何更改。 您只需要標識一個插入點,就可以從現有舊代碼中調用更改后的代碼。
Here is an example:
這是一個例子:
class BooksData {// some code hereaddBooks(books) {for (let book of books) {book.addDate()}// some code herebooksRecords.getNumberOfBooks().add(books)}// some code here
}
Let's say you want to optimize the books reference in the above legacy code, but addBooks() is giving you problems.
假設您想優化上述舊版代碼中的書籍參考,但是addBooks()給您帶來了問題。
So, you can isolate the code in another new method, like newBooks().
因此,您可以使用另一種新方法(例如newBooks())隔離代碼。
Then you can run tests on this new method successfully because it is separate from the rest of the code. Afterwards, you can include a call to the new method in the existing, non-changed code. This way, there'll be minimal changes and minimal risks to the legacy code.
然后,您可以對該新方法成功運行測試,因為它與其余代碼是分開的。 之后,您可以在未更改的現有代碼中包含對新方法的調用。 這樣,對遺留代碼的更改最少,風險也最小。
Here it is:
這里是:
class BooksData {// some code herenewBooks(books) {// some smart and testable logic to optimize books}addBooks(books) {const newBooks = this.newBooks(books)for (let book of newBooks) {book.addDate()}// some code herebooksRecords.getNumberOfBooks().add(books)}// some code here
}
包裝代碼 (Wrap the code)
If you want to make changes that should take place before or after the existing code, wrapping it can also be another solution.
如果要進行應在現有代碼之前或之后進行的更改,則將其包裝也可以是另一種解決方案。
You can achieve this by giving the old method you intend to wrap a new name, adding a new method with the same name and signature just like the old method, and calling the new method from the new method. Lastly, you should place the new logic before or after the previous method call.
您可以通過以下方式實現此目的:給您打算包裝新名稱的舊方法,添加一個與舊方法一樣具有相同名稱和簽名的新方法,然后從新方法中調用新方法。 最后,您應該將新邏輯放在上一個方法調用之前或之后。
With the new logic, you can run tests or make any changes you want – without affecting the source code.
使用新的邏輯,您可以運行測試或進行所需的任何更改-而不會影響源代碼。
For example, here is the code we used previously:
例如,這是我們之前使用的代碼:
class BooksData {// some code hereaddBooks(books) {for (let book of books) {book.addDate()}// some code herebooksRecords.getNumberOfBooks().add(books)}// some code here
}
Here is how to solve the problem through wrapping:
這是通過包裝解決問題的方法:
class BooksData {// some code hereaddBooks(books) {// some smart logic to get booksthis.addMoreNewBooks(moreBooks)}addMoreNewBooks(books) {for (let book of books) {book.addDate()}// some code herebooksRecords.getNumberOfBooks().add(books)}// some code here
}
結論 (Conclusion)
Although modernizing antique software is complicated, demanding, and risky, the results are usually worth the risk. Continuing to rely on legacy IT systems is the same as continuing to use the post office to send an urgent message, while an email could do the trick at the click of the button.
盡管對古董軟件進行現代化改造既復雜,苛刻又有風險,但通常值得承擔風險。 繼續依賴舊版IT系統與繼續使用郵局發送緊急消息的方法相同,而單擊按鈕則可以通過電子郵件來解決問題。
Furthermore, as a programmer, do you equip yourself with modern coding skills? Or, do you still rely on old approaches?
此外,作為一名程序員,您是否具備現代編碼技能? 或者,您仍然依靠舊方法嗎?
For example, in the exciting world of JavaScript programming, we’ve witnessed a surge of frameworks, like React and Angular, which are defining the future of the language. Spending some time learning about them could prevent you from falling into obsoleteness.
例如,在令人興奮JavaScript編程世界中,我們目睹了如React和Angular之類的框架的不斷涌現,它們定義了該語言的未來。 花一些時間了解它們可能會防止您過時。
Do you agree?
你同意嗎?
翻譯自: https://www.freecodecamp.org/news/legacy-software-maintenance-challenges/
維護舊項目