Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
NET_Coding_Guidelines.doc
Скачиваний:
2
Добавлен:
12.11.2019
Размер:
175.62 Кб
Скачать

Coding Guidelines

.NET Coding Guidelines

Version 3.0

16/02/2008

Approval

Name

Signature

Revision History

Date

Comment

Author

2004-10-25

Initial draft.

Pavel Lebedev

2004-10-27

Review.

Dmitry Zhuk

2005-06-10

Small fixes.

Pavel Lebedev

2005-12-20

.NET 2.0 additions.

Pavel Lebedev

2006-02-08

Change template and small fixes.

Pavel Lebedev

2007-10-22

Format changes and review.

Max Pliats

2007-11-29

Change maximum line length.

Pavel Lebedev

2008-02-16

Update for .NET 3.5.

Pavel Lebedev

Table of Contents

Coding Guidelines 1

.NET Coding Guidelines 1

1

1. Introduction 5

1.1 Overview 5

1.2 Scope of the document 5

1.3 Targeted readers 5

1.4 Typographical conventions 5

2. Naming conventions 6

2.1 Introduction 6

2.2 Abbreviations 7

2.3 Case sensitivity 7

2.4 Namespaces 8

2.5 Classes 9

2.6 Interfaces 10

2.7 Attributes 10

2.8 Exceptions 10

2.9 Enumerations 10

2.10 Static fields 11

2.11 Parameters 11

2.12 Methods 11

2.13 Properties 12

2.14 Events 12

2.15 Local variables 13

2.16 Type parameters 14

2.17 Summary 14

3. Comments 15

3.1 Introduction 15

3.2 Class comments 15

3.3 Method comments 15

3.4 Inline comments 15

4. Code formatting 17

4.1 Files and folders 17

4.2 Indentation, spaces and braces 17

4.3 Separation of operators and punctuators 18

4.4 Line length 18

5. General style recommendations 19

5.1 Structures and classes 19

5.2 Ref and out parameters 19

5.3 Operator overloading 19

5.4 Collections 19

5.5 Partial types 19

5.6 Anonymous methods 19

5.7 C# 3.0 features 19

6. References 21

7. Glossary 22

1.Introduction

1.1Overview

This document presents .NET version of coding guidelines that is obligatory for all Itransition software development process.

1.2Scope of the document

All details about development for other platforms are placed in separate documents. Platform independent information (like scripts development, graphical resources development) is stored in separate document.

This document contains information regarding to C# language mainly, however special section describes points significant to Visual Basic .NET.

1.3Targeted readers

Targeted readers for the document are all Itransition .NET developers.

1.4Typographical conventions

The following special typographical conventions are used within the document:

Font

Description

Italic

Represents emphasis or a referenced material’s title.

Fixed width

Represents any source code fragments (like class, method or attribute names), file names, etc.

2.Naming conventions

2.1Introduction

A consistent naming pattern is one of the most important elements of predictability and discoverability in a managed source code. Widespread use and understanding of these naming guidelines should eliminate many of the most common user questions. This section provides naming guidelines for the different types of entities used.

All identifiers should be written using only proper English words. Avoid too sophisticated words. Do not misuse words. Try to find the simplest and most correct word. Usually you should write “Unique”, but not “Extraordinary”.

The major goal of all conventions is high level of code understandability and maintainability. If you feel that conventions violation can increase understandability in some particular case, you can do that. But think twice before.

You might also have to violate these guidelines to maintain compatibility with existing code. For example, uppercase characters are often used for enumerations and constant values in unmanaged code. In general, these symbols should not be visible outside of the class/assembly that uses them.

Do not use language specific naming. Do not create language-specific method and parameters names, as in the following example:

void Write(double doubleValue);

void WriteDouble(double value);

Use instead:

void Write(double value);

In the extremely rare case that it is necessary to create a uniquely named method for each fundamental data type, use a universal type name (use ReadInt16() instead of ReadShort()).

It is recommended do not replace System.Object (and System.String) type by object keyword (string correspondingly). It is better use “Object” (“String”), not as “object” (“string”) to emphasize its object nature.

Avoid using names that duplicate commonly used .NET Framework namespaces and classes. For example, do not use any of the following names as a class name: System, Collections, Forms, or UI. See the Class Library in the MSDN for a list of .NET Framework namespaces.

In addition, avoid using identifiers that conflict with the keywords listed in the Word Choice MSDN article.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]