Style Guide

A large part of any programmer’s job is not to write code, but to read it. It may be code they wrote yesterday, or two years ago, or it might be someone else’s code. It is therefore of paramount importance that you make sure your code is easily readable and that its meaning is easily discerned. Style is a part of this, language design choices is another.

Write you code for the humans that will read it in the future.

General principles

Some general principles that follow this rule would be:

Specific style issues

There are numerous conventions one can follow for style. Some are really just good practices, others are more matters of choice.

Whitespace

Naming

Language constructs

In most of these constructs we will provide multiple forms.

Top-level let bindings:

let x = ...    (* for short assignments *)
let x =
  ...     (* Indent by 2 or 3 spaces typically *)

Local let bindings:

let x = ... in ...      (* short assignments *)

let x = ... in
...            (* line it up with the let it matches *)

My personal favorite:

let x = ...
in ...

and for multiple bindings:

let x = ... in
let y = ... in
let z = ...
in ....

Conditionals:

if ... then ... else ...     (* for extremely short conditionals *)
if ...
then ...         (* align vertically *)
else ...