Skip to content
This repository was archived by the owner on Mar 23, 2019. It is now read-only.

Style Guide

Mark Cafaro edited this page Apr 15, 2014 · 1 revision

This page covers the coding conventions used throughout the Symphony code base.

This list is not exhaustive. In general, follow the coding style of the file you are modifying.

MATLAB Code

This section covers all MATLAB code outside of the Core Stubs.

Whitespace

  • Separate properties and events blocks with a single blank line
properties (Constant, Abstract)
	identifier
	version
end

properties
	state
end

events
	StateChanged
end
  • Separate methods and function blocks with two blank lines (except for the first and last function in a methods block)
properties
	identifier
end


methods

	function setState(obj)
		...
	end
	
	
	function requireDeviceNames(obj)
		...
	end
	
	
	function prepareProtocol(obj)
		...
	end

end

  • Function/method declaration: No space between variables and surrounding brackets/parentheses, a comma and one space between input and output variable names, no brackets unless required for multiple outputs, no space following function name
function myFunction()

function out = myFunction(obj, in)

function [out1, out2, out3] = myFunction(obj, in1, in2)
  • Function/method calls should match the spacing format of function declarations
myFunction()

out = obj.myFunction(in)

[out1, out2, out3] = obj.myFunction(in1, in2)
  • Anonymous functions: No space between input arguments, no space between parentheses and function body
@(in1,in2)in1 + in2;
  • Attributes: One space between keywords and attribute specifications, one space between each attribute
properties (Constant, Abstract)

methods (SetAccess = protected, Abstract) 
  • Use 4 spaces instead of tabs (the MATLAB editors default)

  • In general, add a space after a comma. Vector/cell indices and anonymous function inputs are possible exceptions.

Naming convention

  • Class names are UpperCamelCase
classdef SymphonyProtocol
  • Property names are lowerCamelCase
properties
	rigPrepared
	epoch
	epochKeywords
end
  • Function/method names are lowerCamelCase
function setState(obj)
  • Event names are UpperCamelCase
events
	FigureClosed
end
  • Local variables are lowerCamelCase
function names = parameterNames(obj, includeConstants)
	localVariable = includeConstants;
epoch

Ordering

  • Classes should follow this general order:
  1. Properties blocks
  2. Events blocks
  3. Public methods
  4. Private methods
  5. Private functions
  • Order methods by tasks

Miscellaneous

MATLAB Core Stubs

Follow the C# coding convention as closely as possible. This will make it easier to maintain the stubs in parallel with the core.

C# Code

This section covers all C# code. In general we try to follow the Microsoft C# Coding Conventions. Deviations from these guidelines (if any) are listed below.

Whitespace

Naming convention

Ordering

Miscellaneous