From 12ff1c270210965abb741ae16da8cfcfeb061eb2 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 24 Jan 2021 10:23:52 +0100 Subject: [PATCH] doc: document the new const rule --- doc/docs.md | 15 +++++++++++---- vlib/v/checker/tests/var_duplicate_const.out | 7 ------- 2 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 vlib/v/checker/tests/var_duplicate_const.out diff --git a/doc/docs.md b/doc/docs.md index ef88fb6cfd..9d00d9828d 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1716,15 +1716,22 @@ const ( blue = rgb(0, 0, 255) ) -println(numbers) -println(red) -println(blue) +println(main.numbers) +println(main.red) +println(main.blue) ``` Global variables are not allowed, so this can be really useful. +When naming constants, `snake_case` must be used. In order to distinguish consts +from local variables, the full path to consts must be specified. For example, +to access the PI const, full `math.pi` name must be used both outside the `math` module, +and inside it. This can be seen in the example above with `println(main.numbers)`. + +vfmt takes care of this rule, so you can type `println(pi)` inside the `math` module, +and vffmt will automatically update it to `println(math.pi)`. +