[Code Cleanliness] others sentiment

Source: Internet
Author: User

This cleancode training, let me very feeling, the original "Tao" this thing really as the ancient sages said, there is no time, everywhere. Software programming, this is a modern vocabulary, this can be a way? The answer is yes.

This course of training, always around this point, at the beginning of the teacher raised a lot of programming masters of the quotations, each master although with different expression, but are talking about one thing, is to use their own understanding in the elaboration of the Tao.

So, what is Tao?

Kent Beck, author of the implementation model, says that the first value of programming is to value the importance of communicating with others, and Google's chief Java architect, Joshua Bloch, says that programming is first and foremost understandable, and the author of the Code clean Way, Robert Martin, says The Master programmer treats the system as a story rather than as a program to write.

What do you mean? Summing up, is Chairman Mao said that serving the people, is now called human-oriented.

It is around this core: to serve the staff, programming has the "code neat Way" thinking and specific skills. So specifically who should serve?

The first is to serve all who will read our program. Whether he's a code maintainer, a tester, a two-time developer, a leader, a reviewer, a learning person, including himself. To make every person who can read our code correct, smooth, and without pressure to understand our expression, this is the purpose of modern code writing. The teacher says that programming is for humans first and then for computers.

Around this goal, we need to have a humble mindset, a human-service mindset, and the code we write must be easy to understand and simple. Specific operating level:

    • Single abstract hierarchy Principle: The directory expression, with several functions to clearly explain the main business steps or logic, function name to describe the implementation of the function, rather than how to implement.
    • Single principle of responsibility

A function one thing

A loop one thing

One thing for a variable

One line of code one thing

    • Short principle:

The code recommends 20 lines, up to 50 lines.

Nesting up to 3 layers

Parameters up to 5

Variable maximum of 7

Cyclomatic complexity of up to 10

    • I encapsulate some poorly understood code, or the code of specific details, or complex boolean judgments, with an understandable function name encapsulated, even if only one line of code, even if only once, sometimes the meaning of a function is simply for the sake of understanding.
    • Use the function name to eliminate some comments, the function name can be long, 40 characters or less can be.
    • The function name does not contain not, which makes the person more comfortable to understand.
    • Try not to break and continue statements, because they tend to produce multiple understandings.
    • Do not have an empty statement or {}, you can create a function called donothing (), so as not to cause misunderstanding.
    • Any expression that may cause a variety of interpretations, in other words, the goal is to have only one possible understanding.

Secondly, it is for all the people who will use our program, mainly for the user service. If our code like a brief, short, will let the maintenance of its personnel compared to maintain a large lump of code, come to a clear point of thinking, pain index a little less, happiness Index a little higher. And even if there is a problem, it is easier to locate, rather than a needle in the haystack, which can improve maintenance staff satisfaction. It also improves end-user satisfaction by reducing the time it takes to fix bugs and improving the responsiveness of the users, so that those who use our code have a happy smile.

So, when we are programming, we should also hold the purpose of making people easy to understand, easy to maintain, use clear and simple expression, the so-called Boulevard to Jane. When programming, try to speak words, think more about how people feel, rather than how the computer feels.

------------------------------------------------------

Three qualities of a programmer: Clean code, refactoring, unit testing. We need to write neat, easy-to-understand code that is ready to be refactored and immediately unit tested without changing the behavior of the software. Learn to use tools Logicsocpe,sourcemonitor,checkstyle,pmd,sonar such as testing code to improve efficiency.

We also need to continue to learn, trainers introduced a lot of books such as: "Code neat Way Clean Code", the reconstruction of the classic: "Refactoring: Improve the existing code design", "Refactoring Handbook" "The Art of Writing readable Code" code Daquan 2 "Code quality" "Implementation Mode" "Reconstruction and Mode" "The Art of modifying Code" "Programming Life"

------------------------------

    • Letter dozens of one principle:

① a cycle only one thing;

② a variable to do only one thing;

③ a line of code to do one thing;

④ a function to do only one thing;

⑤ single abstract level principle;

⑥ code organizes only one thing at a time;

⑦ changes only one place ;

The complexity of ⑧ function circle should be less than 10;

The first principle of ⑨ function must be short;

⑩ writing functions must be dedicated, focused and humble.

    • Common Judgment principles

① single Responsibility SRP(Simple responsibility principle)

② opening and closing principle OCP (open-closed Principle)

③ single abstract hierarchy principle slap (individual level of abstraction principle)

④ function Query Modification separation principle CQS(command-query separation)

⑤sofa Principles

--------------------------------------

[Code Cleanliness] others sentiment

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.