This page holds the coding standards for the Orbit Determination Toolbox.
Revision 0.4 2011-04-29 Allen Brown
The standards included here are:
An example is attached.
Generally these standards are also applied to MATLAB classes. Exceptions will be noted.
Other possible standards for code-level (syntax and formatting), design-level (API or algorithm structure), or external data (input or output file formats) are not yet defined.
This is the coding standards for the ODTBX MATLAB files. While “formatting alone does not make a good coding standard”, the documentation of a MATLAB .m function is more specialized than for other languages because it is free-form but serves multiple purposes:
1. Support and integrate with the various MATALB Help Systems,
2. Support the users of the function (the clients),
3. Support of current and future maintainers of the function (the developers).
These are written so that a developer with any level of MATLAB or ODTBX experience could follow them and get their code integrated with ODTBX.
• Keep the name short but keep it consistent with other functions and intelligible
• A good guideline is to keep the name pronounceable
• The use of uderscores in MATLAB function or class names is under discussion.
• The function name should not begin with a number.
• The function names should not contain other punctuation.
• Note: We are discussing whether underscores should be used to distinguish between MATLAB functions and classes.
• The ODTBX standard for case is that functions should be all lower case.
• However, there are several examples of mixed case where capitalized letters are used for readable abbreviations.
• Note: We are discussing whether MATLAB classes should be named with a different style than MATLAB functions, such as "CamelCase" with no underscores.
• Allowable mixed-case conventions:
o Technical terminology:
o RK for Runge-Kutta, or extensions (e.g. RK4 or RKF78)
o JD or MJD for Julian Date or Modified Julian Date
o DCM for direction cosine matrix
o Capital D can be used for dimension
o Specific algorithm or system abbreviations (e.g. WGS, IAU, GPS, etc). These must not be ambiguous in the ODTBX world and must be consistent with other functions.
• Numbers in the function name are allowed. Generally the following is true:
o The number denotes a specific dimension (e.g. 2D or 3D)
o The number denotes an algorithm (e.g. WGS84)
o “2” has a special use where it signifies a conversion from one thing to another (e.g. kep2cart)
Each MATLAB function in the ODTBX will have at least the following:
Rationale: Fighting an editor’s built-in formatting usually introduces more unintended changes over the life of a project. These changes, if they accidentally occur, will always have to be evaluated as formatting-only changes or true content changes and this takes time and effort.
General Rules for the MATLAB Help System Documentation:
Both the input arguments and output variables are described in a similar format. The inputs are described first, followed by the outputs. If either of the two set have no variables in function specification (e.g. function [] = x(y) or function [y] = x() ) then that section can be skipped. Each section is formatted as a space-delimited table format for readability.
Labels: The next line is the column header labels for the section, it is:
VARIABLE TYPE SIZE DESCRIPTION
Order: The items in the section should be presented in the same order as they appear in the function specification. This includes all optional arguments.
o Optional inputs should have “(Optional)” at the beginning of their description.
o Units must be noted in parenthesis for every variable with no exceptions. For non-dimensional parameters use “(unitless)”, “(dimensionless)”, “(no units)”, etc. Abbreviations can be used if the meaning is clear from the description, e.g. “(km)” for a distance variable.
o Reference Systems (coordinate systems, time systems, etc.) must be included so there is no ambiguity. Time specifications can be more complex because they may require separate specifications for the date format (JD, MJD, etc.) and the time system (UTC, TDB, TT, etc).
o Any restriction such as dimension size, numerical ranges, etc. on a specific variable should be documented here or in the Limitations below where there is more room. Restrictions due to a combination of variables should be documented separately. Use a (see LIMITATIONS, below) comment for this.
o Any defaulted values should be explicitly noted.
o The variable names, types, and sizes should be spaced so they appear in a column under their respective labels.
o The description should start under its DESCRIPTION label. Multiple lines should also use spaces to continue as a “block” for readability.
o Be sure to document the expected type(s) and size(s) of the items in the cell array. Also note if there are any conventions on the type and location in the cell array.
o Be sure to explicitly describe every field in the struct. The struct itself should appear on a line by itself. Its fields should each be described immediately underneath the struct. Place a “.” before each field so they are easily identifiable as fields of the above struct. For example, if r is a struct with four fields:VARIABLE TYPE SIZE DESCRIPTION r struct 1 r contains the range measurements to the target from the installation in the “installation reference” frame .x double 1xN X component (km) .y double 1xN Y component (km) .z double 1xN Z component (km) .t double 1xN measurement time (MATLAB serial time)
o Separate by one line of (commented) whitespace,
o Start the line with “LIMITATIONS: “
o Describe the ways this limitation can be encountered.
o Describe how the function will behave (different return values, any MATLAB errors, etc.) when this limitation is encountered.
o If possible, provide advice on what could be changed to avoid this problem when it is encountered. For example,” If this occurs, try reducing the XYZ threshold value to 10% of its former value.”
If desired, please have one or two simple examples with associated command line statement(s) and the expected output. This can be very useful for functions with extensive, or optional, inputs and/or outputs.
This section documents other ODTBX functions or significant MATLAB functions that this routine relies upon. Placing them here allows the user to navigate through the help system. It is not required if this routine doesn’t depend upon other functions.
The [OdtbxLicensing] page describes the license that should be applied to source files. In summary, there are two parts:
1 A short reference to the license that is visible in the MATLAB Help system,
2 The longer license reference with copyright that should not be visible in the MATLAB Help system.
One line of uncommented whitespace separates these two parts. This short reference should be the bottom-most item displayed in the Help System documentation.
A manually-maintained, file-specific, change log is not yet a standard on all ODTBX files. If it is desired, then this section should be separated from the License and other Help System documentation by at least one line of uncommented whitespace.
An example is attached.
[OdToolBoxQa] - Go back to the OD Toolbox QA Page
[IssueProcess] - Go to the OD Toolbox Issue Process
[ForDevelopers] - Go back to the main development page
OdToolboxDocuments? - Go back to OD Toolbox Documents
WikiStart - Go back to OD Toolbox Home
Wiki: ForDevelopers
Wiki: Home
Wiki: IssueProcess
Wiki: OdToolBoxQa
Wiki: OdtbxLicensing