Skip to content
jperl edited this page Mar 16, 2012 · 20 revisions

##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.

XAML

Root Order

  1. x:Class, x:Name
  2. All references, maximum 2 per line
  3. Design, other properties (Ex. mc:Ignorable="d" d:DesignWidth="230" Foreground="Blue")
  4. ViewModelLocator
  5. Bindings

Rules:

-Wrap lines when they pass more the longest reference line

Controls Properties Order

  1. x:Name
  2. Hardcoded properties
  3. Properties with StaticResources
  4. Event handlers
  5. Properties with Bindings

Example:

<Rectangle x:Name="rectangle1" Height="1" Width="{StaticResource LgRectangleWidth}" Fill="{Binding FillColor}" Loaded="Rectangle1Loaded" />

CSharp

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:

  1. Code Execution
  2. Alphabetically

Example code execution section:

//Section explanation

firstMethodCalled
{
}

secondMethodCalled
{
    innerMethodA();

    innerMethodB();
}

innerMethodA
{

}

innerMethodB
{

}

Using Statements

Order alphabetically.

Lambdas

When you don't need to use the variable, you can use _ => for one variable or (_,__) for multiple variables.

Example:

AddCommand.Subscribe(_ => UpdateFilter());

Reactive Extensions

good learning resource: http://reactiveui.net/welcome/pdf

Commenting

General

  1. As a general rule, include one comment per line of Silverlight code.
  2. 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
{
}

Multiple Conditions

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())

Easy Mistakes

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.

Clone this wiki locally