-
Notifications
You must be signed in to change notification settings - Fork 113
Naming style guidelines
-
As function is the process, - therefore in the function names the main strong word is the verb. It is best for the verb to be the first or only word in the function name. The most useful writing advice (for literature writers) - is to use strong verbs instead of auxiliary words ("very") or adjectives. A good thing to look at.
-
Builders are functions - they start with
mk. -
Unnamed local functions are
fun. -
Unnamed recursive local functions are
go. If the function does not have recursion - please, do not name itgoname. & recursion is always a special thing important to know about.For counterexample -
adiis a bad name for a function, acronyms generally are, especially if consider no sufficient explanation is given for it,adiis forAbstract Definitional Interpreters- which is just great ... It still does not say much but at least some direction to several Computer Science papers to read. In reality, all it does & is for is tointerleaveactions or data layers in data type, embellish,addsMetaInformation/Annotationto something. But generaladiisinterleave. -
Please, use
{fold,sequence,traverse,show,put,map,bind}& other verbs of famous type classes inside the function names with that main assence. -
Since HNix is also a library, functions that are generalized/customizable/transformation-able versions of a default implementation function & ends with an
F, as having a higher-order functor nature added to the main implementation. Examples would beMonadThunk{,F}type classes with functions accordingly named ending in{,F}, asFfunctions take in a Kleisli arrow they pass around. -
Instead of
Fnames can haveAfor applicative andMfor monad - if they indeed have Applicative of Monad nature of computation, but since applicatives & monads are functors (in terms of theory - applicative functor and every functor is a monad, every monad is a functor),Fis recommended default choice.Quite frequently the code implementation is too generalized (for example the
Valuemodule methods) for "project as a library" purposes, while for "project as an implementation" purposes the default implementation are created, in that case, the generalized versions become renamed to haveF.
-
-
Main word in an object (variable/data type (kind
*)) - is (mainly) a noun.- Data & type constructors are considered variables - they are nouns (or adjectives).
- Data record:
- Start with a
get. -
newtypes go without record & use Haskell Core'scoercewith adding type-level signatures (documentation) to local functions. Ifnewtypeis too hard for GHC to infercoercein polymorphism - only then add a recordunTypeNameto use it.
- Start with a
-
Starting anything with
_reserved to named bottom/typed holes. GHC & HLS specifically support this way. Those provide code readability, for exampleotherwisesays nothing,_NixStringOrStringLike- is descriptive, so when bottom trap bug is found - contributor can tell for what case that bottom was created for. They also give a hint at the functionality to implement, or functionality/argument that can be reduced.
In other cases https://kowainik.github.io/posts/naming-conventions is recommended.