The elements of programming style

Source: Internet
Author: User
The elements of programming style is a very old book. Although FORTRAN
We are not very familiar with it. Although novel languages are emerging
The years cannot cover up the insights.
The English version of Google is everywhere.
Set Code Do not be clever.
What do you want to do? It's simple and straightforward.
Use the library function whenever possible.
Avoid using too many temporary variables.
"Efficiency" is not a reason to sacrifice clarity.
Let the machine do the dirty work.
Repeated expressions should be replaced with function calls.
Enclose brackets to avoid ambiguity.
Do not use ambiguous variable names.
Remove unnecessary branches.
Do not use bad features when using good language features.
Do not use too many conditional branches when using logical expressions.
If the logical expression is hard to understand, try to perform the deformation.
Select Program More concise data expression.
Use pseudocode first and then translate it into your language.
Modular. Use procedures and functions.
As long as you can ensure the readability of the program, you don't need to use Goto.
Don't patch bad code-Just rewrite it.
Split a large program into a small part to write and test in blocks.
Recursive Programs are used to process recursive data structures.
Test the correct and wrong input data.
Make sure that the input does not exceed the program limit.
End the input by end of the file, instead of relying on a count.
End the file as an input.
Identifies the wrong input. Fix it if possible.
It makes the input data easy to construct, so that the output data is self-evident.
Use a unified input format.
Make input easy to proofread.
If possible, provide a more free input format.
Use the input prompt to allow the default value. And display them.
Put the input and output in the subroutine.
Make sure all variables are initialized before use.
Do not stop because of a bug.
Open the debugging option of the Compilation Program.
The constant structure is initialized with data declaration, and the variable structure is initialized with Execution Code.
Be careful about off-by-one errors.
Be careful when there are multiple exit points in the loop.
If you do not do anything, you must show it elegantly.
Use the boundary value to test the program.
Manually check some answers.
Defensive Programming-write a few pieces of code for an impossible situation.
It is hard to ensure that the value is always 10.0 by 0.1.
7/8 is equal to 0, while 7.0/8.0 is not equal to 0.
Do not directly judge that two floating point numbers are equal.
First, right, and then fast.
First, make it reliable, and then make it faster.
First clean the code and make it faster.
Don't sacrifice cleanliness to get a little bit of "performance.
Let the compiler do some simple optimization.
Do not overdo code reuse. You can organize the code again the next time you use it.
Make sure that the special case is really special.
Keep it concise to get the speed.
Do not crack the code to speed up-find a better one Algorithm .
Use tools to analyze your program. Evaluate the performance before improving it.
Make sure that the comments are consistent with the Code.
Do not repeat the code in the comment-making every comment valuable.
Do not annotate bad code-rewrite it.
Give variables a meaningful name.
Repeat the program to make it easier for people who read the code to understand it.
Write a document for your data layout.
Do not comment too much.

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.