7.7. Naming conventions¶
Variable names in Kink have syntactical roles. If a function is stored in a variable whose symbol is a function symbol, which does not contain upper case letters, the function can be called by its symbol. In contrast, a function in a variable whose symbol is a data symbol cannot be called by its symbol.
Note
The distinction between function variables and data variables was inspired by the orthography of German language, where nouns are capitalized.
Variable names also can indicate their accessibility.
For example, if a method name starts from _,
the method is private.
This chapter describes other aspects of naming conventions of variables.
7.7.1. Words are separated by underscores¶
Words of variable symbols should be separated by an underscore _.
Examples: open_to_read, _make_config, More_lines?.
7.7.2. Only the first letter of a data variable should be capitalized¶
As a general rule, only the first letter of a data variable
should be capitalized.
Examples: X, Tree, Valid_arg?.
As an exception, a variable containing a module should be the end part
of the module name.
For example, kink/BIN module should be stored in BIN variable.
Example:
:BIN.require_from('kink/')
:Prefix <- BIN.of(0xca 0xfe 0xba 0xbe)
stdout.print_line(Prefix.repr) # => (bin 0xca 0xfe 0xba 0xbe)
As another example, if a data variable refers to a symbol of a different
programming language,
it is permissible to have multiple uppercase letters.
For example, a variable which represents Java class
java.util.ArrayList can be named as ArrayList_class.
7.7.3. ? at the end of Bool variables and functions¶
A symbol of a data variable which contains a bool value,
or a function which returns a bool value
should end with ?.
Examples: Null?, More_lines?, is?, _valid_type?