[Finishing] KISS principle introduction

KISS principle introduction

 

KISS principle is the realm of high-level user experience, simple to understand this sentence, is to take a product to do even an idiot would use, which is also known as "lazy principle." In other words, the "less is more." The same applies in the secondary development of the SAP system, the core idea is "decoupling, decoupling, re-decoupling" duty single, single function into the future maintenance and reconstruction will bring great convenience.

Background

The KISS principle says that you should always choose the simplest solution for a problem. KISS is an acronym and can have any of the following meanings (the list is not exhaustive):

KISS principle is that you should always choose the simplest solution to a problem. KISS is actually an acronym, meaning you can have any of the following (list is not exhaustive):

  1. Keep it simple, stupid.
  2. Keep it small and simple.
  3. Keep it sweet and simple.
  4. Keep it simple and straightforward.
  5. Keep it short and simple.
  6. Keep it simple and smart.
  7. Keep it strictly simple.

The basic statement of the KISS principle is similar to Occam’s razor, which says that in science the preferred theory is the one that makes fewest assumptions to explain observations (see Wikipedia entry on the KISS principle).

About KISS principle of Occam's razor basic statement similar to the law, it is said in science, the theory is preferred with a minimum of hypotheses to explain observations of the theory (see the Wikipedia entry on KISS principle).

Tip : Occam's razor's law (Occam's Razor, Ockham's Razor ) , also known as "Ockham's Razor", it is by the 14th century English logician and Franciscan William Shiao will repair Cam's (William of Occam, about 1285-1349) proposed. This principle is called "if not necessary, do not by entity" that is "simple and effective principle." As his "book of Proverbs Notes" Volume 2 15 title says "Do not waste more things to do, with fewer things, you can do the same thing."

For example, Japan's largest cosmetics company received customer complaints, bought soap dish is empty inside. So they To prevent such things happening again production line, the invention is to find ways to engineer an X-ray fluoroscopy to monitor each shipment soap dish. The same problem also occurs in another small company, their solution is to buy a powerful industrial fans to blow each soapbox, he was blown away is not put empty boxes of soap. The same thing, using two very different ways, which is better do you think?

 

Rule

Follow the KISS principle

Follow the KISS principle, and limit the complexity of your programs as far as possible.

Follow the KISS principle

Follow the KISS principle, and limit the complexity of the program as much as possible.

 

Details

The best solution to a problem is usually the one that is as simple, minimalist, and easy to understand as possible, while ensuring stability, understandability, and maintainability in addition to functional correctness.

There are plenty of bad examples of the KISS principle. Why is this?

1、Programs are too complex right from the start. This can be due to poor design or simply a rash, undisciplined programming style.

2、Programs are maintained for lengthy periods. Instead of creating new implementations for old and new functions together, new functions are simply added (usually using IF control structures) to old functions. Programs that were initially simple thus become ever more complex, although this is not justified by the complexity of the task at hand.

To develop according to the KISS principle, you should ensure right from the start that the complexity of the program remains manageable. Rules that support this approach relate to the structure and style of programs, in particular comments and complexity.

The best solution to a problem is usually as simple as possible, minimalist and easy to understand, and in addition to the functional correctness, but also to ensure stability, understandability and maintainability.

KISS principle there are many examples of good. Why is that?

1 , from the outset, the program is too complex. This may be due to bad design, or just sloppy, undisciplined style of programming.

2 , to long-term maintenance program. The new function is not implemented as the old while creating new functions and new functions, but simply added to the old function (usually IF control structure). Initially simple program thus become more complex, although this is not the complexity of the task at hand demonstrated.

To be developed according to the KISS principle, you should be sure that the complexity of the program and control from the outset. Rules support this approach to be related to the structure and style of the program, in particular the comments and complexity.

 

Note

If existing programs do not follow the KISS principle, and these programs need to be further developed, we recommend refactoring as appropriate. Refactoring refers to the process of manually or automatically improving the structure of programs while retaining the observable program behavior. It improves legibility, understandability, maintainability, and extensibility, as well as considerably reducing the related effort for troubleshooting and functional enhancements (see Wikipedia entry on refactoring). The (incremental) refactoring of an existing program is not only useful for following the above rule, but also for all following rules.

The refactoring of existing code is supported by the required coverage by unit tests. Comprehensive unit tests can ensure that a program behaves in the same way after the refactoring process.

If the existing program does not follow the KISS principle, and the need for further development of these programs, we recommend reconstructed as needed. Reconstruction means to retain observable behavior of the program while the process of manually or automatically improve program structure. It improves readability, understandability, maintainability and scalability, and greatly reduced the work-related aspects of troubleshooting and enhancements (see the Wikipedia entry for reconstruction). (Incremental) reconstruction of an existing program applies not only to follow the above rules, but to all the rules to follow.

Coverage of the desired test unit support reconstruction of existing code. Comprehensive unit tests to ensure that the program is running in the same way after the reconstruction process.

 

Example

The figure below shows the structure of a method that does not follow the KISS principle. The method consists of approximately 160 statements and reaches a nesting depth of 12 levels. The method, which is only illustrated schematically, is a real example from a live ABAP program, which reached the state shown on the left after continuous additional developments. The method had become so complex that it was practically impossible to make another necessary change, and the developer was forced to refactor in line with the KISS principle.

The following figure shows the structure of the method is not a to KISS, the method from the statements about 160 nesting depth of 12 layers. This method is only symbolically illustrates an example of a real-time from the ABAP program, after continuous additional development, the program has reached the state as shown in the left. This method has become so complex that it is almost impossible to do it again the necessary changes, developers can only be forced to be reconstructed in accordance with the KISS principle.

The result is illustrated on the right of the figure. By splitting the method M into three methods, each with less than 100 statements and a maximum nesting depth of 5 levels, manageable modularization units were generated, which follow the rules for complexity, and allow the required modification to be made. Ideally, however, the state shown on the left side of the figure should never occur.

Results are shown in the right side of the picture, by the method M into three methods, each method statement less than 100, the maximum nesting depth of layer 5, the modular unit may generate management, which complies with the complexity of the rules and allow for modifications required. However, ideally, the picture on the left shows the state should not appear.

 

 

Released 2018 original articles · won praise 3957 · Views 10,350,000 +

Guess you like

Origin blog.csdn.net/zhongguomao/article/details/104929600