Page MenuHomePhabricator

Style
Updated 753 Days AgoPublic

Purpose

Style conventions help programmers to make the most of the language's syntax and features and generally unifies everyone around a common convention, reducing the effort needed to both read and write code.

All recommendations regarding Ratscript style should go in this document. These are not enforced by the language interpreter itself, but should be highlighted by any linters and automatically enforced by auto-formatters. A good IDE should do both of these things, in compliance with this standard.

Naming

There are three broad groups of names in Ratscript, using one of three cases:

Class namesUse UpperCamelCase
Function and variable namesUse lower_snake_case
Constant namesUse SCREAMING_SNAKE_CASE

Indentation

Whitespace is largely ignored by Ratscript, but it can aid in reading. Place either two spaces or one tab after every subordination operator to improve readability. We recommend two spaces, which is used throughout all our documents.

if foo
;  if bar
;  ;  print("Foobar!")
;  else
;  ;  print("Foo")

You'll see how this creates a straight line between statements at the same subordination level.

Operator Spacing

Binary operators should be padded on either side with a single space:

make sum = 40 + 2

Unary operators need no such padding.

make sum = sum++

No padding should be used with parentheses or brackets:

print("Hello!")
make first_element = some_list[0]

Line Limits

Line length should be limited to 80 columns. This should be more than sufficient for most code, and the line continuation operator (...) should help facilitate this.

In the rare case more space is needed, 120 columns is permissible, but code should never exceed 120 columns.

Lambda Expressions

Short lambda expressions should go on one line:

make num_plus_ten = lambda a ; a + 10

Mutability

Requiring a mutable reference to be passed to a function, while possible, is strongly discouraged. See Mutability for more information.

Typing

Explicit typing is preferred on a define statement, especially if possibly ambiguous, to drive home that it cannot be changed or implicitly casted elsewhere:

define ANSWER as int = 42
Last Author
emlarson
Last Edited
Jul 22 2020, 2:27 PM