This appendix describes some of the naming conventions I've developed while working on The Castle on Fire. Improvisation and experimentation are encouraged, but you might find these guidelines to be a useful starting point.
= suffix is for functions/methods which perform an assignment, the
! suffix is for
functions/methods which perform any other kind of destructive mutation, and the
? suffix is for
boolean variables and for functions/methods which return booleans. For conversions, consider
src->dst for a function or
->dst for a method.
lower-kebab-case is used for local variables,
let-macro macros, built-in
functions, built-in macros, class fields, class clauses, and keyword symbols like
'ok. If you're
defining a function or macro which is intended to be very global, such as a new control-flow macro
or a new numeric function, you should similarly use unprefixed
UpperCamelCase is used for classes, states and
RData types. This includes mixins, structs,
local classes defined with
let-class, and variables which store classes. Class names should
avoid prefixes where possible:
Sprite rather than
follows the same rules as for a Rust struct, e.g.
HudPopup rather than
RData's constructor function should be a global variable, named to resemble a class constructor:
(Sprite rgb w h),
(PhysicsRect coords). If an
RData or a class has multiple possible
constructors, globally bind a function to the type name, plus a suffix:
(TileLayer:from-arr tiles). In general, when manipulating
RData and objects, prefer methods over
Global functions and global variables are categorized into de-facto modules with very short
res. Global names are prefixed with their "module":
let variables and
let-fn functions are similarly
prefixed, mostly to differentiate them from local variables.
(defn phys:step () ...) (let-fn phys:box-coords (box) ...)
A small number of ubiquitous global variables are prefixed with
:, purely to make them more
brief. For example,
:clock for the current game-time,
:dt for the "delta time" since the last
:screen-w for the pixel width of the back buffer.