Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is DRY?

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what is DRY". In daily operation, I believe many people have doubts about what is DRY. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is DRY?" Next, please follow the editor to study!

What is DRY?

Don't repeat yourself, referred to as DRY, is a widely accepted best practice in software engineering. In principle, DRY requires that every part of the system must be expressed in a single, clear and authoritative manner. It's all about developing software reliably and making development projects easier to understand and maintain. The most basic principle of DRY is not to repeat code.

In software engineering, "clean code" is an ideal pursuit. Programmers who can identify repetition and eliminate it through appropriate practice will write cleaner code than programmers who repeat code all the time.

Many people limit DRY to "don't write repetitive code", but it puts more emphasis on repetition of knowledge and intention.

Second, how does repetition occur?

Most of the repetitive problems we see in the programming process can be roughly divided into the following four categories:

1. Imposed repetition most people have worked when they are unable to avoid repetition

For example, some projects may cause us to repeat common definitions and processes, or some programming languages themselves require the structure of some repetitive information.

Such as comments that are often emphasized in documentation specifications, but in fact useless comments can make the code worse. If you apply the law of DRY, it is to put easy-to-understand knowledge in the code and reserve comments for other high-level instructions. Otherwise, you are repeating knowledge.

2. Inadvertently repeating errors in code design usually makes developers unaware that they are repeating information.

3. Impatient repetition this repetition is usually due to developers' laziness, believing that repetition will make the implementation of the function easier. It will also drive some developers to copy and modify the original code and take shortcuts because of the time constraints of the project.

Haste makes waste. Repetition may save a few seconds, but if something goes wrong, it will take more time to fix it.

4. The most typical example of repetition among developers is the following example. In a state of the United States, during a millennium bug inspection of government computer systems, an audit found that there were more than 10,000 programs, each containing a different version of the social security number verification code.

Duplication by different developers on the same team is probably the most difficult to detect and deal with. These repetitions may exist for many years, are not easy to detect, and can lead to various maintenance problems.

Third, preliminary implementation of DRY, you can try to do so

1. Stop repeating unnecessary code

2. When the code is repeated 3 times, stop and think about whether you need to further abstract the code or tool class

3. Add test programs to the historical legacy code, sort out the logic, add explanatory documents and notify the relevant personnel.

4. Explain the project at the right time, clarify the existing functions and code of the project, and reduce the repetition caused by not knowing the project.

At this point, the study of "what is DRY" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report