-
-
Notifications
You must be signed in to change notification settings - Fork 44
Naming Conventions
Lukas Obermann edited this page Sep 10, 2019
·
1 revision
Functions are generally named camel case. If there are overlapping functions names, e.g. when there are two accessor functions accessing an attribute of the same name, but different type, a prefix separated by an underscore is allowed.
const { wikiEntry, effect } = Advantage.A // Attribute accessors for record Advantage
/**
* `getAdvEffect :: Advantage -> String`
*/
export const getAdvEffect = pipe (wikiEntry, effect)
...
const { wikiEntry: spell_wikiEntry } = Spell.A
/**
* `getSpellEffect :: Spell -> String`
*/
export const getSpellEffect = pipe (spell_wikiEntry, effect)
- Functions that return an attribute of a value or a part of it have the name of the attribute.
Examples:id
,value
,description
- Functions that access some kind of state or reference are named
getX
, whereX
is the name of the part being accessed.
Examples:getCurrentHeroId
,getSpellEffect
- Functions returning a value with an attribute set to a new value are named
setX
, whereX
is the name of the attribute or part being set. Usually, this type of function does not contain any computation or deep state access.
Examples:setId
,setTotalAP
- Functions that set some kind of state or reference are named
putX
, whereX
is the name of the part being accessed.
Examples:putCurrentHeroId
,putHeroEntry
- Functions returning a container
X
modified by a function of typea -> a
have the nameupdateX
.
Example:updateTotalAP :: (Int -> Int) -> Hero -> Hero
- Functions modifying a container
X
by a function of typea -> a
have the namemodifyX
.
Example:modifyHero :: (Hero -> Hero) -> Hero -> Hero
, although a special function might not make sense in that specific case ... imagine one or two additional params.
- Predicates testing a property
X
have the nameisX
.
- Functions converting a value of type
X
to a value of typeY
have the namexToY
with all leading uppercase characters ofX
converted to lower case.
Example:maybeToList
- Overloaded functions have the name
toX
orfromX
, depending on if they convert to or from a specific type, respectively.
Examples:toInt
,fromJSON
-
g_
: A variant ofg
with only tiny changes. Haskell:g'
-
gF
: Flipped version (first two arguments) ofg
. -
gS
: Safe version ofg
. -
gL
: Lens version ofg
.
Example: Accessorvalue
and corresponding lensvalueL
, if both are present. The lens would need to be renamed manually though, as its default name would bevalue
, too.
- Functions and actions which are potentially dangerous to use and leave some kind of proof obligation to the programmer have the name
unsafeX
.
Example:unsafeIndex :: Int -> [a] -> a
: Get the element at the specified index in the list. Throws if list not that long.
Variables can be named camel case or snake case, but, to prevent shadowing functions, snake case is prefered.
const mwiki_entry = lookup ("SPELL_12") (spells) // Wrapped in Maybe
const ewiki_entry = maybeToEither ("Not found.") (mwiki_entry) // Wrapped in Either
... some logic ...
const wiki_entry = fromRight (ewiki_entry) // Unwrapped value
-
mx
: aMaybe
ofx
. -
ex
: anEither
ofx
.
Main Tables
- Advantages, Disadvantages, Special Abilties
- Attributes
- Blessings
- Books
- Cantrips
- Combat Techniques
- Cultures
- Equipment
- Experience Levels
- Liturgical Chants
- Profession Variants
- Professions
- Race Variants
- Races
- Skills
- Spells
- UI
Subtables
Additional Tables
Programming
Data Structures