mmap.page

Express more in code

Code tends to be clearer and more precise.

Math formula

The traditional math language has a lot of issues:

Instead of writing , I’d rather just write e = m * (c ** 2).

Tables

Most tables can be converted to code in a clear way. For example:

Strength Dexterity Constitution
9 (-1) 11 (+0) 10 (+0)

Via direct variable declaration:

strength = 9;
strength_modifier = -1;
dexterity = 11;
dexterity_modifier = 0;
constitution = 10;
constitutito_modifier = 0;

Or via a data structure:

class AbilityScore(Integer score) {
  assert(score >= 1 && score <= 30);
  shared Integer modifier => floor((score - 10) / 2.0).integer;
}
value strength = AbilityScore(9);
value dexterity = AbilityScore(11);
value constitution = AbilityScore(10);

In fact, the later form reveals the relationship between ability and modifier.

Choices of language

Examples of suitable languages:

Some of the above languages have pitfalls in practical projects, such as design flaws (Go), dynamic typing (Scheme, Lua, Groovy), lack of libraries (Scheme, TypedRacket, Lua, Swift), less powerful IDE and debugging support (Scheme, TypedRacket, Lua), and restrict to certain platforms (Swift). These issue does not affect brief code samples though.

If a language with C like syntax is chosen, then it is recommended to use the Java style (opening braces on same line) and a indent level of 2 spaces. This saves space and does not harm readability for brief code samples.