clone url: git://git.m455.casa/fa
doc/style-guide-programming.md
This document outlines preferred programming styles when contributing to the fa project.
This document is mainly for my friend Will Sinatra who knows I'm not actually as picky as I seem in this guide.
This section describes naming conventions related to the shortening of names, locals, functions, and parameters.
This section consists of the following subsections:
Prefer kebab case over other cases.
user-str
arg-tbl
some-seq
local-network
userStr
Argtbl
some_seq
LocalNetwork
Prefer guessable, three-letter names if you are shortening a name.
arg-table
can be shorted to arg-tbl
some-sequence
can be shorted to arg-seq
arg-string
can be shorted to arg-str
arg-number
can be shorted to arg-num
arg-table
shouldn't be shortened to arg-t
some-sequence
shouldn't be shortened to arg-s
arg-string
shouldn't be shortened to arg-s
arg-number
shouldn't be shortened to arg-n
Prefer to prefix names with a category if they fall under the same category.
(local cmd-add "add")
(local cmd-rm "rm")
(local cmd-ls "ls")
(local add-cmd "add")
(local rm-cmd "rm")
(local ls-cmd "ls")
(Yes, I did this in the original code, and I need to fix it haha!)
Prefer verbose, descriptive local names, unless you can shorten the name according to the Shortening names section.
number-found
number-received
num-found
num-received
n-found
n-received
Prefer verbose, descriptive function names, unless you can shorten the name according to the Shortening names section.
If the function returns true
or false
, add a ?
at the end of the function
name.
nil?
string?
user-id->string
user-id->str
get-user-id
stringify-user-id
user-id-to-string
s-user-id
user-id-s
user-id-to-s
Prefer verbose, descriptive parameter names, unless you can shorten the name according to the Shortening names section.
Append the parameter type at the end of the name, shortening to a three-letter type, if possible.
(fn greet-user [name-str]
(print (.. "Hello, " name-str)))
(fn grt-u [n]
(print (.. "Hello, " n)))
Prefer verbose, descriptive parameter names, unless you can shorten the name according to the Shortening names section.
Append the parameter type at the end of the name, shortening to a three-letter type, if possible.
(fn greet-two-numbers [num-1 num-2]
(let [num-1-str (tostring num-1)
num-2-str (tostrign num-2)
nums-combined (.. num-1-str num-2-str)]
(print (.. "Hello, " nums-combined))))
(fn greet-two-numbers [num-1 num-2]
(let [n-1-str (tostring num-1)
n-2-str (tostrign num-2)
n-combined (.. n-1-str n-2-str)]
(print (.. "Hello, " n-combined))))
This section describes preferred indentation conventions.
This section consists of the following subsections:
Prefer two-spaced indentation, instead of tabs.
Indent let bindings so they line up vertically.
(fn greet-two-numbers [num-1 num-2]
(let [num-1-str (tostring num-1)
num-2-str (tostrign num-2)
nums-combined (.. num-1-str num-2-str)]
(print (.. "Hello, " nums-combined))))
(fn greet-two-numbers [num-1 num-2]
(let [num-1-str (tostring num-1)
num-2-str (tostrign num-2)
nums-combined (.. num-1-str num-2-str)]
(print (.. "Hello, " nums-combined))))
Indent match patterns and result functions so they line up vertically.
If the pattern is too long, move the result function one line below the pattern.
``` (match arg-tbl [cmd-add date-str event-str nil] (add date-str event-str)
[cmd-rm date-str nil] (rm date-str))
(match arg-tbl
[cmd-add date-str event-str nil] (add date-str event-str)
[cmd-help nil] (help)
[cmd-init nil] (init)
[cmd-rm date-str nil] (rm date-str))
If you start using a new abbreviation, add it to the list below.
tbl = table
str = string
num = number
seq = sequence