. net best practices – learning notes

Time:2020-2-13

. net best practices

========== ========== ==========
Stephen Ritchie
(c) Huang Dengqiao, Huang Haoyu, Li Yong
[publication] Mechanical Industry Press
[edition] January 2014 Edition 1
[printing time] first printing in January 2014
[price] 69.00 yuan
========== ========== ==========

(P001)

Developers should be skeptical of any practice they call “best practice.”.

Developers should choose which “best practices” to adopt based on their specific environment.

(P009)

Microsoft’s visual studio IDE is a widely used integrated development environment.

(P016)

I read every chapter of the. Net design specification carefully, from which I learned how to build the. Net framework. This book also records the thinking of designing and building. Net framework team. Through this book, you can learn many very important. Net practices, which is a very important resource.

The FxCop tool can be seen as a supplement to the. Net design specification. It will help you check. Net assemblies one by one according to the rules you specify in advance.

(P044)

In software projects, activities are not goals. All activities must aim to achieve results.

(P063)

Brainstorming is a way to promote “ideas and experience” collaboration.

(P065)

Only through communication can your ideas become others’ ideas.

(P068)

To arrange the work, we should put the challenging work that needs to be done by brain and complexity into the beginning of the project. Leave the simple and less demanding tasks behind. It’s important to allow more time for challenging tasks to think and explore better ways.

(P069)

By learning from other people’s experience, we can prevent problems before they happen.

Using other people’s experience is a high leverage method, which can avoid difficult and time-consuming problems.

(P071)

Experiential learning is the understanding of materials found or exposed to in work. Many things can only be understood through experience. New knowledge needs to be acquired through participation or contact with software technology. Skills need to be acquired through practice in combination with technology. Anything written should be improved and improved through experience.

(P077)

When catching and rethrowing exceptions, write an empty throw statement. This is the established way to keep the call stack. An empty throw statement ensures that the stack keeps track of the origin of the method exception to help debug the error.

(P078)

Using the disposable mode is the main mechanism. Net uses to release local and unmanaged resources.

(P079)

When a. Net type has a local resource or disposable field, it should implement IDisposable.

(P081)

Statement using allows code to declare when an object that implements IDisposable should be released properly.

(P082)

To prevent the dispose method from being called twice, a try finally block can be used instead of the outer using statement when writing code.

(P084)

The default value for an uninitialized enumeration is 0.

Explicitly define zero enumeration elements when appropriate.

(P085)

Whenever an empty instance is semantically equal to returning a null value, an empty instance, such as string.empty, is returned.

Define a publicly visible field static readonly, which allows fields declared in this way to change values without client assembly recompilation to receive updated values.

(P087)

Variable names should be easy to understand and must indicate what they represent. Variable names must be unambiguous, correct, and consistent.

(P093)

An extension method must be defined as a static method of a static class, and this keyword must be placed before the first parameter in the signature of the method.

Extension methods cannot extend a static class. In addition, if the signature of an extension method is the same as that of an existing method of type, the extension method will never be called.

(P094)

Generally speaking, the extended method is an effective way to transform the closed type, which can add new behaviors and functions.

In some cases, using the VaR keyword is required. For anonymous types to work, local variables of implicit types are required. Because the type is anonymous, developers cannot explicitly specify the type of the variable. The compiler automatically handles all implicit types of anonymous types.

(P096)

In C, variables that reference types (classes, interfaces, generics, and delegates) can be assigned null values. Value types (enums, numeric types, Boolean types, and user-defined structs) cannot assign null values.

In. Net 2.0, the type that can be null is introduced to assign a null value to a variable of basic value type. These nullable types are system.nullableStructure, where the type parameter t is the value type. More common is the syntax “t?”, which is system. NullableShort for, where t is the value type.

(P102)

Since. Net 2.0, C ා language has two forms of generics:

Generic type: use one or more type parameters to define a class, structure, interface, or delegate;

Generic methods: methods defined with one or more type parameters;

(P103)

With the introduction of LINQ in. Net 3.0, query enters C ා and becomes the basis of foreach loop, delegation and extension methods as a major language construction.

(P104)

LINQ has a lot of content. There are many related language features that are essential to LINQ, including extension methods, lambda expressions, anonymous data types, and partial methods. There are also many keywords and many query structures.

(P107)

The Entity Framework, NHibernate and LINQ to SQL all provide LINQ database, and all support delayed execution.

(P119)

The naming convention uses the format “+ tests” to name classes that contain test methods.

In the tests class, the word tests intentionally uses the plural. It means the class that contains the test, also known as the test fixture class.

The name of the test method needs to be clear about three important things: the tested method; the condition of test execution; the expected result after the test passes;

The naming convention of the test method should conform to the readability pattern and be able to clearly express the intention of the test.

This Convention is “method under test” with specified condition “expectthisresult.

The 3A pattern “arrange act assert” is a widely used and useful convention.