".Net best practices" - study notes

".Net best practices"

========== ========== ==========
[author] (US) Stephen Ritchie
[Translator] (in) yellow bridge Huang Haoyu Li Wing
[publishing] machine Press
[edition] January 2014 first edition
[Impression] January 2018 1st printing
[price] 69.00 yuan
========== ==== ====== ==========

(P001)

Developers should any practice called "best practices" to maintain a skeptical attitude.

Developers should be based on the specific environment where he used to select the "best practices" adopted.

(P009)

Microsoft's Visual Studio IDE is an integrated development environment to get widely used.

(F0l6)

I carefully read the ".NET design" of each chapter, from which I learned how .NET framework is built. The book also records crystal design thinking to build .NET Framework team. Can learn many important .NET practice through this book, it is a very important resource.

FxCop tool can be seen as a complement to ".NET design" of. It will help you to check one by one .NET assembly in accordance with the rules specified in advance.

(P044)

In software projects, the activities are not the goal. All activities must be targeted in order to achieve results.

(P063)

Brainstorming is a way to promote "ideas and experiences" cooperation.

(P065)

Only through communication can make your ideas become someone else's idea.

(P068)

To arrange a good job, carried out at the beginning of the mental and physical needs and complex challenges of work into the project. Those simple and less demanding tasks left to do it later. Methods leave more time for the challenging task to think about and explore better is important.

(P069)

By learning other people's experiences, you can prevent problems before they occur.

Use the experience of others is a highly leveraged way to avoid difficult, time-consuming problem.

(P071)

Understanding of the learning experience is to find work or come into contact with the material. Many things can only be understood by experience. The new knowledge required to participate in or be obtained by contacting software technology. It requires a combination of technical skills to get through practice. Any written form of things shall be improved and enhanced through experience.

(P077)

Capturing and re throw an exception when writing an empty throw statement. This is an established way to retain the call stack. Empty throw statement can be sure that stack trace for exception to the origin position to help debug errors.

(P078)

Use disposable .NET mode is the main mechanism for release of local and unmanaged resources.

(P079)

When the .NET types have local resources or disposable field, this type should implement IDisposable.

(P081)

Statements using statement allows the code to implement the IDisposable objects and when should be released correctly.

(P082)

In order to prevent the two calls Dispose method using statement, using a try-finally block write code to replace the outer layer.

(P084)

An uninitialized default value is 0 enumeration.

When appropriate explicitly defining the zero element of the enumeration.

(P085)

Whenever an empty instance semantically equal returns NULL, return an empty instance, as String.Empty.

Field defines a publicly visible static readonly, in the fields declared in this way without changing the value of allowing the client to receive the assembly is recompiled update value.

(P087)

Variable names should be very easy to understand, the variable name must show that what is represented by that variable. Variable names must be clear, correct and consistent.

(P093)

Extension method must be defined as static methods static class, and to determine before the first parameter of the signature method to place this keyword.

Extension methods can not extend a static class. In addition, if the same method signature and the signature of existing types of extension methods, then the extension method will never be called.

(P094)

In general, the extension method is an effective way to transform a closed type, to add new behavior and features.

在某些情况下,使用 var 关键字是必需的。如果要让匿名类型工作,隐式类型的局部变量就是必需的。由于类型是匿名的,开发人员不能明确指定变量的类型。编译器会自动处理所有的匿名类型的隐式类型。

(P096)

在 C# 语言中,引用类型(类、接口、泛型和委托)的变量可分配空值。值类型(枚举、数字类型、布尔类型和用户定义的struct)不能分配空值。

在 .NET 2.0 中引入可以为空的类型,用来为一个基本值类型的变量分配一个空值。这些可为空的类型是 System.Nullable<T> 结构的实例,其中的类型参数 T 是值类型。更常见的是语法 “T?”,是 System.Nullable<T> 的简写,其中的 T 是值类型。

(P102)

从 .NET 2.0 开始,C# 语言就有两种形式的泛型:

泛型类型:使用一个或多个类型参数定义类、结构、接口或委托;

泛型方法:使用一个或多个类型参数定义的方法;

(P103)

随着 .NET 3.0 引入 LINQ,查询进入 C# 并作为一种主要的语言构造,成为 foreach 循环、委托和扩展方法的基础。

(P104)

LINQ 的内容很多。有许多相关的语言特性对 LINQ 来说是必不可少的,包括扩展方法、 Lambda 表达式、匿名数据类型以及分部方法。还有很多关键字和很多查询结构。

(P107)

实体框架 (Entity Framework)、NHibernate 和 LINQ to SQL 都可以提供数据库 LINQ,并且都支持延迟执行。

(P119)

命名约定使用 “<被测试类> + Tests” 的格式来命名包含了测试方法的类。

在测试类 (tests class) 中,单词 Tests 故意使用了复数。它的意思是包含了测试的类,也被称为测试夹具类。

测试方法的名称需要明确以下三个重要的事情:被测试方法; 测试执行的条件;测试通过后的预期结果;

测试方法的命名约定要符合可读性模式,并能清楚表达测试的意图。

这个约定是“被测试方法_指定的条件_期望的结果” (MethodUnderTest_WithSpecifiedCondition_ExpectThisResult)。

3A模式“安排-动作-断言 (Arrange-Act-Assert)”是一种广泛使用和有益的约定。

 

Guess you like

Origin www.cnblogs.com/GATTACA2011/p/12003844.html