"Clean code" tells the code word, rather than surgery

Clean code

See " Clean code" a book, learning to write code for a master's, simple and efficient generation of

1. Objectives

Bjarne Stroustrup: elegant and efficient; straightforward; to reduce dependence; only one thing to do

Grady booch: straightforward

Dave thomas: readable and maintainable, unit testing

Ron Jeffries: Do not repeat, single responsibility, expressive ( expressiveness)

Write code, reflecting to some extent the skill of programming ideas, coders, and identifies the red part I think it reflects the functional programming, object-oriented thinking, we need to understand in detail

2 Name

2.1  pre-standardized, worthy of the name

Prior to the development of a good agreement, strictly adhered to, can not be late to temporarily add or iteration time, any name, or use comments to explain named

2.2  avoid ambiguity

Do not trickery, function and naming is not uniform, then prone to post-maintenance, add temporary situation demands, iterations, etc.

2.3  name should not be too easy to search and easy to read

Name just a synonym, to make people easy to read, easy to search, easy to discuss, express semantics, see the word direct mapping of thinking, can not be discussed at the time, unable to speak a name card for a long time, too long or want insufficiency

3 comments

The proper use of comments is to compensate for our failure to express ourself in code.

The fact is: the proper role of the comment is to remedy failures encountered when using the code we express intention, comments, just second-hand information .

The truth is in the code expressive code is real code

What is a good comment:

Basic information --- ease of code maintenance, transfer

The intent of the comment, why do ideas --- functions implemented

Warning --- prone to errors, performance and other factors may order, at the expense of readability, is a balanced

The importance of seemingly irrational things of amplifying --- professional knowledge, professional code, such as in the algorithm

4 Functions

Return to the original meaning, in the end what is the function

I understand: it is a code tool, it emphasized that only one thing, only one thing, to query is a query, you want to modify is modified, a fixed input parameters, you want to return to a fixed output, no extra side effects, it embodies the principle of a single

Embedding function which a plurality of function levels, better seen in this way

Pumping function layer 5 application

' There's nothing the problem is not pumping function layer can not be resolved, and if not, then two '

Principles: a function, a level of abstraction, function statements show the same level of abstraction , especially in the face of complex interactions of large projects, in accordance with the breadth-first strategy, first understand the overall structure, to seize the trunk, and then go into the details, such as the elephant put into the refrigerator:

def pushElephantIntoRefrige():

openRefrige ()  to open the refrigerator

pushElephant ()  the elephant in the refrigerator

closeRefrige ()  to close the fridge

 

They belong to a hierarchy, and how this detail in the refrigerator need to have a new level

 

 

 

 

 6  test

Test principle:

You are not allowed to write any production code unless it is to make a failing unit test pass. Do not write any function codes before test

You are not allowed to write any more of a unit test than is sufficient to fail;. And compilation failures are failures only write just to reflect a situation of failed test code

You are not allowed to write any more production code than is sufficient to pass the one failing unit test. Just write code that can only function test

 

Guess you like

Origin www.cnblogs.com/suoni/p/11532763.html