What makes good code?

Source: Internet
Author: User

A good program runs without flaws and no bugs. What are the internal factors? In fact, this is not mysterious. We only need to occasionally remind ourselves that C/C ++, C #, Java, basic, Perl, COBOL, and ASM are used for encoding, all good codes show the same features: concise, easy to read, attention, layering, design, efficiency, elegance, and clarity.
  ConciseThis means that you can use five lines of code instead of ten lines. This requires extra effort to simplify, but do not make the code obscure too much. Concise organization, implementation, and design can make your code more reliable, away from bugs, and avoid errors.
Easy to read is to allow others to read your code. You must write comments and follow the naming rules of variables. For example, "taxrate" is better than "TR.
  AdequacyIt means that your program is like everything in the universe. The world is made up of molecules, and molecules are made up of atoms, electrons, nuclear, Quark, and lies (if you believe. Similarly, good large system programs are composed of small components, which are composed of smaller component blocks. You can write a text editor with only the most basic functions: Move, insert, and delete. Just as atoms can be combined in a variety of amazing ways, components can be reused.
  LayeredMake your program look like a sandwich cake from the inside. Applications are built on the framework, the framework is built on the operating system, and the operating system is built on the hardware. Even within an application, layers are still required, for example, file-document-View-frame. The upper layer calls the lower layer (calls downstream and responds to upstream ). The lower layer will never know what the upper layer is. If the Doc directly calls the frame, things will get worse. Modules and layers are determined by API, which limits their boundaries. From this point of view, design is very critical.
  DesignIt means that it takes time to design your program before it is built. After all, it is much more cost-effective to think carefully at the early stage than to perform laborious debugging later. A commendable criterion is the design in half the time. You need to have a functional instruction book (describing what the program is doing) and a development plan. All APIs must be written into files.
  EfficiencyIt means that your program runs fast and the cost is low. Does not cause file and Data Link redundancy. It only does what it should do. Orderly loading and unloading. At the function level, you can always optimize it during testing. But at a higher level, you must have a good plan for performance.
  EleganceLike the US, it's hard to describe, but it's easy to recognize. Elegance brings together a feeling of simplicity, efficiency, and beauty. For example:

int fact( int n ){return n==0 ? 1 : n * fact(n-1);}

  ClearIs the most important of all other features. Computers provide the possibility of creating more complex software systems than physical hardware. The biggest challenge of programming is management complexity. Concise, easy-to-read, modular, layered, design, efficiency, and elegance are all very clear ways to deal with complexity. Clear coding, clear design, and clear purpose. At every level, you must really understand what you do, or else it is not clear. The failure of a bad program is usually not due to lack of coding skills, but to lack of a clear goal. This is why design is the most important. It makes you honest. If you cannot write it down and you cannot explain it to others, you will not really understand what you are doing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.