9.5 Naming Conventions

The way functions are named has been unified in GAP 4. This might help to memorize or even guess names of library functions.

If a variable name consists of several words then the first letter of each word is capitalized.

If the first part of the name of a function is a verb then the function may modify its argument(s) but does not return anything, for example Append appends the list given as second argument to the list given as first argument. Otherwise the function returns an object without changing the arguments, for example Concatenation returns the concatenation of the lists given as arguments.

If the name of a function contains the word By then the return value is thought of as built in a certain way from the parts given as arguments. For example, GroupByGenerators returns a group built from its group generators, and creating a group as a factor group of a given group by a normal subgroup can be done by taking the image of NaturalHomomorphismByNormalSubgroup (see also Homomorphisms vs. Factor Structures). Other examples of ``By'' functions are GroupHomomorphismByImages and UnivariateLaurentPolynomialByCoefficients.

If the name of a function contains the word Of then the return value is thought of as information deduced from the arguments. Usually such functions are attributes (see Attributes in this Tutorial and Attributes in the Reference Manual). Examples are GeneratorsOfGroup, which returns a list of generators for the group entered as argument, or DiagonalOfMat.

For the setter and tester functions of an attribute attr (see Attributes vs. Record Components in this Tutorial and Attributes in the Reference Manual) the names Setattr resp. Hasattr are available.

If the name of a function fun1 ends with NC then there is another function fun2 with the same name except that the NC is missing. NC stands for ``no check''. When fun2 is called then it checks whether its arguments are valid, and if so then it calls fun1. The functions SubgroupNC and Subgroup are a typical example.

The idea is that the possibly time consuming check of the arguments can be omitted if one is sure that they are unnecessary. For example, if an algorithm produces generators of the derived subgroup of a group then it is guaranteed that they lie in the original group; Subgroup would check this, and SubgroupNC omits the check.

Needless to say, all these rules are not followed slavishly, for example there is one operation Zero instead of two operations ZeroOfElement and ZeroOfAdditiveGroup.

[Top] [Previous] [Up] [Next] [Index]

GAP 4 manual
February 2000