DeveloperStyleGuide - GaloisInc/cryptol GitHub Wiki

Developer Style Guide

Here are some style guide-lines for contributing code to Cryptol. The purpose of these guidelines is to simplify working on the code. None of these are hard rules, and it is perfectly reasonable to break them if a particular situation calls for it.

Import Order

Order imports by "distance" from the current module, with the most closely related imports at the bottom. Group related imports into groups separated by space. This helps create a mental model of what's related to what, it also can be used to give indication about where things come from (i.e., project internal vs. external libraries).

For example:

import Data.Map(Map)
import qualified Data.Map as Map

import Cryptol.ModuleSystem

Declarations

Avoid multi-equation declarations for types with more than a few constructors, using case instead. This makes the code more readable, and easier to maintain (e.g., rename a function or search for function occurrences).

For example:

-- Avoid:
someFun (Con1 x) = ..
someFun (Con2 x) = ..
someFun (Con3 x) = ..
someFun (Con4 x) = ..

-- Prefer:
someFun x =
  case x of
    Con1 x -> ..
    Con2 x -> ..
    Con3 x -> ..
    Con4 x -> ..