Environment
It is extremely important, when coding in .NET, to enable Option Explicit and Option strict for all projects. This forces developers to explicitly declare and type variables before they are used. The compiler will generate more efficient machine code and significantly increase application performance.
Formatting
Formatting makes the logical organization of the code obvious. Taking the time to ensure that the source code is formatted in a consistent, logical manner is helpful to you and to other developers who must decipher the source code.
- Keep maximum line length for comments and code to a reasonable length to avoid having to scroll the source code editor. This strategy also provides cleaner hard copy presentation.
- Use line breaks between logical blocks of code. Doing so creates "paragraphs" of code, which aid the reader in comprehending the logical segmenting of the software.
- Develop and use structured error-handling routines where applicable. This includes file IO, database operations, and network operations.
- Do not use abbreviations or contractions as parts of identifier names. For example, use GetWindow instead of GetWin.
- Do not use acronyms that are not generally accepted in the computing field.
- Where appropriate, use well-known acronyms to replace lengthy phrase names. For example, use UI for User Interface and OLAP for On-line Analytical Processing.
- When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton. However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io.
- When writing SQL statements, use all uppercase for keywords and mixed case for database elements, such as tables, columns, and views.
- Put each major SQL clause on a separate line so that statements are easier to read and edit.
Variables
Good variable naming standards and practices is vital in creating code that is easily understood and maintained. In most situations, the developer working with code is not the developer who originally wrote it. There are three naming standards that you should be aware of:
Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:
Uppercase
All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters. For example:
Refer to these capitalization styles for the variable naming standards below.
- Keep the scope of variables as small as possible to avoid confusion and to ensure maintainability.
- Use Camel case for local variables and parameters
- Use Pascal case for namespaces, properties, enumerated values, classes, events, methods and functions.
- Use the prefixes below for visual objects used on your forms. This lets you and other developers know what object type you are working with, and aids in readability and understanding of your code. For client-side objects, declared variables, and visual objects that are not used such as static labels, no prefix is necessary.
LBL - Label
GRD or GRID - GridView
TXT - Textbox
DL - DataList
CMD or BUT - Button
DTL - DetailsList
CMD or BUT - LinkButton
FMV - FormView
CMD or BUT - ImageButton
REP - Repeater
LNK - HyperLink
DS - SqlDataSource
CMB or DDL - DropDownList
DS - AccessDataSource
LST - ListBox
DS - ObjectDataSource
CHK - Checkbox
DS - XmlDataSource
CHK - CheckboxList
DS - SiteMapDataSource
OPT - RadioButton
RTV - ReportViewer
OPT - RadioButtonList
IMG - Image
IMG - ImageMap
TBL - Table
UOL - BulletedList
HID - HiddenField
LIT - Literal
CAL - Calendar
AD - AdRotator
FUL - FileUpload
WIZ - Wizard
XML - XML
MLV - MultiView
PNL - Panel
PLH - PlaceHolder
VIEW - View
SUB - Substitution
LOC - Localize
SQL
Using a naming standard and good practices for the SQL statements in your project will make your queries easier to read and understand, which will make the underlying dataset and relevant code easier to understand as well.
- Never use “SELECT *”
- Do not use prefixes for database objects. For example, use Employee instead of tblEmployee.
- Database object names should be singular. For example, name a table “Order” instead of “Orders”.
- When creating a SQL query in your code, put each statement on a separate line.
- Avoid using reserved keywords for database object or field names. You can use the SQL Reserved Words Checker located at http://www.petefreitag.com/tools/sql_reserved_words_checker to make sure.
No comments:
Post a Comment
Your feedback is important. I enjoy hearing other opinions and ideas, even if you disagree. Please keep comments constructive.