|
41 | 41 | - [General](#general) |
42 | 42 | - [Try-Catch](#try-catch) |
43 | 43 |
|
| 44 | +# Deviations in this fork from the original MathWorks version |
| 45 | +- This section. |
| 46 | +- Removed discussion on detection of rule and best practice violations using plain MATLAB - as this version of the document is targeting CC4M users. |
| 47 | +- Added [section](#detection-using-cc4m) on detection violations using CC4M. |
| 48 | + |
| 49 | +<!--# TODO |
| 50 | +- Add ID to every guidelin |
| 51 | +- Update detection to also reflect the check used in CC4M |
| 52 | +--> |
| 53 | + |
| 54 | + |
| 55 | + |
44 | 56 | # The Purpose of this Document |
45 | 57 |
|
46 | 58 | As applications get larger and more complex, organizations are adopting more formal coding practices including code reviews, automated builds, and continuous integration. Organizations which develop applications involving teams of people writing MATLAB code want to introduce regularity and consistency in their code bases to enhance the quality of their MATLAB code. |
@@ -142,53 +154,13 @@ The table for each guideline has the following fields. |
142 | 154 |
|
143 | 155 | - **History:** The version of this document when the guideline was introduced. |
144 | 156 |
|
145 | | -## Rules |
146 | | - |
147 | | -Rule violations are (or will be) detectable by the MATLAB Code Analyzer. The Code Analyzer is a tool in MATLAB that examines code to identify problems and make recommendations for improvement. It can identify issues related to syntax errors, compatibility, performance, deprecated functionality and much, much more. The Code Analyzer provides [over two thousand checks](https://www.mathworks.com/help/matlab/matlab_env/index-of-code-analyzer-checks.html) for various potential code issues. Those checks can be enabled, disabled, or customized by [creating a local codeAnalyzerConfiguration.json file](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html) similar to the example shown below. |
148 | | - |
149 | | -<img title="" src="../images/codeAnalyzerConfiguration.png" alt="" width="439"> |
150 | | - |
151 | | -The MATLAB Code Analyzer can detect violations for a subset of the Rules listed in this document. Note that some versions of MATLAB may not be able to detect violations for all of the rules. When the Code Analyzer detects a Rule violation, it identifies the issue in both the MATLAB Editor and the Code Analyzer Report. Beginning in R2025a, violations in the Editor are indicated on the right-hand side of the Editor panel as shown in the following screenshot. |
152 | | - |
153 | | -<img title="" src="../images/Editor%20Checks.png" alt="" width="356"> |
154 | | - |
155 | | -This guidelines document is accompanied by a `codeAnalyzerConfiguration.json` file which implements the checks for the set of Rule violations that can be detected. |
156 | | - |
157 | | -The Code Analyzer check for any Rule can be disabled. Consider the example in the screenshot above. There is a Rule that specifies that function names must be lowercase or lowerCamelCase. You can disable this Rule if you want to turn off checking for function name casing. Most Rules can also be configured. In the case above, you could change the options for function name casing to use a different convention (e.g., UpperCamelCase). The Detection field in the Rule information table provides information about which Code Analyzer check is used to detect violations of the Rule. You can then disable or modify the check in your Code Analyzer Configuration file. |
158 | | - |
159 | | -## Best Practices |
160 | | - |
161 | | -Best Practices are simply recommendations for writing better MATLAB code. The information provided for a Best Practice is similar to that provided for a Rule. Below is an example Best Practice from the Guidelines. |
162 | | - |
163 | | -There are some Best Practices that can (optionally) be detected as Rules by enabling a check in the Code Analyzer. Most of those checks are disabled by default. Information on optional detection, when available, is shown in the **Detection** field of the information for a Best Practice. |
164 | | - |
165 | | -**Type:** Best Practice |
166 | | - |
167 | | -**Description:** Use cell arrays only to store data of varying classes and/or sizes. Do not use cell arrays to store character vectors as text data. Use a string array instead. |
168 | | - |
169 | | -**Motivation:** |
170 | | - |
171 | | -- Readability: Using string arrays instead of cell arrays of character vectors improves the readability of the code. |
| 157 | +## Detection using CC4M |
172 | 158 |
|
173 | | -- Performance: String operations are more performant than operations on cell arrays of character vectors. |
174 | | - |
175 | | -**Allowed:** |
176 | | - |
177 | | -```matlab |
178 | | -data = {datetime "abc" 123}; |
179 | | -arrays = {rand(1,10) zeros(2,4) eye(5)}; |
180 | | -missions = ["Mercury" "Gemini" "Apollo"]; |
181 | | -``` |
182 | | - |
183 | | -**Not Allowed:** |
184 | | - |
185 | | -```matlab |
186 | | -missions = {'Mercury' 'Gemini' 'Apollo'}; |
187 | | -``` |
188 | | - |
189 | | -**Detection:** Optionally by enabling Code Analyzer check `DAFCVC` (R2024a) |
190 | | - |
191 | | -**History:** Introduced in Version 1.0 |
| 159 | +Starting with CC4M version 2.20 a configuration is shipped that checks compatibility with this set of guidelines. |
| 160 | +Why use CC4M? |
| 161 | +- Using CC4M for detecting violations comes with a coverage of 58% of all guidelines (compared to 30% by using the MATLAB Code Analyzer) |
| 162 | +- CC4M runs all checks in MATLAB R2017b and newer. |
| 163 | +- Other valuable features and all available checks are described in the [documentation](https://doc.monkeyproofsolutions.nl/code-checker-for-matlab/code-checker-for-matlab/index.html). |
192 | 164 |
|
193 | 165 | ## Definitions |
194 | 166 |
|
|
0 commit comments