Appendix C. C coding conventions


Appendix C. C# coding conventions

C# coding conventions and guidelines are very different from Java's and take some getting used to if you have been a 100% Java developer so far. [1]

[1] C++ developers should also take note of the new set of guidelines. Even within the C++ community, significant but different naming and casing conventions have sprung up. For example, Windows C++ developers usually prefix strings with psz or lpsz , but Unix C++ developers do not. Some C++ developers also use the Hungarian notation (which is popular in VB programs) but some do not. It would be nice if all C# developers adopted an 'international' convention as documented in the C# Language Specification.

This appendix lists and compares the standard coding conventions of both languages. Bear in mind that conventions and guidelines (unlike specifications) are not mandatory, and can be extended or modified to suit a development team's culture and preferences. Nevertheless, it is highly recommended that you stick to a common convention so that your codes are much more readable outside your project team. Adherence to common practices and guidelines is also good practice in software professionalism .

Table C.1. Common casings/notations used in programming

Name

Description

Example

Pascal casing

The first letter of each word is capitalized and the first letter of each word in the string also starts with a capital letter “ no underscores are used to separate words

ShowWarningMessage GetColor

Camel casing

The first letter of each word is not capitalized but each word in the string starts with a capital letter “ no underscores are used to separate words

showWarningMessage getColor

All upper case

Every letter in the string is capitialized “ to improve readability, it is common to separate words in the string with an underscore

SHOW_WARNING _MESSAGE GETCOLOR

Hungarian notation

Variable names are prefixed with letters that represent the data type

String sMessage char cLetter

Table C.1 gives some common notations/casing.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net