Naming Conventions

From MiniScript Wiki
Jump to navigation Jump to search

The MiniScript intrinsic functions and Mini Micro API have established the following conventions with regard to naming variables.

Capitalization

  • classes (maps intended to be used with new) use captialized CamelCase: Monster, RigidBody, InventoryItem
  • method names use camelCase, starting with lower-case, e.g.: print, calcTotal
  • variables follow the same convention: x, totalIncome

Nouns vs. Verbs

In general, methods that perform some operation should be active verbs, e.g. print, wait, applyDiscount. Clear abbreviations are acceptable when a name would otherwise be unwieldy, e.g. calcTotal instead of calculateTotal. Methods that merely return an attribute (whether stored or calculated) should be named for what they return, e.g. abs, average. (The line between these two cases can be fuzzy; favor a simple attribute name if the calculation is quick and has no side effects, but an active verb if the calculation may take some time or has any effects beyond returning the answer.)

Object references should be descriptive nouns, e.g. player, annualIncome.

Avoid Starting With an Underscore

Per the MiniScript manual, in most cases you should avoid starting any global variables or function names with an underscore. Identifiers starting with an underscore are often used by the host environment for special “under the hood” code, and name collisions there could cause problems.

Short Names

Very short variable names should be used only for fleeting purposes, such as loop counters in small loops, or parameter names in small functions. They are also often used when experimenting in a REPL. The following names are generally understood:

  • i, j: loop counters (usually numbers)
  • c: character (e.g. while looping over a string)
  • x, y: 2D coordinates
  • dx, dy: 2D offset
  • vx, vy: 2D velocity
  • t: time
  • dt: time step or offset
  • s: a string, or any sequence
  • m, d: a map (d is short for "dictionary")
  • l, a: a list (a is short for "array"; and note that l looks very similar to 1, and so should probably be avoided)