Code Daquan 2 study notes 2

Source: Internet
Author: User

Part II: Creating High-quality code

The fifth chapter: Design in Software construction

"In large projects, the design may be detailed to make coding work almost mechanized"

"In a small project, a design might refer to an interface that uses pseudo-code to write classes, or to ask the programmer next to the pattern, to draw a diagram of several classes."

--basically not experienced large projects, the process of small project description is very similar to my contact, the maximum number of design reviews.

"When no one knows how the changes to a code will affect other code, the project stops moving."

How complex, how bad the project will come to this point, no experience.

Because the project is mainly network, there are no employees, employers and other easily abstract objects, so the production of the class is basically a C subroutine and data collection body. I don't know if it's wrong, but I don't feel right about it.

"Information hiding is especially useful in a growing and changing environment."

In the beginning of the code, all the private variables are added to get, set, but slowly feel trouble, all public, feel that the project a person maintenance, all private variables are encapsulated, sometimes do not feel what the meaning, if the individual needs to deal with the special variable is encapsulated into a method.

It is obvious that you do not know the extent or the change to the procedure. Or, I don't feel too much of a benefit.

"Do not use Boolean variables for state variables, use enumerations"

This makes sense, because if you change from 2 to 3 types, it's a tiring job.

P117 Write Summary Mail This is good, after each discussion, often have forgotten, or someone remember wrong, leading to controversy and doubt.

Chapter Sixth: Classes that can work

"Programmers who do not understand ADT (abstract data types) simply heap together sub-programs and data that are slightly related, called classes." ”

Feel like this, but after reading this chapter, the feeling is to teach you to hide the private members, hidden implementation details, in addition to all the black box interface.

Inheritance and inclusion, I use the most, inherit the least.

Always hated to use inheritance, the biggest reason is to use source insight to see the code is not, always jump to the base class method inside. Do not know what reading tools will be better.

"When you want the base class to control the interface, use inheritance. When you want to dye yourself the control interface, with the inclusion of "

It is easy to use inheritance mainly in the list, but I usually use a class, and then include a void*, visit those containing the class, and then use a type variable tag is what kind.

P155

"Avoid creating a universal class"--sometimes the view Control data separation, is not this structure as a transition?

"Eliminate insignificant classes"--analogy structure to put data is much more convenient, why can't there be special data but no behavior of the class?

In C + +, only virtural methods can be overwritten, and the Java default method can be overridden.

The seventh chapter: high-quality sub-program

Sub-program parameters not more than 7, can be made into a structure, so that the time to add a parameter will be more convenient.

Do not show mysterious values, define with constants or use enumerations to replace constants such as 100,4.0,3.14.

Subroutines should be as simple and clear as possible.

Avoid taking input values as working variables.

Subroutines can avoid code duplication, easier to understand, improve portability, future optimization is also more convenient.

The eighth chapter: defensive Programming

"Main idea: To pass the wrong parameters is not afraid."

Assertion is a good method, but the Linux inside with assertions feel is not very good, because the screen printing what is the use of, it is better to print to the log inside, hard point, after printing the log out of the program good.

There are many cases of handling errors, good network situation is estimated to be the alarm and retry it.

Choose between correctness and robustness.

"Only the real exception throws the exception, and the exception should be the same as the assertion, something that should never happen."

--This seems to be incompatible with COM Oh, COM is mainly thrown out of the exception, especially the decoding of COM, throw the exception kind that call a lot.

-The reason for this is "exceptionally weakened encapsulation."

P203 pages criticize programmers for using exceptions to return errors for use

--Remember when I went to school, a classmate also said that his brother is a real object-oriented, all the return error value of the place is treated with exception, we worshipped for a while. But it may not be all right here, after all, it's a book.

"Before deleting an object, fill it with junk data"

--Tough enough, it's also a good idea, so you don't have to sometimes go wrong sometimes, if you try to use a certain crash later.

The Nineth chapter: pseudo-code programming

1. Use natural language to accurately describe specific operations.

2. Avoid using the syntax elements in the target programming language. (This is subject to procedural syntax constraints)

3, first out of the language to describe the intention to solve the problem.

4, and then write the pseudo-code at a low enough level, so that the code can be produced almost automatically from it.

5, after writing the code, you can put the pseudo-code as a comment exists.

The schema should indicate in advance how many resources are available to determine whether performance or readability takes precedence.

"Think about how to test it before writing a subroutine"--it's confusing and doesn't cite an example, just check the input and output? What else can you think about?


This article is from "Flying Justice Blog" blog, please be sure to keep this source http://xzq2000.blog.51cto.com/2487359/1767391

Code Daquan 2 study notes 2

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.