Conventions

Function/method code layout

Functions and methods should be laid out as follows

function chanString = functionName(arguments)
    % What it does summarized in one line
    %
    % function zapit.DAQ.functionName(arguments)
    %
    % Purpose
    % What it does in more detail
    %   
    % Inputs
    % input1 - what it is.
    %
    % Outputs
    % output1- what it is 
    %
    % Examples
    % [This section is optional. If the function or method is likely to be
    %  used by an end-user then it is recommended to include some examples]
    %
    % 
    
end % functionName

Style Conventions

  • Two spaces between methods in a class file.

  • Comment block endings if they are large. e.g. end % methods at the end of methods blocks in a class file, as you typically can not see the methods at the start of the block at the same time as the end.

  • Try to keep class files below about 500 lines.

  • Short methods can remain in the main class file.

  • Longer methods should be in their own files.

  • For consistency it is preferred to use an @className folder for all concrete classes even if there is only one .m file in it. Short abstract classes can be left bare if desired to distinguish them from concrete classes.

  • Unless there is an exceptional reason, all functions should be in a module sub-directory for neatness.

  • Max line length is 100 characters but you can break this rule occasionally if that makes sense. It is better to sometimes have an exceptionally long line than to break up that line in an ugly and hard to read way.

  • Where possible follow the mlinter suggestions, but if doing so will make things ugly then feel free to ignore them.

Format Guidelines

  • Save files with Unix line endings. Sometimes these get switched to Windows endings (don't know how this happens). You can tell this has occurred because the Git client will show that all lines in a file are modified. Please do not commit these files: convert back to Unix line endings and commit. There is a Linux shell script in the project root folder that does this for the whole project, or use a text editor like Sublime Text, which makes it easy to change the line endings. Further, please set up Git to not mess with your line endings.

  • Ident size should be 4 spaces (i.e. two indents should be 8 spaces). Do not use tabs. These are the settings used by default in the MATLAB editor.

Last updated