diff options
Diffstat (limited to 'doc/styleguide.txt')
-rw-r--r-- | doc/styleguide.txt | 25 |
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. -[[ $COMPREPLY == *= ]] && compopt -o nospace +[[ ${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 --------------- |