summaryrefslogtreecommitdiff
path: root/doc/styleguide.txt
diff options
context:
space:
mode:
authorGabriel F. T. Gomes <gabriel@inconstante.net.br>2020-08-03 18:43:13 -0300
committerGabriel F. T. Gomes <gabriel@inconstante.net.br>2020-08-03 18:43:13 -0300
commit95623d39d6029ba78ec96ad5ea08e9ac12629b91 (patch)
treeea0fe36eb5e6f40e0a1f765d44c4b0c0b2bfb089 /doc/styleguide.txt
parent019f3cc463db63abc6460f97deb488deec43840b (diff)
downloadbash-completion-95623d39d6029ba78ec96ad5ea08e9ac12629b91.tar.gz
New upstream version 2.11upstream/2.11upstream
Diffstat (limited to 'doc/styleguide.txt')
-rw-r--r--doc/styleguide.txt25
1 files changed, 24 insertions, 1 deletions
diff --git a/doc/styleguide.txt b/doc/styleguide.txt
index 31ad4469..2251e773 100644
--- a/doc/styleguide.txt
+++ b/doc/styleguide.txt
@@ -61,7 +61,7 @@ need that kind of processing (e.g. file and command names). The
_filedir and _filedir_xspec helpers do this automatically whenever
they return some completions.
-&#91;[ $COMPREPLY == *= ]] && compopt -o nospace
+&#91;[ ${COMPREPLY-} == *= ]] && compopt -o nospace
------------------------------------------------
The above is functionally a shorthand for:
@@ -95,6 +95,29 @@ explicitly handled (non-completed) in the $prev handling block because
--foo=bar options can often be written without the equals sign, and in
that case the long option splitting does not occur.
+Use arithmetic evaluation
+-------------------------
+
+When dealing with numeric data, take advantage of arithmetic evaluation.
+In essence, use (( ... )) whenever it can replace [[ ... ]] because the
+syntax is more readable; no need for $-prefixes, numeric comparison etc
+operators are more familiar and easier on the eye.
+
+Array subscript access
+----------------------
+
+Array subscripts are arithmetic expressions, take advantage of that.
+E.g. write ${foo[bar]}, not ${foo[$bar]}, and similarly ${foo[bar+1]}
+vs ${foo[((bar+1))]} or ${foo[$((bar+1))]}, ${foo[--i]} vs ${foo[((--i))]}.
+
+Loop variable names
+-------------------
+
+Use i, j, k for loop-local indices; n and m for lengths; some other descriptive
+name typically based on array name but in singular when looping over actual
+values. If an index or value is to be accessed later on instead of being just
+locally for looping, use a more descriptive and specific name for it.
+
/////////////////////////////////////////
case/esac vs if
---------------