-
-
Notifications
You must be signed in to change notification settings - Fork 354
Coding standards
The following are the adopted coding standards:
-
First and foremost, follow the established patterns you see in the existing code base. Don’t invent your own patterns!
-
See http://www.dotnetspider.com/tutorials/CodingStandards.doc
- Except where noted in our Naming Conventions follow items 1 through 11 in section 7. Naming Conventions and Standards.
-
Use Spaces not TABs. Use 4 spaces instead of a tab. In Visual Studio, under Tools->Options, Text Editor, C#, Tabs, set your Tab size and Indent size to 4 and radio option to "Insert spaces".
-
Other C# "Spacing" Settings
Check both 'Insert space within argument list parenthesis' options
three other spacing options
four more spacing for delimiter options
-
Use the Organize Usings | Remove and Sort tool when editing your cs files. Sort them putting 'System' directives first. Turn this option on in Visual Studio, under Tools->Options, Text Editor, C#, Advanced, and enable "Place 'System' directives first when sorting usings"
-
Use GhostDoc
Download GhostDoc from http://submain.com/download/ghostdoc/. Enter your email address and click "Download GhostDoc". Just use the default settings when installing. Now that it is installed, use it to document methods, classes, properties, etc. It is OK to just leave the default comments that it generates. At a minimum, it is nice to get rid of the compiler warnings due to wrong or missing XML comments.
Tip: Use the keyboard shortcut Ctrl-Shift-D for quickest usage.
Read the Git Branching Strategy page to follow our branching standard convention.
Read the JavaScript Coding Standards page to get up to speed on what we like to see on the front-end.
Read the Date, Time, Datetime and Numeric Comparison Logic Standards for vital things you should be aware of when writing Linq/SQL code involving Date, Time, Date/Time, or Numeric comparisons.
Code regions (#region X
and #endregion
) should be used to organize code. Models, controls, and blocks should use the following standard region names. Additional code regions can be used inside these standard region names
Region Name | Description |
---|---|
#region Entity Properties |
All the properties that should be mapped to a database field |
#region Virtual Properties |
Non-mapped properties |
#region Public Methods |
|
#region Entity Configuration |
The class used to specify Entity Framework mapping configuration for the entity |
Region Name | Description |
---|---|
#region Fields |
Private variables |
#region Properties |
Public/Protected properties |
#region Base Control Methods |
The overrides of the base RockBlock methods (i.e. OnInit, OnLoad) |
#region Events |
Handlers called by the controls on your block. |
#region Methods |
Your helper functional methods (like BindGrid(), etc.) |
You can create additional sub regions as needed if you have a complicated block.
- Capitalize reserved words
- Main keywords on new line
- Use brackets around table and column names
- Use proper capitalization for table and column names
Example
INSERT INTO
[AttributeValue] ([IsSystem], [AttributeId], [EntityId], [Order], [Value], [Guid])
SELECT
1, @AttributeId, B.[Id], 0, '290C53DC-0960-484C-B314-8301882A454C', NEWID()
FROM
[Block] B
INNER JOIN [Layout] L
ON L.[Id] = B.[LayoutId]
AND L.[SiteId] = @RockSiteId
WHERE
[BlockTypeId] = @BlockTypeID
Be sure to keep the Naming Conventions page handy when you are writing new entities and blocks.