The goal of this set of coding standards that can be automatically checked is to help you write consistent, clean, understandable and maintainable m-code. The resulting code will be more readable for both yourself and others. These guidelines are no strict rules that must be followed at all cost. They are simply there to help you write m-code well and you can deviate from them as you please.
The coding standards described here can be checked using Code Checker for MATLAB by MonkeyProof Solutions. These coding standards are configured in the predefined
MonkeyProofSolutions configurations set available with the tool. This set is the default selection after installing. For instructions on how to check your code against coding standards, see the video below. The steps are also described below the video.
You can check your code for compliance with the guidelines described here as follows:
- Install Code Checker for MATLAB. If you have not purchased the tool yet, you can do so here. Alternatively, you could request a free trial license there.
- Open Code Checker for MATLAB in one of two ways:
- Click the shortcut created at the top of the screen next to the documentation search bar: .
monkeyproof.cc4m.start()from the command window.
- Select whether you want to check one or more files, all files in a folder, or all files in a MATLAB Project.
- Select what files/folder/project to check.
- Further customization is available, for example checking a folder including or excluding all subfolders.
- Click the Run button at the bottom to start checking your code.
The guidelines that require human judgment or are simply not possible to check statically in MATLAB are not part of this coding standard.
The coding standards and guidelines are grouped under specific categories to help keep things organized:
- Naming conventions: Guidelines in this chapter describe how variables, functions etc. can be named in a consistent and insightful manner.
- Layout & comments: This chapter contains guidelines to help improve readability of your code for yourself and for others. There are guidelines on whitespace, comments and more.
- Statements & expressions: The guidelines and coding standards in this chapter are about how to use constructs such as
if/elseblocks, what built-in functions or keywords to avoid, how to best structure your statements etc.
- Higher level guidelines: This chapter contains (among others) coding standards on higher-level objects such as functions or files.
Every guideline is structured as follows:
|ID||A unique guideline identifier.|
|Title||Brief description of the guideline.|
|Priority||Priority of the guideline can be one of Mandatory, Strongly recommended and Recommended. Exactly what each of these means for your case is up to you to decide.|
|Description||A more elaborate description of the guideline. Can include the reasoning behind the guideline: how does your code improve when applying the guideline?|
|Rationale||One or multiple words describing what the guideline is about. Examples: Readability, Stability.|
One or more code examples to avoid using.
The example(s) above improved by complying with the guideline.