View on GitHub

OCamlverse

Documenting everything about OCaml

Edit

Best Practices

Here is a collection of community-chosen best practices for successful programming in OCaml.

Coding Style Tooling

Rather than spending precious time worrying about the correct format for syntax, it’s much more convenient to have tooling that will automatically lay out the code for you in a canonical manner. While ocp-indent used to be the clear choice for automatic coding style, ocamlformat is a recent arrival that, inspired by ReasonML’s refmt tool, uses a more comprehensive approach of end-to-end parsing and printing. Both tools can be integrated into editors to automatically lay out code as you write it.

  • ocp-indent is a coding style formatting tool that relies on heuristics and partial parsing rather than a full end-to-end parsing and printing approach, like ocamlformat below. The advantage of ocp-indent’s approach is that even partially-compiling files can be indented, as can code fragments.
  • ocamlformat is a comprehensive coding style formatting tool that parses the code and prints it out again. This follows the example of the refmt tool for Reason. While new, ocamlformat may eventually overtake ocp-indent.

Coding Style Guidelines

Documentation Best Practices

Writing Efficient Code