Philips Healthcare - C# Coding Standard
|
|
|
- Roy Edwards
- 10 years ago
- Views:
Transcription
1 Philips Healthcare - C# Coding Standard Version 2.0 (c) 2009, Philips Healthcare issued by the CCB Coding Standards Philips Healthcare External Use of this Document The C# coding standard as defined by Philips Healthcare and published via the TIOBE website ( may be used "as-is" by any interested party. You may copy, adapt, and redistribute this document for non-commercial use or for your own internal use in a commercial setting. However, you may not republish this document, nor may you publish or distribute any adaptation of this document for other than non-commercial use or your own internal use, without first obtaining express written approval from Philips Healthcare. Philips Healthcare will not be liable for any direct, indirect, special or consequential damages arising out of any use of the document or the performance or implementation of the contents thereof. Please send questions and suggestions about the C# coding standard and/or its code checker ClockSharp to [email protected].
2 Table of Contents Introduction Objective Scope...1 General rules (General)...3 Rule Naming conventions (Naming)...4 Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule i
3 Table of Contents Naming conventions (Naming) Rule Rule Rule Rule Rule Rule Rule Rule Rule Comments and embedded documentation (Comments)...16 Rule Rule Rule Rule Object lifecycle (Object lifecycle)...19 Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Control flow (Control flow)...25 Rule ii
4 Table of Contents Control flow (Control flow) Rule Rule Rule Rule Rule Rule Rule Rule Object oriented programming (Object oriented)...30 Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule iii
5 Table of Contents Object oriented programming (Object oriented) Rule Rule Rule Rule Rule Rule Exceptions (Exceptions)...39 Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Delegates and events (Delegates and events)...45 Rule Rule Rule Rule Rule Rule iv
6 Table of Contents Delegates and events (Delegates and events)...47 Rule Rule Rule Various data types (Data types)...50 Rule Rule Rule Rule Rule Rule Rule Rule Rule Rule Coding style (Coding style)...55 Rule Rule Rule Rule Rule Literature...57 v
7 Introduction 1.1. Objective This Coding Standard requires or recommends certain practices for developing programs in the C# language. The objective of this coding standard is to have a positive effect on Avoidance of errors/bugs, especially the hard-to-find ones. Maintainability, by promoting some proven design principles. Maintainability, by requiring or recommending a certain unity of style. Performance, by dissuading wasteful practices Scope This standard pertains to the use of the C# language. With few exceptions, it does not discuss the use of the.net class libraries. This standard does not include rules on how to layout brackets, braces, and code in general Rationale Reasons to have a coding standard and to comply with it are not given here, except the objectives listed in section 1.1. In this section the origins of the rules are given and some explanation why these were chosen Sources of inspiration Many of the rules were taken from the MSDN C# Usage Guidelines ([MS Design]). The naming guidelines in that document are identical to those found in Appendix C of the ECMA C# Language Specification ([C# Lang]). Many other recommendations and a few design patterns were also taken from [MS Design]. Some general good practices, most of them concerning Object-Oriented programming, were copied from the Philips Healthcare C++ Coding Standard ([C++ Coding Standard]). The numbering scheme and some of the structure have been copied from [C++ Coding Standard] Contrast with C++ A considerable part of a coding standard for C or C++ could be condensed into a single rule, avoid undefined behavior, and maybe shun implementation defined behavior. Officially C# does not exhibit any of these, barring a few minor, well-defined exceptions. Most examples of undefined behavior in C++ will cause an exception to be thrown in C#. Although this is an improvement on the?anything might happen? of C++, it is highly undesirable for post-release software Applicability This coding standard applies to all C# code that is part of Philips Healthcare software products or directly supportive to these products. Third party software is constrained by this standard if this software is developed specifically for Philips Healthcare. 1
8 1.5. Notational conventions Rule A rule should be broken only for compelling reasons where no reasonable alternative can be found. The author of the violating code shall consult with at least one knowledgeable colleague and a senior designer to review said necessity. A comment in the code explaining the reason for the violation is mandatory Checkable Rules in this coding standard are marked checkable if automatic verification of compliance is enforced by static analyzers Examples Please note that the source code formatting in some examples has been chosen for compactness rather than for demonstrating good practice. The use of a certain compact style in some of the examples is considered suitable for tiny code fragments, but should not be emulated in?real? code. 2
9 General rules (General) Rules Do not mix code from different providers in one file Rule Synopsis: Do not mix code from different providers in one file Level: 6 Category: General In general, third party code will not comply with this coding standard, so do not put such code in the same file as code written by Philips. Also, avoid mixing code from different Philips departments in one file, e.g., do not mix MR code with PII code. This coding standard does not specify layout rules, so code from both providers may look slightly different. 3
10 Naming conventions (Naming) Rules Use US-English for naming identifiers Use Pascal and Camel casing for naming identifiers Do not use Hungarian notation or add any other type identification to identifiers Do not prefix member fields Do not use casing to differentiate identifiers Use abbreviations with care Do not use an underscore in identifiers Name an identifier according to its meaning and not its type Name namespaces according to a well-defined pattern 3@110 Do not add a suffix to a class or struct name 3@111 Use a noun or a noun phrase to name a class or struct 3@112 Abbreviations with more than two letters should be cased as words 3@113 Prefix interfaces with the letter I 3@120 Use similar names for the default implementation of an interface 3@122 Suffix names of attributes with Attribute 3@201 Do not add an enum suffix to an enumeration type 3@202 Use singular names for enumeration types 3@203 Use a plural name for enumerations representing bitfields 3@204 Do not use letters that can be mistaken for digits, and vice versa 3@301 Add EventHandler to delegates related to events 3@302 Add Callback to delegates related to callback methods 3@303 Do not add a Callback or similar suffix to callback methods 3@304 Use a verb (gerund) for naming an event 3@305 Do not add an Event suffix (or any other type-related suffix) to the name of an event 3@306 Use an -ing and -ed form to express pre-events and post-events 3@307 Prefix an event handler with On 3@401 Suffix exception classes with Exception 3@402 Do not add code-archive related prefixes to identifiers 3@501 Name DLL assemblies after their containing namespace 3@503 Use Pascal casing for naming source files 3@504 Name the source file to the main class Rule 3@101 Synopsis: Use US-English for naming identifiers Level: 6 Category: Naming 4
11 US-English means: magnetization, optimizing, realize,... tumor, behavior,... center, millimeter,... ischemic, pediatric, hemodynamic,... Rule Synopsis: Use Pascal and Camel casing for naming identifiers Level: 9 Category: Naming In Pascal casing the first letter of each word in an identifier is capitalized, e.g., BackColor In Camel casing only the first letter of the second, third, etc. word in a name is capitalized; for example, backcolor. The table below provides the casing for the most common types. Identifier Case Example Class Pascal AppDomain Enum type Pascal ErrorLevel Enum values Pascal FatalError Event Pascal ValueChange Exception class Pascal WebException Field camel listitem Const Field Pascal MaximumItems Read-only Static Field Pascal RedValue Interface Pascal IDisposable Method Pascal ToString Namespace Pascal System.Drawing Parameter camel typename Property Pascal BackColor For handling abbreviations see [3@112]. Rule 3@103 Synopsis: Do not use Hungarian notation or add any other type identification to identifiers 5
12 Level: 6 Category: Naming Use of Hungarian notation is deprecated by companies like Microsoft because it introduces a programming language-dependency and complicates maintenance activities. Exceptions: [3@113], [3@122], [3@301], [3@302], [3@307], [3@401]. Rule 3@104 Synopsis: Do not prefix member fields Level: 9 Category: Naming Exception: Member fields can prefixed with an "m" character. Rule 3@105 Synopsis: Do not use casing to differentiate identifiers Level: 7 Category: Naming Some programming languages (e.g. VB.NET) do not support distinguishing identifiers by case, so do not define a type called A and a in the same context. This rule applies to namespaces, properties, methods, method parameters, and types. Please note that it is allowed to have identifiers that differ only in case in distinct categories, e.g. a property BackColor that wraps the field backcolor. Rule 3@106 Synopsis: Use abbreviations with care Level: 10 Category: Naming 6
13 Do not contract words in identifiers, but do use well-known abbreviations. For example, do not use GetWin instead of GetWindow, but do use a well-known abbreviation such as UI instead of UserInterface. Rule 3@107 Synopsis: Do not use an underscore in identifiers Level: 8 Category: Naming Rule 3@108 Synopsis: Name an identifier according to its meaning and not its type Level: 6 Category: Naming Avoid using language specific terminology in names of identifiers. Example: Do not use a definition like: void Write(double doublevalue); Instead, use: void Write(double value); If it is absolutely required to have a uniquely named method for every data type, use Universal Type Names in the method names. The table below provides the mapping from C# types to Universal types. C# TYPE NAME UNIVERSAL TYPE NAME sbyte SByte byte Byte short Int16 ushort UInt16 int Int32 uint UInt32 long Int64 ulong UInt64 float Single double Double bool Boolean char Char string String object Object 7
14 Based on the example above, the corresponding reading methods may look like this: double ReadDouble(); long ReadInt64(); Philips Healthcare C# Coding Standard Rule Synopsis: Name namespaces according to a well-defined pattern Level: 8 Category: Naming Namespaces should be written in Pascal casing and named according to the following pattern: <company>.<technology>.<top-level component>.<bottom-level component> Rule 3@110 Synopsis: Do not add a suffix to a class or struct name Level: 9 Category: Naming Do not add suffixes like Struct or Class to the name of a class or struct. Exceptions: [3@122] and [3@401]. Rule 3@111 Synopsis: Use a noun or a noun phrase to name a class or struct Level: 8 Category: Naming Also, if the class involved is a derived class, it is a good practice to use a compound name. For example, if you have a class named Button, deriving from this class may result in a class named BeveledButton. 8
15 Rule Synopsis: Abbreviations with more than two letters should be cased as words Level: 9 Category: Naming Two-letter abbreviations in Pascal casing have both letters capitalized. In Camel casing this also holds true, except at the start of an identifier where both letters are written in lower case. With respect to capitalization in Pascal and Camel casing, abbreviations with more than two letters are treated as ordinary words. Related to: [3@102] Examples: Camel Casing Pascal Casing newimage NewImage uientry UIEntry pmsmr PmsMR dicomtype DicomType Rule 3@113 Synopsis: Prefix interfaces with the letter I Level: 8 Category: Naming All interfaces should be prefixed with the letter I. Use a noun (e.g. IComponent), noun phrase (e.g. ICustomAttributeProvider), or an adjective (e.g. IPersistable) to name an interface. Rule 3@120 Synopsis: Use similar names for the default implementation of an interface Level: 8 Category: Naming If you provide a default implementation for a particular interface, use a similar name for the implementing class. Notice that this only applies to classes that only implement that interface. Example: 9
16 A class implementing the IComponent interface could be called Component or DefaultComponent. Rule Synopsis: Suffix names of attributes with Attribute Level: 8 Category: Naming Although this is not required by the C# compiler, this convention is followed by all built-in attributes Rule 3@201 Synopsis: Do not add an enum suffix to an enumeration type Level: 9 Category: Naming See also [3@103] Rule 3@202 Synopsis: Use singular names for enumeration types Level: 7 Category: Naming For example, do not name an enumeration type Protocols but name it Protocol instead. Consider the following example in which only one option is allowed. public enum Protocol Tcp, Udp, Http, Ftp 10
17 Rule Philips Healthcare C# Coding Standard Synopsis: Use a plural name for enumerations representing bitfields Level: 7 Category: Naming Use a plural name for such enumeration types. The following code snippet is a good example of an enumeration that allows combining multiple options. [Flags] public enum SearchOptions CaseInsensitive = 0x01, WholeWordOnly = 0x02, AllDocuments = 0x04, Backwards = 0x08, AllowWildcards = 0x10 Rule 3@204 Synopsis: Do not use letters that can be mistaken for digits, and vice versa Level: 7 Category: Naming To create obfuscated code, use very short, meaningless names formed from the letters O, o, l, I and the digits 0 and 1. Anyone reading code like bool b001 = (lo == l0)? (I1 == 11) : (lol!= 101); will marvel at your creativity. Rule 3@301 Synopsis: Add EventHandler to delegates related to events Level: 9 Category: Naming Delegates that are used to define an event handler for an event must be suffixed with EventHandler. For example, the following declaration is correct for a Close event. public delegate CloseEventHandler(object sender, EventArgs arguments) 11
18 Rule Synopsis: Add Callback to delegates related to callback methods Level: 10 Category: Naming Delegates that are used to pass a reference to a callback method (so not an event) must be suffixed with Callback. For example: public delegate AsyncIOFinishedCallback(IpcClient client, string message); Rule 3@303 Synopsis: Do not add a Callback or similar suffix to callback methods Level: 9 Category: Naming Do not add suffixes like Callback or CB to indicate that methods are going to be called through a callback delegate. You cannot make assumptions on whether methods will be called through a delegate or not. An end-user may decide to use Asynchronous Delegate Invocation to execute the method. Rule 3@304 Synopsis: Use a verb (gerund) for naming an event Level: 10 Category: Naming Good examples of events are Closing, Minimizing, and Arriving. For example, the declaration for the Closing event may look like this: public event ClosingEventHandler Closing; Rule 3@305 Synopsis: Do not add an Event suffix (or any other type-related suffix) to the name of an event 12
19 Level: 9 Category: Naming See also [3@103]. Rule 3@306 Synopsis: Use an -ing and -ed form to express pre-events and post-events Level: 9 Category: Naming Do not use a pattern like BeginXxx and EndXxx. If you want to provide distinct events for expressing a point of time before and a point of time after a certain occurrence such as a validation event, do not use a pattern like BeforeValidation and AfterValidation. Instead, use a Validating and Validated pattern. Rule 3@307 Synopsis: Prefix an event handler with On Level: 6 Category: Naming It is good practice to prefix the method that is registered as an event handler with On. For example, a method that handles the Closing event should be named OnClosing(). In some situations, you might be faced with multiple classes exposing the same event name. To allow separate event handlers use a more intuitive name for the event handler, as long as it is prefixed with On. Rule 3@401 Synopsis: Suffix exception classes with Exception Level: 10 Category: Naming 13
20 Rule Philips Healthcare C# Coding Standard Synopsis: Do not add code-archive related prefixes to identifiers Level: 8 Category: Naming For example do not use code archive location (e.g. folder name) as a prefix for classes or fields. However, it is allowed to have some consistent naming scheme for related source files (e.g. belonging to a component or class hierarchy). Rule 3@501 Synopsis: Name DLL assemblies after their containing namespace Level: 8 Category: Naming To allow storing assemblies in the Global Assembly Cache, their names must be unique. Therefore, use the namespace name as a prefix of the name of the assembly. As an example, consider a group of classes organized under the namespace Philips.PmsMR.Platform.OSInterface. In that case, the assembly generated from those classes will be called Philips.PmsMR.Platform.OSInterface.dll. If multiple assemblies are built from the same namespace, it is allowed to append a unique postfix to the namespace name. Rule 3@503 Synopsis: Use Pascal casing for naming source files Level: 9 Category: Naming Do not use the underscore character and do not use casing to differentiate names of files. Rule 3@504 Synopsis: Name the source file to the main class 14
21 Level: 7 Category: Naming In addition, do not put more than one major class plus its auxiliary classes (such as EventArgs-derived classes) in one source file. Exception: If a partial class is used, then the other files for this class can be named as MainClass.PostFix.cs, whereby Postfix is a meaningful name which describes the contents and not just MainClass.2.cs. Example: MyForm.cs and MyForm.Designer.cs. 15
22 Comments and embedded documentation (Comments) Rules Each file shall contain a header block 4@103 Use // for comments 4@105 All comments shall be written in US English 4@106 Use XML tags for documenting types and members Rule 4@101 Synopsis: Each file shall contain a header block Level: 10 Category: Comments The header block must consist of a #region block containing the following copyright statement and the name of the file. #region Copyright Koninklijke Philips Electronics N.V // // All rights are reserved. Reproduction or transmission in whole or in part, in // any form or by any means, electronic, mechanical or otherwise, is prohibited // without the prior written consent of the copyright owner. // // Filename: PatientAdministration.cs // #endregion Rule 4@103 Synopsis: Use // for comments Level: 9 Category: Comments Rule 4@105 Synopsis: All comments shall be written in US English Level: 10 Category: Comments 16
23 See also Rule Synopsis: Use XML tags for documenting types and members Level: 9 Category: Comments All public and protected types, methods, fields, events, delegates, etc. shall be documented using XML tags. Using these tags will allow IntelliSense to provide useful details while using the types. Also, automatic documentation generation tooling relies on these tags. Section tags define the different sections within the type documentation. SECTION TAGS DESCRIPTION LOCATION <summary> Short description type or member <remarks> Describes preconditions and other additional information. type or member <param> Describes the parameters of a method method <returns> Describes the return value of a method method <exception> Lists the exceptions that a method or property can throw method, even or property <value> <example> Describes the type of the data a property accepts and/or returns Contains examples (code or text) related to a member or a type property type or member <seealso> Adds an entry to the See Also section type or member <overloads> Provides a summary for multiple overloads of a method Inline tags can be used within the section tags. INLINE TAGS <see> DESCRIPTION Creates a hyperlink to another member or type <paramref> Creates a checked reference to a parameter Markup tags are used to apply special formatting to a part of a section. MARKUP TAGS <code> <c> <para> <list> <b> <i> Exception: DESCRIPTION Changes the indentation policy for code examples Changes the font to a fixed-wide font (often used with the <code> tag) Creates a new paragraph Creates a bulleted list, numbered list, or a table Bold typeface Italics typeface first method in a overload list. 17
24 In an inheritance hierarchy, do not repeat the documentation but use the <see> tag to refer to the base class or interface member. Exception: Philips Healthcare C# Coding Standard Private and nested classes do not have to be documented in this manner. 18
25 Object lifecycle (Object lifecycle) Rules Declare and initialize variables close to where they are used If possible, initialize variables at the point of declaration Use a public static read-only field to define predefined object instances 5@107 Set a reference field to null to tell the garbage collector that the object is no longer needed 5@108 Do not `shadow? a name in an outer scope 5@111 Avoid implementing a destructor 5@112 If a destructor is needed, also use GC.SuppressFinalize 5@113 Implement IDisposable if a class uses unmanaged/expensive resources or owns disposable objects 5@114 Do not access any reference type members in the destructor 5@116 Always document when a member returns a copy of a reference type or array Rule 5@101 Synopsis: Declare and initialize variables close to where they are used Level: 7 Category: Object lifecycle Rule 5@102 Synopsis: If possible, initialize variables at the point of declaration Level: 7 Category: Object lifecycle Avoid the C style where all variables have to be defined at the beginning of a block, but rather define and initialize each variable at the point where it is needed. Rule 5@106 Synopsis: Use a public static read-only field to define predefined object instances Level: 4 Category: Object lifecycle 19
26 For example, consider a Color class/struct that expresses a certain color internally as red, green, and blue components, and this class has a constructor taking a numeric value, then this class may expose several predefined colors like this. public struct Color public static readonly Color Red = new Color(0xFF0000); public static readonly Color Black = new Color(0x000000); public static readonly Color White = new Color(0xFFFFFF); public Color(int rgb) // implementation Rule 5@107 Synopsis: Set a reference field to null to tell the garbage collector that the object is no longer needed Level: 4 Category: Object lifecycle Setting reference fields to null may improve memory usage because the object involved will be unreferenced from that point on, allowing the garbage collector (GC) to clean-up the object much earlier. Please note that this rule does not have to be followed for a variable that is about to go out of scope. Rule 5@108 Synopsis: Do not `shadow? a name in an outer scope Level: 2 Category: Object lifecycle Repeating a name that already occurs in an outer scope is seldom intended and may be surprising in maintenance, although the behaviour is well-defined. Exception: int foo = something;? if (whatever) double foo = 12.34; double anotherfoo = foo; // Violation. 20
27 In case a method parameter has the same name as a field then the following construction can be used: this.x = x int foo = something;? public void SomeMethod(int foo) this.foo = foo; // No violation int anotherfoo = foo; // However, this again is a violation! Rule 5@111 Synopsis: Avoid implementing a destructor Level: 4 Category: Object lifecycle If a destructor is required, adhere to Rule 5@112 and Rule 5@113. The use of destructors in C# is demoted since it introduces a severe performance penalty due to way the garbage collector works. It is also a bad design pattern to clean up any resources in the destructor since you cannot predict at which time the destructor is called (in other words, it is non-deterministic). Notice that C# destructors are not really destructors as in C++. They are just a C# compiler feature to represent CLR Finalizers. Rule 5@112 Synopsis: If a destructor is needed, also use GC.SuppressFinalize Level: 3 Category: Object lifecycle If a destructor is needed to verify that a user has called certain cleanup methods such as Close() on a IpcPeer object, call GC.SuppressFinalize in the Close() method. This ensures that the destructor is ignored if the user is properly using the class. The following snippet illustrates this pattern. public class IpcPeer bool connected = false; public void Connect() // Do some work and then change the state of this object. connected = true; public void Close() 21
28 // Close the connection, change the state, and instruct garbage collector // not to call the destructor. connected = false; GC.SuppressFinalize(this); ~IpcPeer() // If the destructor is called, then Close() was not called. if (connected) // Warning! User has not called Close(). Notice that you can?t // call Close() from here because the objects involved may // have already been garbage collected (see Rule 5@113). Rule 5@113 Synopsis: Implement IDisposable if a class uses unmanaged/expensive resources or owns disposable objects Level: 2 Category: Object lifecycle If a class uses unmanaged resources such as objects returned by C/C++ DLLs, or expensive resources that must be disposed of as soon as possible, you must implement the IDisposable interface to allow class users to explicitly release such resources. A class should implement the IDisposable interface, in case it creates instances of objects that implement the IDisposable interfaces and a reference to that instances is kept (note that if the class transfer ownership of the create instance to another object, then it doesn't need to implement IDisposable). The follow code snippet shows the pattern to use for such scenarios. public class ResourceHolder : IDisposable ///<summary> ///Implementation of the IDisposable interface ///</summary> public void Dispose() // Call internal Dispose(bool) Dispose(true); // Prevent the destructor from being called GC.SuppressFinalize(this); ///<summary> /// Central method for cleaning up resources ///</summary> protected virtual void Dispose(bool disposing) // If disposing is true, then this method was called through the // public Dispose() 22
29 if (disposing) // Release or cleanup managed resources // Always release or cleanup (any) unmanaged resources ~ResourceHolder() // Since other managed objects are disposed automatically, we // should not try to dispose any managed resources (see Rule // We therefore pass false to Dispose() Dispose(false); If another class derives from this class, then this class should only override the Dispose(bool) method of the base class. It should not implement IDisposable itself, nor provide a destructor. The base class?s `destructor? is automatically called. public class DerivedResourceHolder : ResourceHolder protected override void Dispose(bool disposing) if (disposing) // Release or cleanup managed resources of this derived // class only. // Always release or cleanup (any) unmanaged resources. // Call Dispose on our base class. base.dispose(disposing); Rule 5@114 Synopsis: Do not access any reference type members in the destructor Level: 2 Category: Object lifecycle When the destructor is called by the garbage collector, it is very possible that some or all of the objects referenced by class members are already garbage collected, so dereferencing those objects may cause exceptions to be thrown. Only value type members can be accessed (since they live on the stack). Rule 5@116 Synopsis: Always document when a member returns a copy of a reference type or array Level: 5 Category: Object lifecycle 23
30 By default, all members that need to return an internal object or an array of objects will return a reference to that object or array. In some cases, it is safer to return a copy of an object or an array of objects. In such case, always clearly document this in the specification. 24
31 Control flow (Control flow) Rules Do not change a loop variable inside a for loop block 6@102 Update loop variables close to where the loop condition is specified 6@103 All flow control primitives (if, else, while, for, do, switch) shall be followed by a block, even if it is empty 6@105 All switch statements shall have a default label as the last case label 6@106 An else sub-statement of an if statement shall not be an if statement without an else part 6@109 Avoid multiple or conditional return statements 6@112 Do not make explicit comparisons to true or false 6@115 Do not access a modified object more than once in an expression 6@118 Do not use selection statements (if, switch) instead of a simple assignment or initialization Rule 6@101 Synopsis: Do not change a loop variable inside a for loop block Level: 2 Category: Control flow Updating the loop variable within the loop body is generally considered confusing, even more so if the loop variable is modified in more than one place. This rule also applies to foreach loops. Rule 6@102 Synopsis: Update loop variables close to where the loop condition is specified Level: 4 Category: Control flow This makes understanding the loop much easier. Rule 6@103 Synopsis: All flow control primitives (if, else, while, for, do, switch) shall be followed by a block, even if it is empty Level: 3 Category: Control flow 25
32 Example 1: Example 2: if (DoAction()) result = true; // Count number of elements in array. for (int i = 0; i < y; i++) Exceptions: an "else" statement may directly followed by another "if" An if clause, followed by a single statement, does not have to enclose that single statement in a block, provided that the entire statement is written on a single line. Of course the exception is intended for those cases where it improves readability. Please note that the entire statement must be a one-liner (of reasonable length), so it is not applicable to complex conditions. Also note that the exception is only made for if (without else), not for while etc. Examples: if (failure) throw new InvalidOperationException("Failure!"); if (x < 10) x = 0; Rationale for the exception: code readability can be improved because the one-liner saves vertical space (by a factor of 4). The lurking danger in later maintenance, where someone might add a statement intending it to be subject to the condition, is absent in the one-liner. Rule 6@105 Synopsis: All switch statements shall have a default label as the last case label Level: 2 Category: Control flow A comment such as?no action? is recommended where this is the explicit intention. If the default case should be unreachable, an assertion to this effect is recommended. If the default label is always the last one, it is easy to locate. Rule 6@106 Synopsis: An else sub-statement of an if statement shall not be an if statement without an else part 26
33 Level: 5 Category: Control flow The intention of this rule, which applies to else-if constructs, is the same as in [6@105]. Consider the following example. void Foo(string answer) if ("no" == answer) Console.WriteLine("You answered with No"); else if ("yes" == answer) Console.WriteLine("You answered with Yes"); else // This block is required, even though you might not care of any other // answers than "yes" and "no". Rule 6@109 Synopsis: Avoid multiple or conditional return statements Level: 9 Category: Control flow One entry, one exit is a sound principle and keeps control flow simple. However, if some cases, such as when preconditions are checked, it may be good practice to exit a method immediately when a certain precondition is not met. Rule 6@112 Synopsis: Do not make explicit comparisons to true or false Level: 9 Category: Control flow It is usually bad style to compare a bool-type expression to true or false. Example: while (condition == false) // wrong; bad style while (condition!= true) // also wrong while (((condition == true) == true) == true) // where do you stop? 27
34 while (condition) // OK Rule Synopsis: Do not access a modified object more than once in an expression Level: 5 Category: Control flow The evaluation order of sub-expressions within an expression is defined in C#, in contrast to C or C++, but such code is hard to understand. Example: v[i] = ++c; v[i] = ++i; i = i + 1; i = ++i + 1; // right // wrong: is v[i] or v[++i] being assigned to? // right // wrong and useless; i += 2 would be clearer Rule 6@118 Synopsis: Do not use selection statements (if, switch) instead of a simple assignment or initialization Level: 5 Category: Control flow Express your intentions directly. For example, rather than bool pos; if (val > 0) pos = true; else pos = false; or (slightly better) write bool pos = (val > 0)? true : false; bool pos; pos = (val > 0); // single assignment or even better 28
35 bool pos = (val > 0); // initialization 29
36 Object oriented programming (Object oriented) Rules Declare all fields (data members) private Provide a default private constructor if there are only static methods and properties on a class 7@105 Explicitly define a protected constructor on an abstract base class 7@201 Selection statements (if-else and switch) should be used when the control flow depends on an object's value; dynamic binding should be used when the control flow depends on the object's type 7@301 All variants of an overloaded method shall be used for the same purpose and have similar behavior 7@303 If you must provide the ability to override a method, make only the most complete overload virtual and define the other operations in terms of it 7@402 Use code to describe preconditions, postconditions, exceptions, and class invariants 7@403 It shall be possible to use a reference to an object of a derived class wherever a reference to that object?s base class object is used 7@501 Do not overload any `modifying? operators on a class type 7@502 Do not modify the value of any of the operands in the implementation of an overloaded operator 7@504 Use a struct when value semantics are desired 7@520 Implement the GetHashCode method whenever you implement the Equals method 7@521 Override the Equals method whenever you implement the == operator, and make them do the same thing 7@522 Override the Equals method any time you implement the IComparable Interface 7@525 Consider implementing the Equals method on value types 7@526 Reference types should not override the equality operator (==) 7@530 Consider implementing operator overloading for the equality (==), not equal (!=), less than (<), and greater than (>) operators when you implement IComparable 7@531 Consider overloading the equality operator (==), when you overload the addition (+) operator and/or subtraction (-) operator 7@532 Consider implementing all relational operators (<, <=, >, >=) if you implement any 7@601 Allow properties to be set in any order 7@602 Use a property rather than a method when the member is a logical data member 7@603 Use a method rather than a property when this is more appropriate 7@604 Do not create a constructor that does not yield a fully initialized object 7@608 Always check the result of an as operation Rule 7@101 Synopsis: Declare all fields (data members) private Level: 2 Category: Object oriented An honored principle, stated in both [C++ Coding Standard] and [MS Design]. 30
37 Exceptions to this rule are static readonly fields and const fields, which may have any accessibility deemed appropriate. See also Rule Synopsis: Provide a default private constructor if there are only static methods and properties on a class Level: 5 Category: Object oriented Instantiating such a class is pointless. Exceptions: In case the class is defined as static, then the private constructor is not required. In case the class is defined as abstract, then the protected constructor is required, see [7@105]. Rule 7@105 Synopsis: Explicitly define a protected constructor on an abstract base class Level: 3 Category: Object oriented Of course an abstract class cannot be instantiated, so a public constructor should be harmless. However, [MS Design] states: Many compilers will insert a public or protected constructor if you do not. Therefore, for better documentation and readability of your source code, you should explicitly define a protected constructor on all abstract classes. Rule 7@201 Synopsis: Selection statements (if-else and switch) should be used when the control flow depends on an object's value; dynamic binding should be used when the control flow depends on the object's type Level: 9 Category: Object oriented 31
38 This is a general OO principle. Please note that it is usually a design error to write a selection statement that queries the type of an object (keywords typeof, is). Exception: Using a selection statement to determine if some object implements one or more optional interfaces is a valid construct though. Rule 7@301 Synopsis: All variants of an overloaded method shall be used for the same purpose and have similar behavior Level: 3 Category: Object oriented Doing otherwise is against the Principle of Least Surprise. Rule 7@303 Synopsis: If you must provide the ability to override a method, make only the most complete overload virtual and define the other operations in terms of it Level: 6 Category: Object oriented Using the pattern illustrated below requires a derived class to only override the virtual method. Since all the other methods are implemented by calling the most complete overload, they will automatically use the new implementation provided by the derived class. public class MultipleOverrideDemo private string sometext; public MultipleOverrideDemo(string s) this.sometext = s; public int IndexOf(string s) return IndexOf(s, 0); public int IndexOf(string s, int startindex) return IndexOf(s, startindex, sometext.length - startindex ); 32
39 // Use virtual for this one. public virtual int IndexOf(string s, int startindex, int count) return sometext.indexof(s, startindex, count); An even better approach, not required by this coding standard, is to refrain from making virtual methods public, but to give them protected accessibility, changing the sample above into: public class MultipleOverrideDemo // same as above... public int IndexOf(string s, int startindex, int count) return InternalIndexOf(s, startindex, count); // Use virtual for this one. protected virtual int InternalIndexOf(string s, int startindex, int count) return sometext.indexof(s, startindex, count); Rule Synopsis: Use code to describe preconditions, postconditions, exceptions, and class invariants Level: 10 Category: Object oriented Compilable preconditions etc. are testable and longer lasting than just comments. The exact form (e.g. assertions, special Design By Contract functions such as require and ensure) is not discussed here. Rule Synopsis: It shall be possible to use a reference to an object of a derived class wherever a reference to that object?s base class object is used Level: 3 Category: Object oriented This rule is known as the Liskov Substitution Principle, (see [Liskov 88]), often abbreviated to LSP. Please note that an interface is also regarded as a base class in this context. 33
40 Rule Synopsis: Do not overload any `modifying? operators on a class type Level: 6 Category: Object oriented In this context the `modifying? operators are those that have a corresponding assignment operator, i.e. the non-unary versions of +, -, *, /, %, &,, ^, << and >>. There is very little literature regarding operator overloading in C#. Therefore it is wise to approach this feature with some caution. Overloading operators on a struct type is good practice, since it is a value type. The,code>class is a reference type and users will probably expect reference semantics, which are not provided by most operators. Consider a class Foo with an overloaded operator+(int), and thus an impicitly overloaded operator+=(int). If we define the function AddTwenty as follows: public static void AddTwenty (Foo f) f += 20; Then this function has no net effect: Foo bar = new Foo(5); AddTwenty (bar); // note that `bar? is unchanged // the Foo object with value 25 is on its way to the GC... The exception to this rule is a class type that has complete value semantics, like System.String. Rule 7@502 Synopsis: Do not modify the value of any of the operands in the implementation of an overloaded operator Level: 1 Category: Object oriented This rule can be found in a non-normative clause of [C# Lang], section Breaking this rule gives counter-intuitive results. 34
41 Rule Philips Healthcare C# Coding Standard Synopsis: Use a struct when value semantics are desired Level: 6 Category: Object oriented More precisely, a struct should be considered for types that meet any of the following criteria: Act like primitive types. Have an instance size under ±16 bytes. Are immutable. Value semantics are desirable. Remember that a struct cannot be derived from. Rule 7@520 Synopsis: Implement the GetHashCode method whenever you implement the Equals method Level: 1 Category: Object oriented This keeps GetHashCode and Equals synchronized. Rule 7@521 Synopsis: Override the Equals method whenever you implement the == operator, and make them do the same thing Level: 1 Category: Object oriented This allows infrastructure code such as Hashtable and ArrayList, which use the Equals method, to behave the same way as user code written using the equality operator. Note: For value types, the other way around applies also, i.e., whenever you override the Equals method, then also also implement the equality operator. 35
42 Rule Philips Healthcare C# Coding Standard Synopsis: Override the Equals method any time you implement the IComparable Interface Level: 1 Category: Object oriented Rule 7@525 Synopsis: Consider implementing the Equals method on value types Level: 3 Category: Object oriented On value types the default implementation on System.ValueType will not perform as well as your custom implementation. Rule 7@526 Synopsis: Reference types should not override the equality operator (==) Level: 1 Category: Object oriented The default implementation is sufficient. Rule 7@530 Synopsis: Consider implementing operator overloading for the equality (==), not equal (!=), less than (<), and greater than (>) operators when you implement IComparable Level: 3 Category: Object oriented Rule 7@531 Synopsis: Consider overloading the equality operator (==), when you overload the addition (+) operator and/or subtraction (-) operator Level: 2 Category: Object oriented 36
43 Rule Philips Healthcare C# Coding Standard Synopsis: Consider implementing all relational operators (<, <=, >, >=) if you implement any Level: 2 Category: Object oriented Rule 7@601 Synopsis: Allow properties to be set in any order Level: 4 Category: Object oriented Properties should be stateless with respect to other properties, i.e. there should not be an observable difference between first setting property A and then B and its reverse. Rule 7@602 Synopsis: Use a property rather than a method when the member is a logical data member Level: 9 Category: Object oriented Rule 7@603 Synopsis: Use a method rather than a property when this is more appropriate Level: 9 Category: Object oriented In some cases a method is better than a property: The operation is a conversion, such as Object.ToString. The operation is expensive enough that you want to communicate to the user that they should consider caching the result. Obtaining a property value using the get accessor would have an observable side effect. Calling the member twice in succession produces different results. The order of execution is important. See [7@601]. The member is static but returns a value that can be changed. The member returns a copy of an internal array or other reference type. Only a set accessor would be supplied. Write-only properties tend to be confusing. 37
44 Rule Philips Healthcare C# Coding Standard Synopsis: Do not create a constructor that does not yield a fully initialized object Level: 2 Category: Object oriented Only create constructors that construct objects that are fully initialized. There shall be no need to set additional properties. A private constructor is exempt from this rule. Rule 7@608 Synopsis: Always check the result of an as operation Level: 2 Category: Object oriented If you use as to obtain a certain interface reference from an object, always ensure that this operation does not return null. Failure to do so may cause a NullReferenceException at a later stage if the object did not implement that interface. 38
45 Exceptions (Exceptions) Rules Only throw exceptions in exceptional situations Do not throw exceptions from unexpected locations Only re-throw exceptions when you want to specialize the exception List the explicit exceptions a method or property can throw 8@105 Always log that an exception is thrown 8@106 Allow callers to prevent exceptions by providing a method or property that returns the object?s state 8@107 Use standard exceptions 8@108 Throw informational exceptions 8@109 Throw the most specific exception possible 8@110 Only catch the exceptions explicitly mentioned in the documentation 8@202 Provide common constructors for custom exceptions 8@203 Avoid side-effects when throwing recoverable exceptions 8@204 Do not throw an exception from inside an exception constructor Rule 8@101 Synopsis: Only throw exceptions in exceptional situations Level: 3 Category: Exceptions Do not throw exceptions in situations that are normal or expected (e.g. end-of-file). Use return values or status enumerations instead. In general, try to design classes that do not throw exceptions in the normal flow of control. However, do throw exceptions that a user is not allowed to catch when a situation occurs that may indicate a design error in the way your class is used. Rule 8@102 Synopsis: Do not throw exceptions from unexpected locations Level: 1 Category: Exceptions Throwing an exception from some locations are unexpected and can cause problems. For example when you call an exception from inside a destructor, the CLR will stop executing the destructor, and pass the exception to the base class destructor (if any). If there is no base class, then the destructor is discarded. Do not throw exceptions from the following locations: 39
46 Location Event accessor methods Equals methods GetHashCode() methods ToString methods Static constructors Finalizers (destructors) Dispose methods Equality Operators (==,!=) Implicit cast operators Exception constructor Note The followings exceptions are allowed: System.InvalidOperationException, System.NotSupportedException and System.ArgumentException. This also includes their derivates. An Equals method should return true or false. Return false instead of an exception if the arguments to not match. GetHashCode() should always return a value, otherwise you lose values in a hash table. This method is also used by the debugger to display information about objects in a string format. Therefore it should not raise an exception. A type becomes unusable if an exception is thrown from its static constructor. Throwing an exception from a finalizer can cause a process to crash. Dispose methods are often called in finally clauses as part of cleanup. Also Dispose(false) is called from a finalizer, which in itself should not throw an exception als. Like the Equals methods, the operators should always return true or false. A user is usually unaware that an implicit cast operators is called, therefore throwing an exception from them is unexpected and should not be done. Calling a exception constructor is done to throw an exception. If the constructor throws an exception, then this is confusing. Rule 8@103 Synopsis: Only re-throw exceptions when you want to specialize the exception Level: 3 Category: Exceptions Only catch and re-throw exceptions if you want to add additional information and/or change the type of the exception into a more specific exception. In the latter case, set the InnerException property of the new exception to the caught exception. Rule 8@104 Synopsis: List the explicit exceptions a method or property can throw Level: 8 Category: Exceptions Describe the recoverable exceptions using the <exception> tag. 40
47 Explicit exceptions are the ones that a method or property explicitly throws from its implementation and which users are allowed to catch. Exceptions thrown by.net framework classes and methods used by this implementation do not have to be listed here. Rule 8@105 Synopsis: Always log that an exception is thrown Level: 8 Category: Exceptions Logging ensures that if the caller catches your exception and discards it, traces of this exception can be recovered at a later stage. Rule 8@106 Synopsis: Allow callers to prevent exceptions by providing a method or property that returns the object?s state Level: 8 Category: Exceptions For example, consider a communication layer that will throw an InvalidOperationException when an attempt is made to call Send() when no connection is available. To allow preventing such a situation, provide a property such as Connected to allow the caller to determine if a connection is available before attempting an operation. Rule 8@107 Synopsis: Use standard exceptions Level: 3 Category: Exceptions The following list of exceptions are too generic and should not be raised directly by your code: System.Exception System.ApplicationException Any exception which is reserved for use by the CLR only (check MSDN for this) 41
48 The.NET framework already provides a set of common exceptions. The table below summarizes the most common exceptions that are available for applications. EXCEPTION IndexOutOfRangeException InvalidOperationException NotSupportedException ArgumentException ArgumentNullException Philips Healthcare C# Coding Standard CONDITION Indexing an array or indexable collection outside its valid range. An action is performed which is not valid considering the object?s current state. An action is performed which is may be valid in the future, but is not supported. An incorrect argument is supplied. A null reference is supplied as a method?s parameter that does not allow null. ArgumentOutOfRangeException An argument is not within the required range. Rule 8@108 Synopsis: Throw informational exceptions Level: 6 Category: Exceptions When you instantiate a new exception, set its Message property to a descriptive message that will help the caller to diagnose the problem. For example, if an argument was incorrect, indicate which argument was the cause of the problem. Also mention the name (if available) of the object involved. Also, if you design a new exception class, note that it is possible to add custom properties that can provide additional details to the caller. Rule 8@109 Synopsis: Throw the most specific exception possible Level: 6 Category: Exceptions Do not throw a generic exception if a more specific one is available (related to [Rec:8@108]). Rule 8@110 Synopsis: Only catch the exceptions explicitly mentioned in the documentation Level: 1 42
49 Category: Exceptions Moreover, do not catch the base class Exception, SystemException or ApplicationException. Exceptions of those classes generally mean that a non-recoverable problem has occurred. Exception: It is allowed to catch one of the mentioned base exceptions, if it is rethrown at the end of the catch block. In order to preserve the stack details, use "throw;". Example: try... catch (Exception e)... // For example do some logging here or close some resource. throw; Rule 8@202 Synopsis: Provide common constructors for custom exceptions Level: 5 Category: Exceptions It is advised to provide the three common constructors that all standard exceptions provide as well. These include: XxxException() XxxException(string message) XxxException(string message, Exception innerexception) Rule 8@203 Synopsis: Avoid side-effects when throwing recoverable exceptions Level: 1 Category: Exceptions When you throw a recoverable exception, make sure that the object involved stays in a usable and predictable state. With usable it is meant that the caller can catch the exception, take any necessary actions, and continue to use the object again. With predictable is meant that the caller can make logical assumptions on the state of 43
50 the object. For instance, if during the process of adding a new item to a list, an exception is raised, then the caller may safely assume that the item has not been added, and another attempt to re-add it is possible. Rule 8@204 Synopsis: Do not throw an exception from inside an exception constructor Level: 1 Category: Exceptions Throwing an exception from inside an exception's constructor will stop the construction of the exception being built, and hence, preventing the exception from getting thrown. The other exception is thrown, but this can be confusing to the user of the class or method concerned. 44
51 Delegates and events (Delegates and events) Rules Do not make assumptions on the object's state after raising an event Always document from which thread an event handler is called Raise events through a protected virtual method 9@104 Use the sender/arguments signature for event handlers 9@105 Implement add/remove accessors if the number of handlers for an event must be limited 9@106 Consider providing property-changed events 9@107 Consider an interface instead of a delegate 9@108 Use delegate inference instead of explicit delegate instantiation when possible 9@110 Each subscribe must have a corresponding unsubscribe Rule 9@101 Synopsis: Do not make assumptions on the object's state after raising an event Level: 2 Category: Delegates and events Prepare for any changes to the current object's state while executing an event handler. The event handler may have called other methods or properties that changed the object?s state (e.g. it may have disposed objects referenced through a field). Rule 9@102 Synopsis: Always document from which thread an event handler is called Level: 9 Category: Delegates and events Some classes create a dedicated thread or use the Thread Pool to perform some work, and then raise an event. The consequence of that is that an event handler is executed from another thread than the main thread. For such an event, the event handler must synchronize (ensure thread-safety) access to shared data (e.g. instance members). Rule 9@103 Synopsis: Raise events through a protected virtual method 45
52 Level: 9 Category: Delegates and events If a derived class wants to intercept an event, it can override such a virtual method, do its own work, and then decide whether or not to call the base class version (whether or not this should be done, is mentioned by the base class documentation). Since the derived class may decide not to call the base class method, ensure that it does not do any work required for the base class to function properly. Name this method OnEventName, where EventName should be replaced with the name of the event. Notice that an event handler uses the same naming scheme but has a different signature. The following snippet (most parts left out for brevity) illustrates the difference between the two. ///<summary>an example class</summary> public class Connection // Event definition public event EventHandler Closed; // Method that causes the event to occur public void Close() // Do something and then raise the event OnClosed(EventArgs.Empty); // Method that raises the Closed event. protected virtual OnClosed(EventArgs args) if (Closed!= null) Closed(this, args); ///<summary>main entrypoint.</summary> public static void Main() Connection connection = new Connection(); connection.closed += new EventHandler(OnClosed); // For.NET 2 // connection.closed += OnClosed; ///<summary>event handler for the Closed event</summary> private static void OnClosed(object sender, EventArgs args)... Rule 9@104 Synopsis: Use the sender/arguments signature for event handlers Level: 6 Category: Delegates and events 46
53 The goal of this rule is to have a consistent signature for all event handlers. In general, the event handler?s signature should look like this public delegate void MyEventHandler(object sender, EventArgs arguments) Using the base class as the sender type allows derived classes to reuse the same event handler. The same applies to the arguments parameter. It is recommended to derive from the.net Framework?s EventArgs class and add your own event data. Using such a class prevents cluttering the event handler?s signature, allows extending the event data without breaking any existing users, and can accommodate multiple return values (instead of using reference fields). Moreover, all event data should be exposed through properties, because that allows for verification and preventing access to data that is not always valid in all occurrences of a certain event. Note: If possible use the generic EventHandler instead of defining your own EventHandler delegate. Rule 9@105 Synopsis: Implement add/remove accessors if the number of handlers for an event must be limited Level: 8 Category: Delegates and events If you implement the add and remove accessors of an event, then the CLR will call those accessors when an event handler is added or removed. This allows limiting the number of allowed event handlers, or to check for certain preconditions. Rule 9@106 Synopsis: Consider providing property-changed events Level: 9 Category: Delegates and events Consider providing events that are raised when certain properties are changed. Such an event should be named PropertyChanged, where Property should be replaced with the name of the property with which this event is associated. Rule 9@107 Synopsis: Consider an interface instead of a delegate 47
54 Level: 9 Category: Delegates and events If you provide a method as the target for a delegate, the compiler will only ensure that the method signature matches the delegate's signature. This means that if you have two classes providing a delegate with the same signature and the same name, and each class has a method as a target for that delegate, it is possible to provide the method of the first class as a target for the delegate in the other class, even though they might not be related at all. Therefore, it is sometimes better to use interfaces. The compiler will ensure that you cannot accidentally provide a class implementing a certain interface to a method that accepts another interface that happens to have to same name. Rule 9@108 Synopsis: Use delegate inference instead of explicit delegate instantiation when possible Level: 9 Category: Delegates and events Using delegate inference for subscribing to and unsubscribing from event, code can be made much more elegant than the old previous way, which was like: someclass.someevent += new EventHandler(OnHandleSomeEvent); private void OnHandleSomeEvent(object sender, EventArgs e)... This can now be replaced by: someclass.someevent += OnHandleSomeEvent; private void OnHandleSomeEvent(object sender, EventArgs e)... Note: this only applies to code written in C# 2.0 and higher. Rule 9@110 Synopsis: Each subscribe must have a corresponding unsubscribe Level: 2 Category: Delegates and events Subscribing to an event gives the object that sends the event, a reference to the subscribed object. If the subscribed object does not unsubscribe once that is not needed, then it will still be called. If for example, the 48
55 subscribed object is disposed, then the event still is called on that disposed object (which usually is not intended), and also it is not garbage collected. Therefore it is good to ensure that for each subscribe that is done, also an unsubscribe is done, once listening to that event is no longer needed. The Dispose() implementation could be used to ensuring that all unsubscribes are done. 49
56 Various data types (Data types) Rules Use an enum to strongly type parameters, properties, and return types Use the default type Int32 as the underlying type of an enum unless there is a reason to use Int64 10@203 Use the [Flags] attribute on an enum if a bitwise operation is to be performed on the numeric values 10@301 Do not use?magic numbers? 10@401 Floating point values shall not be compared using either the ==,!=, >=, <= operators and Equals method. 10@403 Do not cast types where a loss of precision is possible 10@404 Only implement casts that operate on the complete object 10@405 Do not generate a semantically different value with a cast 10@406 When using composite formatting, do supply all objects referenced in the format string 10@407 When using composite formatting, do not supply any object unless it is referenced in the format string Rule 10@201 Synopsis: Use an enum to strongly type parameters, properties, and return types Level: 6 Category: Data types This enhances clarity and type-safety. Try to avoid casting between enumerated types and integral types. Exception: In some cases, such as when databases or PII interfaces that store values as ints are involved, using enums will result in an unacceptable amount of casting. In that case, it is better to use a const int construction. Rule 10@202 Synopsis: Use the default type Int32 as the underlying type of an enum unless there is a reason to use Int64 Level: 5 Category: Data types If the enum represents flags and there are currently more than 32 flags, or the enum might grow to that many flags in the future, use Int64. 50
57 Do not use any other underlying type because the Operating System will try to align an enum on 32-bit or 64-bit boundaries (depending on the hardware platform). Using a 8-bit or 16-bit type may result in a performance loss. Rule 10@203 Synopsis: Use the [Flags] attribute on an enum if a bitwise operation is to be performed on the numeric values Level: 7 Category: Data types It is good practice to use the Flags attribute for documenting that the enumeration is intended for combinations. Also using this attribute provides an implementation of the ToString method, which displays the values in their original names instead of the values. Example: FileInfo file = new FileInfo(fileName); file.attributes = FileAttributes.Hidden FileAttributes.ReadOnly; Console.WriteLine("file.Attributes = 0", file.attributes.tostring()); The printed result will be ReadOnly Hidden. Use an enum with the flags attribute only if the value can be completely expressed as a set of bit flags. Do not use an enum for open sets (such as the operating system version). Use a plural name for such an enum, as stated in [3@203]. Example: [Flags] public enum AccessPrivileges Read = 0x1, Write = 0x2, Append = 0x4, Delete = 0x8, All = Read Write Append Delete Rule 10@301 Synopsis: Do not use?magic numbers? Level: 7 Category: Data types 51
58 Do not use literal values, either numeric or strings, in your code other than to define symbolic constants. Use the following pattern to define constants: public class Whatever public static readonly Color PapayaWhip = new Color(0xFFEFD5); public const int MaxNumberOfWheels = 18; There are exceptions: the values 0, 1 and null can nearly always be used safely. Very often the values 2 and -1 are OK as well. Strings intended for logging or tracing are exempt from this rule. Literals are allowed when their meaning is clear from the context, and not subject to future changes. mean = (a + b) / 2; WaitMilliseconds(waitTimeInSeconds * 1000); // okay // clear enough If the value of one constant depends on the value of another, do attempt to make this explicit in the code, so do not write public class SomeSpecialContainer public const int MaxItems = 32; public const int HighWaterMark = 24; // at 75%... but rather do write public class SomeSpecialContainer public const int MaxItems = 32; public const int HighWaterMark = 3 * MaxItems / 4; // at 75%... Please note that an enum can often be used for certain types of symbolic constants Rule 10@401 Synopsis: Floating point values shall not be compared using either the ==,!=, >=, <= operators and Equals method. Level: 2 Category: Data types Most floating point values have no exact binary representation and have a limited precision. Use the following instead: Math.Abs(x - y) < Single.Epsilon Exception: When a floating point variable is explicitly initialized with a value such as 1.0 or 0.0, and then checked for a 52
59 change at a later stage. Rule 10@403 Synopsis: Do not cast types where a loss of precision is possible Level: 1 Category: Data types For example, do not cast a long (64-bit) to an int (32-bit), unless you can guarantee that the value of the long is small enough to fit in the int. Rule 10@404 Synopsis: Only implement casts that operate on the complete object Level: 2 Category: Data types In other words, do not cast one type to another using a member of the source type. For example, a Button class has a string property Name. It is valid to cast the Button to the Control (since Button is a Control), but it is not valid to cast the Button to a string by returning the value of the Name property. Rule 10@405 Synopsis: Do not generate a semantically different value with a cast Level: 2 Category: Data types For example, it is appropriate to convert a Time or TimeSpan into an Int32. The Int32 still represents the time or duration. It does not, however, make sense to convert a file name string such as c:\mybitmap.gif into a Bitmap object. Rule 10@406 Synopsis: When using composite formatting, do supply all objects referenced in the format string 53
60 Level: 1 Category: Data types Composite formatting, e.g. in String.Format, uses indexed placeholders that must correspond to elements in the list of values. A runtime exception results if a parameter specifier designates an item outside the bounds of the list of values, and we prefer not to have runtime exceptions. Example: Console.WriteLine("The value is 0 and not 1", i); where the 1 specifier designates a missing parameter. Rule 10@407 Synopsis: When using composite formatting, do not supply any object unless it is referenced in the format string Level: 4 Category: Data types Composite formatting, e.g. in String.Format, uses indexed placeholders that must correspond to elements in the list of values. It is not an error to supply objects in that list that are not referenced in the format string, but it very likely a mistake. Example: Console.WriteLine("The value is 0 and not 0", i, j); where the second specifier was probably intended to be 1 to refer to j. 54
61 Coding style (Coding style) Rules Do not mix coding styles within a group of closely related classes or within a module 11@403 The public, protected, and private sections of a class or struct shall be declared in that order 11@407 Write unary, increment, decrement, function call, subscript, and access operators together with their operands 11@409 Use spaces instead of tabs 11@411 Do not create overly long source lines Rule 11@101 Synopsis: Do not mix coding styles within a group of closely related classes or within a module Level: 9 Category: Coding style This coding standard gives you some room in choosing a certain style. Do keep the style consistent within a certain scope. That scope is not rigidly defined here, but is at least as big as a source file. Rule 11@403 Synopsis: The public, protected, and private sections of a class or struct shall be declared in that order Level: 9 Category: Coding style Although C# does not have the same concept of accessibility sections as C++, do group them in the given order. However, keep the fields at the top of the class (preferably inside their own #region). The protected internal section goes before the protected section, and the internal section before the private section. Rule 11@407 Synopsis: Write unary, increment, decrement, function call, subscript, and access operators together with their operands Level: 10 Category: Coding style 55
62 This concerns the following operators: unary: & * + - ~! increment and decrement: function call and subscript: () [] access:. It is not allowed to add spaces in between these operators and their operands. It is not allowed to separate a unary operator from its operand with a newline. Note: this rule does not apply to the binary versions of the & * + - operators. Example: a = -- b; a = --c; // wrong // right a = -b - c; // right a = (b1 + b2) + (c1 - c2) + d - e - f; // also fine: make it as readable as possible Rule 11@409 Synopsis: Use spaces instead of tabs Level: 9 Category: Coding style Different applications interpret tabs differently. Always use spaces instead of tabs. You should change the settings in Visual Studio.NET (or any other editor) for that. Rule 11@411 Synopsis: Do not create overly long source lines Level: 8 Category: Coding style Long lines are hard to read. Many applications, such as printing and difference views, perform poorly with long lines. A maximum line length of 80 characters has proven workable for C and C++. However, C# tends to be more verbose and have deeper nesting compared to C++, so the limit of 80 characters will often cause a statement to be split over multiple lines, thus making it somewhat harder to read. This standard does not set any explicit limit on the length of a source line, thus leaving the definition of `too long? to groups or projects. 56
63 Literature C# Lang Title: C# Language Specification Author: TC39/TG2/TG3 Year: 2001 Publisher: ecma ISBN: ECMA C++ Coding Standard Title: Philips Healthcare C++ Coding Standard Author: Philips Healthcare CCB Coding Standards Year: 2008 Publisher: Philps Healthcare Liskov 88 Title: Data Abstraction and Hierarchy Author: Barbara Liskov Year: 1988 Publisher: SIGPLAN Notices, 23,5 (May, 1988) MS Design Title: Design Guidelines for Developing Class Libraries Author: Microsoft, MSDN Meyer 88 Title: Object Oriented Software Construction Author: Betrand Meyer Year: 1988 Publisher: Prentice Hall 57
C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents
Technotes, HowTo Series C Coding Style Guide Version 0.3 by Mike Krüger, [email protected] Contents 1 About the C# Coding Style Guide. 1 2 File Organization 1 3 Indentation 2 4 Comments. 3 5 Declarations.
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)
Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Duration of Course: 6 Months Fees: Rs. 25,000/- (including Service Tax) Eligibility: B.E./B.Tech., M.Sc.(IT/ computer
C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.
Koln C#5.0 IN A NUTSHELL Fifth Edition Joseph Albahari and Ben Albahari O'REILLY Beijing Cambridge Farnham Sebastopol Tokyo Table of Contents Preface xi 1. Introducing C# and the.net Framework 1 Object
PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
09336863931 : provid.ir
provid.ir 09336863931 : NET Architecture Core CSharp o Variable o Variable Scope o Type Inference o Namespaces o Preprocessor Directives Statements and Flow of Execution o If Statement o Switch Statement
Applied Informatics C++ Coding Style Guide
C++ Coding Style Guide Rules and Recommendations Version 1.4 Purpose of This Document This document describes the C++ coding style employed by Applied Informatics. The document is targeted at developers
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.
Objectif This six-day instructor-led course provides students with the knowledge and skills to develop applications in the.net 3.5 using the C# 3.0 programming language. C# is one of the most popular programming
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
Software documentation systems
Software documentation systems Basic introduction to various user-oriented and developer-oriented software documentation systems. Ondrej Holotnak Ondrej Jombik Software documentation systems: Basic introduction
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Java Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
Object Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
CORBA Programming with TAOX11. The C++11 CORBA Implementation
CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
Java (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Software Development (CS2500)
(CS2500) Lecture 15: JavaDoc and November 6, 2009 Outline Today we study: The documentation mechanism. Some important Java coding conventions. From now on you should use and make your code comply to the
vector vec double # in # cl in ude <s ude tdexcept> tdexcept> // std::ou std t_of ::ou _range t_of class class V Vector { ector {
Software Design (C++) 3. Resource management and exception safety (idioms and technicalities) Juha Vihavainen University of Helsinki Preview More on error handling and exceptions checking array indices
Getting Started with the Internet Communications Engine
Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2
C # Coding Standards for.net By Lance Hunt. Document Version 1.15 March 2007. Copyright Lance Hunt 2007 All Rights Reserved
C # Coding Standards for.net By Lance Hunt Document Version 1.15 March 2007 Copyright Lance Hunt 2007 All Rights Reserved Published by Lance Hunt Please submit comments, questions, and feedback to http://www.lance-hunt.net.
Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions
COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)
Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB) Course Number: 4995 Length: 5 Day(s) Certification Exam There are no exams associated with this course. Course Overview
Computing Concepts with Java Essentials
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann
.NET Overview. David Smith. Today s s Topics. Why am I here? A tool. Microsoft s s Vision for.net
.NET Overview David Smith Microsoft Student Ambassador CS Major Michigan State University Today s s Topics Why I m I m here. Exciting Demo IssueVision What is.net? Why learn.net? Look into the Demo Old
Coding conventions and C++-style
Chapter 1 Coding conventions and C++-style This document provides an overview of the general coding conventions that are used throughout oomph-lib. Knowledge of these conventions will greatly facilitate
UML for C# Modeling Basics
UML for C# C# is a modern object-oriented language for application development. In addition to object-oriented constructs, C# supports component-oriented programming with properties, methods and events.
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive
Concepts and terminology in the Simula Programming Language
Concepts and terminology in the Simula Programming Language An introduction for new readers of Simula literature Stein Krogdahl Department of Informatics University of Oslo, Norway April 2010 Introduction
Software Engineering Techniques
Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary
CSE 308. Coding Conventions. Reference
CSE 308 Coding Conventions Reference Java Coding Conventions googlestyleguide.googlecode.com/svn/trunk/javaguide.html Java Naming Conventions www.ibm.com/developerworks/library/ws-tipnamingconv.html 2
JetBrains ReSharper 2.0 Overview Introduction ReSharper is undoubtedly the most intelligent add-in to Visual Studio.NET 2003 and 2005. It greatly increases the productivity of C# and ASP.NET developers,
MISRA-C:2012 Standards Model Summary for C / C++
MISRA-C:2012 Standards Model Summary for C / C++ The LDRA tool suite is developed and certified to BS EN ISO 9001:2000. This information is applicable to version 9.4.2 of the LDRA tool suite. It is correct
TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction
Standard 2: Technology and Society Interaction Technology and Ethics Analyze legal technology issues and formulate solutions and strategies that foster responsible technology usage. 1. Practice responsible
VB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
Volume I, Section 4 Table of Contents
Volume I, Section 4 Table of Contents 4 Software Standards...4-1 4.1 Scope...4-1 4.1.1 Software Sources...4-2 4.1.2 Location and Control of Software and Hardware on Which it Operates...4-2 4.1.3 Exclusions...4-3
Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.
Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles
Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt
core. 2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Volume I - Fundamentals Seventh Edition CAY S. HORSTMANN GARY
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)
TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions
National Database System (NDS-32) Macro Programming Standards For Microsoft Word Annex - 8
National Database System () Macro Programming Standards For Microsoft Word Annex - 8 02/28/2000 /10:23 AM ver.1.0.0 Doc. Id: RNMSWS softcopy : word page : 1/6 Objectives A well-defined system needs to
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
INF5140: Specification and Verification of Parallel Systems
INF5140: Specification and Verification of Parallel Systems Lecture 7 LTL into Automata and Introduction to Promela Gerardo Schneider Department of Informatics University of Oslo INF5140, Spring 2007 Gerardo
Basic Programming and PC Skills: Basic Programming and PC Skills:
Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of
Computer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
N3458: Simple Database Integration in C++11
N3458: Simple Database Integration in C++11 Thomas Neumann Technische Univeristät München [email protected] 2012-10-22 Many applications make use of relational database to store and query their data. However,
6. Control Structures
- 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,
TypeScript for C# developers. Making JavaScript manageable
TypeScript for C# developers Making JavaScript manageable Agenda What is TypeScript OO in TypeScript Closure Generics Iterators Asynchronous programming Modularisation Debugging TypeScript 2 What is TypeScript
Coding Standards for C#
DotNetDaily.net Coding Standards for C# This document was downloaded from http://www.dotnetdaily.net/ You are permitted to use and distribute this document for any noncommercial purpose as long as you
JavaScript: Control Statements I
1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can
PL/SQL Overview. Basic Structure and Syntax of PL/SQL
PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension
JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
CS 241 Data Organization Coding Standards
CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
Chapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
Change Management for Rational DOORS User s Guide
Change Management for Rational DOORS User s Guide Before using this information, read the general information under Appendix: Notices on page 58. This edition applies to Change Management for Rational
Windows PowerShell Essentials
Windows PowerShell Essentials Windows PowerShell Essentials Edition 1.0. This ebook is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights
Functional Programming
FP 2005 1.1 3 Functional Programming WOLFRAM KAHL [email protected] Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling
Binary storage of graphs and related data
EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics
El Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
Introduction to Programming System Design. CSCI 455x (4 Units)
Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,
PL/SQL Practicum #2: Assertions, Exceptions and Module Stability
PL/SQL Practicum #2: Assertions, Exceptions and Module Stability John Beresniewicz Technology Manager Precise Software Solutions Agenda Design by Contract Assertions Exceptions Modular Code DESIGN BY CONTRACT
Course Title: Software Development
Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.
Visual Basic. murach's TRAINING & REFERENCE
TRAINING & REFERENCE murach's Visual Basic 2008 Anne Boehm lbm Mike Murach & Associates, Inc. H 1-800-221-5528 (559) 440-9071 Fax: (559) 440-0963 [email protected] www.murach.com Contents Introduction
C Compiler Targeting the Java Virtual Machine
C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the
There are 2 approaches to starting a session: the mutation scope can contain a whole codebase or in a single chosen method.
Visual Mutator 2.1 User Manual A1. Overview Visual Mutator is a mutation testing tool and a Visual Studio extension that can be used to verify quality of a test suite in the active solution. It operates
VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...
Using the Studio Source Control Hooks
Using the Studio Source Control Hooks Version 2008.1 29 January 2008 InterSystems Corporation 1 Memorial Drive Cambridge MA 02142 www.intersystems.com Using the Studio Source Control Hooks Caché Version
Skyline Interactive Tool Support
Skyline Interactive Tool Support Skyline supports external tools that extend Skyline functionality without directly integrating into the large and complex Skyline source code base. External Tools provide
How to create/avoid memory leak in Java and.net? Venkat Subramaniam [email protected] http://www.durasoftcorp.com
How to create/avoid memory leak in Java and.net? Venkat Subramaniam [email protected] http://www.durasoftcorp.com Abstract Java and.net provide run time environment for managed code, and Automatic
Programming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
Web Services for Management Perl Library VMware ESX Server 3.5, VMware ESX Server 3i version 3.5, and VMware VirtualCenter 2.5
Technical Note Web Services for Management Perl Library VMware ESX Server 3.5, VMware ESX Server 3i version 3.5, and VMware VirtualCenter 2.5 In the VMware Infrastructure (VI) Perl Toolkit 1.5, VMware
C++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
Software Construction
Software Construction Debugging and Exceptions Jürg Luthiger University of Applied Sciences Northwestern Switzerland Institute for Mobile and Distributed Systems Learning Target You know the proper usage
Going Above and Beyond
Whitepaper Going Above and Beyond Using Advanced Techniques to Create Customized HTML Templates August 3, 2010 Copyright 2010 L-Soft international, Inc. Information in this document is subject to change
Async startup WPF Application
Async startup WPF Application Friday, December 18, 2015 5:39 PM This document is from following the article here: https://msdn.microsoft.com/enus/magazine/mt620013.aspx While working through the examples
Introduction to Visual Studio and C#
Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Introduction to Visual Studio and C# HANS- PETTER HALVORSEN, 2014.03.12 Faculty of Technology, Postboks
UML Modeling Guidelines
UML Modeling Guidelines Version 1.0 March 13, 2015 ONF TR-514 ONF Document Type: Technical Recommendation ONF Document Name: UML Modeling Guidelines V1.0 Disclaimer THIS SPECIFICATION IS PROVIDED AS IS
Programming and Software Development (PSD)
Programming and Software Development (PSD) Course Descriptions Fundamentals of Information Systems Technology This course is a survey of computer technologies. This course may include computer history,
Code Contracts User Manual
Code Contracts User Manual Microsoft Corporation August 14, 2013 What s New? We fixed the debug information generated by the rewriter for async and iterator methods so that locals now appear again when
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
A Practical Guide to Test Case Types in Java
Software Tests with Faktor-IPS Gunnar Tacke, Jan Ortmann (Dokumentversion 203) Overview In each software development project, software testing entails considerable expenses. Running regression tests manually
www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk
CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling
