Appendix 5. How to name variables, methods, and classes correctly

A name should be clear at least to you, and ideally-to anyone else reading your code. The name may be in any language. The only principle you should stick to is uniformity. We however recommend that you use English language (what if you become world-famous one day?). Words in names had better be in singular. Whenever a need occurs, use compound names like "column_color": it is always easy to understand what such a name implies.

Parser is case-sensitive!

$Parser and $parser are different variables!

There are certain characters which should not be used in names. In Parser, name ends before:
space character
tab character
newline character
; ] } ) " < > # + * / % & | = ! ' , ?
character "-" in expressions.

Code…

$var[value_of_variable]
$var>text

…outputs…

value_of_variable>text

…, i.e. Parser regards character ">" as end of name of variable
$var and outputs its value. That is why the characters listed above had better be avoided in names.

Whenever one needs any of characters not listed above to immediately (i.e. with nothing in between) follow a variable's value, one should use syntax:
${var}.text

In this case, the output will be:
value_of_variable.text

One must NOT use characters "
.", ":", "^" in names, since these will be regarded as part of Parser's code, which will inevitably cause errors during code processing.

All other symbols are allowed, theoretically. We however recommend that you use no special characters at all when giving names, except in case you really have to (that is, practically, NEVER). The only character we recommended to use is underscore, which is not reserved by Parser and whose meaning is clear enough.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 01.04.2004