-
Notifications
You must be signed in to change notification settings - Fork 86
Style Guide
Jonathan Chan edited this page Aug 25, 2019
·
5 revisions
Due to the long and varied history of LambdaNative and the lack of automated style linting, the coding style throughout the repository may be inconsistent. Nevertheless, the below is a guide for all future contributions.
- Never use tabs; always use spaces. Indentation is two spaces in most places.
- Lines may not have trailing spaces.
- Files must end in a newline.
- In
let
-style expressions, declare bindings on separate lines and align the inner parentheses. Use one level of indentation for the body.
(let ((var1 0)
(var2 #t)
(var3 ""))
...)
(let* ((var1 0)
(var2 #t)
(var3 ""))
...)
(letrec ((var1 0)
(var2 #t)
(var3 ""))
...)
- In
cond
expressions, align the test expressions on separate lines with one level of indentation. If the body is too long, put it on a separate line with an additional level of indentation.
(cond
(test1 0)
(test2 #f)
(test3
"this is a very long result")
(else
"this is another very long result"))
- In
if
expressions, if the test expression and the two cases are very short, they may all go on one line. Otherwise, then and else cases should be aligned on separate lines. Often the cases arebegins
; the keyword may go on the same line as the test expression if there is only a then case, or they may be aligned as usual.
(if condition result1 result2)
(if condition
"this is a longer then result"
(string-append "this is a longer " "else result"))
(if condition
(func1 "do something"))
(if condition (begin
...
...)
(if condition
(begin
...
...)
(begin ...))
- In
lambda
,define
, orbegin
expressions, the body is typically on separate lines with one level of indentation, but short bodies may be on the same line as the keyword.
(lambda (arg1 arg2 . args)
...
...)
(lambda args ...) ;; _
;; λ -=(')
(define var1 #f) ;; ;;
;; //
(define (func1 arg1 arg2) ;; //
... ;; : '.---.__
...) ;; | --_-_)__)
;; `.____,'
(begin ;; \ \
... ;; ___\ \
...) ;; ( \
;; \
(begin ...) ;; /
- Closing parentheses are usually stacked, but sometimes when the body of the current expression is vertically long, the parentheses may be hanging to more clearly delineate the extent of an expression. Follow the patterns currently used in the file wherever possible.
- Use kebab case for functions and snake case for variables, prefixed with the module name, separated by a colon rather than a dash or an underscore if it is intended to be private to a file, e.g.
module-my-public-function
,module:my-private-function
, andmodule:my_private_variable
. - Variables should be private to a file and accessed using getters and setters, often named
module-variable-get
andmodule-variable-set!
. - Functions whose main purpose is to return a boolean (e.g. to check for certain properties) are sometimes postpended with a question mark, e.g.
(define (contains-numbers? str) ...)
. - Prefer longer, more descriptive names over shorter, tenser names, unless the short name is conventionally used, e.g.
x
,y
for coordinates,w
,h
for dimensions,g
,wgt
for the main gui and a widget. - Named
let
s are usually namedloop
when their main purpose is to recursively loop.
(let loop ((var1 0) (var2 #f))
...
...
(loop (+ var1 1) #t))
-
- accelerometer
- alist
- audio
- audioaux
- base64
- btle-scan
- camera
- cdb
- cgi
- config
- csv
- curl
- digest
- dmtx
- download
- eventloop
- fcgi
- fft
- generalized-arrays
- gps
- graph
- gyro
- hidapi
- hpdf
- html
- httpsclient
- hybridapp
- json
- lmdb
- ln_core
- ln_glcore
- ln_glgui
- ln_store
- localization
- localization_gui
- localnotification
- magnetometer
- mdns
- mqtt
- mqtt-store
- multitouch
- oauth
- orientation
- p256ecdsa
- png
- portaudio
- pregexp
- pressure
- prime
- pushnotification
- redcap
- rsa
- rtaudio
- rupi
- rotation
- sanestring
- scheduler
- serial
- sets
- settings
- simplexnoise
- sqlite
- ssax
- syntax-case
- timestamp
- ttf
- uiform
- url
- uuid
- vibrate
- videoplayer
- watchdog
- website
- xml
- zip