Advice on writing MATLAB code usually addresses efficiency concerns, with recommendations such as “Don’t use loops.” This document is different. Its concerns are correctness, clarity and generality. The goal of these guidelines is to help produce code that is more likely to be correct, understandable, sharable and maintainable. As Brian Kernighan writes, “Well-written programs are better than badly-written ones - - they have fewer errors and are easier to debug and to modify — so it is important to think about style from the beginning.” This document lists MATLAB coding recommendations consistent with best practices in the software development community. These guidelines are generally the same as those for C, C++ and Java, with modifications for Matlab features and history. The recommendations are based on guidelines for other languages collected from a number of sources and on personal experience. These guidelines are written with MATLAB in mind, and they should also be useful for related languages such as Octave, Scilab and O-Matrix. Guidelines are not commandments. Their goal is simply to help programmers write well. Many organizations will have reasons to deviate from them. “You got to know the rules before you can break ‘em. Otherwise it’s no fun.” Sonny Crockett in Miami Vice MATLAB is a registered trademark of The MathWorks, Inc. In this document the acronym TMW refers to The MathWorks, Inc…
Functions should have meaningful names. There is an unfortunate MATLAB tradition of using short and often somewhat cryptic function names—probably due to the DOS 8 character limit. This concern is no longer relevant and the tradition should usually be avoided to improve readability. Use computetotalwidth() Avoidcompwid() An exception is the use of abbreviations or acronyms widely used in mathematics. max(.), gcd(.) Functions with such short names should always have the complete words in the first header comment line for clarity and to support lookfor searches…
Download MATLAB Programming Style Guidelines.Pdf
from http://www.pdfee.com
No comments:
Post a Comment