Inside the MATLAB Desktop
March 3rd, 2008
Sharing Your M-Lint Settings
Writing robust, production quality MATLAB code is a whole lot easier when you use M-Lint. M-Lint inspects your code for problems and also recommends changes that will help improve the performance or maintainability of your code. M-Lint is analogous to the spelling and grammar checkers I so depend on, available in most word processors.
In order to really take advantage of M-Lint, I’ve found it useful to integrate it into the code review process. So when working on a team project, we use an agreed upon set of M-Lint settings, which are stored on a public drive. Then, each developer points their M-Lint analyzer to those settings, and codes against them.
Finally, when completing a code review, one of the exit requirements is that the MATLAB code must be in a “green” state (no errors, no warnings). We do allow warnings to be ignored using %#ok, though good justification must be provided.
Here’s how you can set up shared M-Lint settings:
The person setting up the shared settings should do the following
- Open the Preferences dialog by going to File -> Preferences… and select M-Lint (you should see the dialog below)
- Tweak the M-Lint settings as needed
- Press Save As…
- Navigate to a shared directory and press Save (alternatively you could check this file into source control)
Each team member should do the following
- Open the Preferences dialog by going to File -> Preferences… and select M-Lint
- Click on the Active Settings combo-box and select Browse…
- Navigate to your teams shared M-Lint settings, select that file and click Open
- Press Apply or OK for the settings to become active.
Many of us work on multiple teams, so I should point out that it’s very easy to switch between M-Lint settings. Go to Tools -> M-Lint and select the appropriate settings for the project your working on.
I think you’ll find this approach really makes you think about your warnings, and it will force you to justify any usages of %#ok.
By the way, there’s a new blogger in the family. Seth will be talking about Simulink over at his new blog, Seth On Simulink. This will be a great place for Simulink users to pick up tips and tricks, as well as share their experiences with the product.
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
7:09 am |
Posted in Editor, Preferences |
Permalink |
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
I’ve noticed that M-lint can be harsh on M-files written for older versions of MATLAB. For example, take a look at Cleve Moler’s NCM toolbox, or Nick Higham’s matrix computation toolbox. There are lots of warnings such as “use two ampersands instead of one” in logical statements. These are both well-written codes, however.
Here is a suggestion. What if an m-file could have a special help line that M-link recognizes (like “See also”, “Copyright” etc). It could look like
% Written for MATLAB Version 6.5
or something, which would tell M-lint not to complain about features used in MATLAB v6.5 that are no longer deemed acceptable.
I write code that’s meant to back-port to old versions of MATLAB, so I have to use lots of #%ok’s to tell m-lint to keep quiet …
Hi Tim,
Thats a great point - older M files were not written with the guiding hand of M-Lint. As an alternative to your suggestion, I’d recommend creating a second set of M-Lint settings and then switch to those settings when you open an older file.
This certainly isn’t as convenient and user-friendly as your method, but it would work in the interim.
Thanks for the feedback Tim,
-Ken
Great Post Ken. Writing code amongst many group members can cause many headaches from clashing styles and structure.
Thanks Quan. Collaboration is an oft overlooked portion of the work-flow.