Guidelines about coding style

There a few rules about coding style that we try to follow ourselves in the Mathemagix libraries written in our own language. Although these rules are not mandatory, the readability of your code should be easier for others if you follow them.

1.Naming conventions

In general, we try to avoid abbreviations when chosing names for global variables, functions, classes and categories, and choose short (often one letter) names for local variables. For instance:

hamming_distance (i: Int, j: Int): Int == …;

Of course, standard mathematical functions such as exp, log, cos, etc. carry their traditional names. We also recall the following general conventions from the section about regular identifiers:

2.Indentation

The following indentation rules are implemented both in TeXmacs and in the Emacs mode for Mathemagix. In both cases, you may use the key for indenting the current line.

Blocks of code are usually indented by two spaces. For instance:

if x < y then {
  z: T == x;
  x := y;
  y := z;
}

Multiple line bodies of keywords are enclosed between braces { and }, whereas one line bodies are simply indented whenever we put them on separate lines:

if weather = "cold" then
  mmout << "take a coat!" << lf;
else if weather = "hot" then
  mmout << "a T-shirt will suffice" << lf;
else
  mmout << "syntax error in weather; please call Meteo France" << lf;

Input/output operators are indented as follows:

mmout << "first line" << lf
      << "second line" << lf;

Functions or vectors with many arguments are indented as follows:

mmout << beginners_function (a, b, c, d, e, f, g, h,
                             i, j, k, l, m, n, o, p,
                             q, r, s, t, u, v, w, x) << lf;
v: Vector Int == [ 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111,
                   11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111 ];

Sometimes, the readability can be enhanced by using ad hoc indentation rules:

if a = 1 then return 2*x + 3*y + 4*z;
         else return 3*x + 4*y + 2*z;

3.Spacing rules

There are a few less strict rules concerning whitespace management:

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License. If you don't have this file, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.