-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Practices
##Javascript Follow practices here: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml Use JSDoc comments: http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html To further be worked out.
Root Order
- x:Class, x:Name
- All references, maximum 2 per line
- Design, other properties (Ex. mc:Ignorable="d" d:DesignWidth="230" Foreground="Blue")
- ViewModelLocator
- Bindings
Rules:
-Wrap lines when they pass more the longest reference line
Controls Properties Order
- x:Name
- Hardcoded properties
- Properties with StaticResources
- Event handlers
- Properties with Bindings
Example:
<Rectangle x:Name="rectangle1" Height="1" Width="{StaticResource LgRectangleWidth}" Fill="{Binding FillColor}" Loaded="Rectangle1Loaded" />
The FoundOps code structure is broken into these sections
Code Structure
Enclose different types of codes in #region/#endregion
All comments should start capitalized and use proper punctuation.
Class Structure:
//Summary
Properties & Variables
-Public
-Protected
-Locals
Constructors (least parameters => most parameters)
Logic(Always in a region)
Example property:
//Summary
private int _num
public int Num
{
get{...}
set{...}
}
Logic Code Organization
Organize by:
- Code Execution
- Alphabetically
Example code execution section:
//Section explanation
firstMethodCalled
{
}
secondMethodCalled
{
innerMethodA();
innerMethodB();
}
innerMethodA
{
}
innerMethodB
{
}
Using Statements
Order alphabetically.
When you don't need to use the variable, you can use _ => for one variable or (_,__) for multiple variables.
Example:
AddCommand.Subscribe(_ => UpdateFilter());
good learning resource: http://reactiveui.net/welcome/pdf
- As a general rule, include one comment per line of Silverlight code.
- With Ghost Doc installed, use ctrl + shift + d to add a comment block to class, method, or public property.
Example comments for a class:
/// <summary>
/// Works with the FileController to Get, Insert, Update and Delete protected files.
/// </summary>
public static class FileManager
{
}
Separate the code like this:
// Update Filter whenever: a) routes are changed or is set, b) the SelectedRouteTypes changes,
// c) the SelectedRegions changes
var loadedRoutes = DataManager.GetEntityListObservable<Route>(Query.RoutesForServiceProviderOnDay);
//a) routes are changed or is set
loadedRoutes.FromCollectionChangedOrSetGeneric()
//b) the SelectedRouteType changes
.Merge(SelectedRouteTypes.FromCollectionChangedEventGeneric())
//c) the SelectedRegions changes
.Merge(SelectedRegions.FromCollectionChangedEventGeneric())
Confusing seconds and milliseconds when using TimeSpans.
new TimeSpan(0, 0, 300) //300 seconds
new TimeSpan(0, 0, 0, 0, 300) //300 milliseconds
TimeSpan.FromMilliseconds(300) //even better
See [http://msdn.microsoft.com/en-us/library/system.timespan.aspx](this link) for more information.