From 12123f05404c51a024b1d49ecc3d992af764fd3b Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 14 Dec 2020 09:38:52 +0100 Subject: [PATCH] Style guide: Document avoidance of globals in Go code (#29803) * Chore: Document avoidance of globals in Go code Signed-off-by: Arve Knudsen --- contribute/style-guides/backend.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contribute/style-guides/backend.md b/contribute/style-guides/backend.md index 28f4dcaafed..5aacba09da3 100644 --- a/contribute/style-guides/backend.md +++ b/contribute/style-guides/backend.md @@ -39,3 +39,9 @@ Tests must use the standard library, `testing`. For assertions, prefer using [te The majority of our tests uses [GoConvey](http://goconvey.co/) but that's something we want to avoid going forward. In the `sqlstore` package we do database operations in tests and while some might say that's not suited for unit tests. We think they are fast enough and provide a lot of value. + +## Globals + +As a general rule of thumb, avoid using global variables, since they make the code difficult to maintain and reason +about, and to write tests for. The Grafana codebase currently does use a lot of global variables, especially when +it comes to configuration, but that is a problem we're trying to solve.