Naming

Sather - Language Specification
Prev | Chapter 14. Conventions | Next

# 14.2. Naming

In addition to 'create', there are a number of other naming conventions:

- Classes which are related should reflect this in their names. For example, there are many examples in the library of an abstraction, classes implementing the abstraction, and code testing implementations of the abstraction. For example, in the standard library the set abstraction is named $SET, H_SET is a hash table implementation, and the test code is TEST_SET.

- Some classes implement an immutable, 'mathematical' abstraction (eg. integers), and others implement mutable abstractions that can be modified in place (eg. arrays). Sometimes is is possible to have both immutable and mutable abstractions for the same concept. The former are usually easier to reason about and safer to program with, while the later can be more efficient. It is very important not to confuse the two: objects that at any time represent a set are not sets themselves. They have entirely different properties, such as observable aliasing and having an equality relation that changes over time.

> NOTE: Classes with immutable semantics are given their 'mathematical' names: STR, VEC, $SET. Mutable classes that represent a value that may change over time have the prefix 'OB': OBSTR, OBVEC, $OBSET. When both versions exist, the method 'value' is used to take a 'snapshot' of the object's state, converting from the mutable to the immutable form.

- Conversions from a type FOO to a type BAR occur in two ways: by defining an appropriate 'create' routine in BAR as seen above, or be defining a routine 'bar:BAR' in FOO. For example, in the standard library conversion of a FLT to a FLTD is done by calling the routine 'fltd:FLTD' defined in FLT.

- Methods which return a BOOL (predicates) should have the prefix 'is_'. For example, 'is_prime' tests integers for primality.

- Abstract classes that require a single method should be named after that method. For example, subtypes of $HASH define the method 'hash'.

- If there is a single iterator in a container class which returns all of the items, it should be named 'elt!'. If there is a single iterator which sets the items, it should be named 'set!'. In general, iterators should have singular ('elt!') rather than plural ('elts!') names if the choice is arbitrary.

Prev | Home | Next
Conventions | Up | Object Identity