English Original:3 Key software principles You must understand, translation: Iteye
In this article, we will cover 3 important software development principles (DRY, KISS, Yagni), which you may already know or know only one of them. These principles may seem simple, but they can be difficult to implement. In any case, these principles provide a powerful way to manage complex software projects. When it comes to real-world project development, you will find that these principles are very useful.
Principle 1: Do not repeat yourself (Don ' t Repeat yourself,dry principles)
This principle is very important, in other words, do not write duplicate code .
When you are building a large software project, you are often overwhelmed by the complexity of the whole. The most basic strategy for solving complexity is to divide the system into several easy-to-handle parts. At first, you might want to divide the system into components , each representing a subsystem that contains everything you need to accomplish a particular function.
Components can also be split down so that complexity is reduced to a single responsibility, and each responsibility can be implemented using a class that contains methods and properties . Method implementation algorithm, the sub-parts of these algorithms and algorithms are the minimum knowledge blocks that make up the software business logic. You just have to make sure that the blocks are not duplicated.
DRY principle stipulates that in the whole system, every small knowledge block can only happen once, and each knowledge block must have a single, clear, authoritative characterization.
In a perfect application, each small piece of business logic will be encapsulated in a characterization, i.e. a variable or a class. A variable is encapsulated in a class that can be described as a representation of a responsibility, and the class is encapsulated in a component that can be described as a functional representation. This approach is called a modular architecture , and the DRY principle is an important part of it.
Implement DRY
You can reduce the complexity of your software project in the following ways to make it easier to identify potential duplicate issues:
Drawing the software architecture diagram and mapping the main components, complex projects may require a dedicated architecture diagram for each component.
If you reach the level of connection responsibilities, you may need to convert to a UML diagram .
Before writing a code block, name it according to its hierarchy in the project. Define what it stands for and make sure you know what it does in the component.
Define What should be represented (such as the ability to execute SQL in a database driver) and what should be hidden (such as database authentication information).
Ensure that representations do not depend on another complex level of characterization (such as one component that relies on classes in another component).
When you find that the code you're writing is similar or identical to the code you've written before, you'll need to take the time to think about what you're doing and make sure you don't repeat yourself.
Principle 2: As simple as possible, at a glance (Keep it stupid,kiss principles)
The simplest explanation is often the most correct.
Here the Stupid translates to "at a Glance" better, simple does not mean a glance, such as ". (){.. &};. "Simple enough, but do you understand what this is? This is actually a fork bomb in bash (constantly fork a new process, exhausting system resources).
So to be simple at the same time, but also to do at a glance. You can also understand that using a software as an idiot will be used. This is the highest level of user experience .
How do you do it simple and at a glance? This is due to the maintainability and the understandable nature of software development. The KISS principle is often reflected in the requirements design phase, and when you consider how to transform the customer's needs into an achievable component, try to confirm the following sections:
The function of profit and effort proportion is not adjusted
Features that are highly dependent on other features
Features that may become complex
All in all, if a task looks super complex, try to think of a creative, unique way. Spend more time discussing the key points to see if there are other more appropriate options.
principle 3: Moderation (you Ain ' t gonna need it,yagni principle)
The YAGNI principle refers to the need to include only the functionality required by the application, rather than trying to add any other functionality that you think might be required.
In a software project, 80% of the time is often spent on 20% of the functionality.
When you are ready to list a list of items, try to consider the following questions:
Low complexity by lowering the level of abstraction
Separate functions according to their characteristics
Moderate acceptance of non-functional requirements
Identify time-consuming tasks and get rid of them
These principles may seem simple, but in practice, there are a variety of problems to emerge. Once you force yourself to apply these principles, you will find that you are not far from creating the perfect software.
3 important principles of software development