(I thought there was an issue about this already, but I can't find it.)
We need a basic linter for M2, but there needs to be a style guide first. We can use this issue to collect suggestions. I'll start with a few. Feedback for changing these are welcome!
Break any of the rules below when necessary for readability.
Use 4 space indents inside code after opened (, {, [, <|.
Use 4 space indents inside code after for, do, list, while, if, then, else, e.g.
if cond then (
multi-line code 1
)
else (
multi-line code 2
)
if cond
then result1
else result2
if cond then
result1
else
result2
while cond do
stuff
while cond
do stuff
while cond do (
multi-line stuff
)
for i in range do
stuff
for i in range
do stuff
for i in range do (
multi-line stuff
)
3. Use 4 spaces after `->` and `=>`, e.g.
```m2
longMethodName Module := Module => opts -> (n, R, M) ->
if n == 0 then R^1 else
if n > 0 then blah blah M else
error "expected non-negative integer"
longMethodName Ideal := Module => opts -> (n, R, I) ->
longMethodName(n, R, module I)
longMethodName Ideal := Module => opts ->
(n, R, I) -> longMethodName(n, R, module I)
H = new HashTable from {
"very very ......................................... very long key" =>
12,
}
When plausible, use spaces to tabulate keys and values in hash tables, e.g.
(I thought there was an issue about this already, but I can't find it.)
We need a basic linter for M2, but there needs to be a style guide first. We can use this issue to collect suggestions. I'll start with a few. Feedback for changing these are welcome!
(, {, [, <|
.for, do, list, while, if, then, else
, e.g.if cond then result1 else result2
if cond then result1 else result2
while cond do stuff
while cond do stuff
while cond do ( multi-line stuff )
for i in range do stuff
for i in range do stuff
for i in range do ( multi-line stuff )
Node, Key, ...
, but one more or less for cases like this is acceptable:(n, R, M)
.[x,y,z]
.dim(module(I) -- bad dim module I -- good
coker(gens(I M)) -- good coker gens(I M) -- good
-- exception: functions which accept only a single object func = (x) -> stuff