-
Notifications
You must be signed in to change notification settings - Fork 2
Style guide
We broadly follow http://snapframework.com/docs/style-guide . Some points of differences/clarification
80 columns is very restrictive, especially for functional code that tends to get very indented. It's a rule that dates to IBM punchcards, not for modern high-res monitors.
120 columns is a better rule, though often breaking that rule is better than excessive line splitting.
Instead of:
import Data.List (groupBy, nub)
write
import Data.List ( groupBy, nub )
No particular reason, just consistency and aesthetics.
There's a sense of beauty and cognitive ease that comes from seeing similar code lining up vertically. It is much easier to read:
foo ShortCon x = doAThing (fun1 x)
foo VeryLongConstructorName x = doAThing (fun2 x)
than
foo ShortCon x = doAThing (fun1 x)
foo VeryLongConstructorName x = doAThing (fun2 x)
In the former, it is very easy to identify that the two cases differ only in calling fun1 vs. fun2. The latter takes much more effort.
This kind of code is great in any language, but Haskell lets you write programs short enough to make it worth it, even without good tools that really should exist to do it for you.
Vertically align multiple import statements from the same package.
E.g.: instead of
import Data.Map ( Map )
import qualified Data.Map as Map
write
import Data.Map ( Map )
import qualified Data.Map as Map
See https://us16.campaign-archive.com/?u=8b565c97b838125f69e75fb7f&id=98894575a9
---------------------------------------------------------------
-------------- This is a major section of a file --------------
---------------------------------------------------------------
--------------------
------- A minor section
--------------------
------- Subsubsection