Add rules for condition evaluations
parent
b724a02cb5
commit
e3321ca524
1 changed files with 11 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
These are the code style guidelines that should be followed when contributing to zim.
|
These are the code style guidelines that should be followed when contributing to Zim.
|
||||||
|
|
||||||
Indentation
|
Indentation
|
||||||
-----------
|
-----------
|
||||||
|
@ -18,7 +18,7 @@ for x in a very very very very \
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
Line Length
|
Line length
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Be reasonable. Keeping within 80 characters is recommended, 120 is the maximum.
|
Be reasonable. Keeping within 80 characters is recommended, 120 is the maximum.
|
||||||
|
@ -37,15 +37,21 @@ Use existing variables whenever possible:
|
||||||
* Good: `${PWD}` `${USER}`
|
* Good: `${PWD}` `${USER}`
|
||||||
* Bad: `$(pwd)` `$(whoami)`
|
* Bad: `$(pwd)` `$(whoami)`
|
||||||
|
|
||||||
Flow Logic
|
Flow logic
|
||||||
----------
|
----------
|
||||||
|
|
||||||
For short single commands, prefer one-liners:
|
For short single commands, prefer one-liners:
|
||||||
* `for` with the zsh syntax: `for x (foo bar) print ${x}`
|
* `for` with the Zsh syntax: `for x (foo bar) print ${x}`
|
||||||
* `&&` instead of if: `(( ! ${+FOO} )) && FOO='bar'`
|
* `&&` instead of if: `[[ -d ${dir} ]] && cd ${dir}`
|
||||||
|
|
||||||
Otherwise just place `; do` `; then` on the same line as `while`, `for ... in`, and `if`.
|
Otherwise just place `; do` `; then` on the same line as `while`, `for ... in`, and `if`.
|
||||||
|
|
||||||
|
Use `(( ))` for arithmetic conditions, and `[[ ]]` for other condition evaluations. Don't use `[ ]`.
|
||||||
|
|
||||||
|
With arithmetic conditions:
|
||||||
|
* Don't use `$` in front of variables: `(( var > 1 ))`
|
||||||
|
* Unless some substitution is needed: `(( ${#var} > 1 ))`
|
||||||
|
|
||||||
Functions
|
Functions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
@ -63,4 +69,3 @@ Misc
|
||||||
|
|
||||||
Do **NOT** use backticks ``` ` ``` to execute something in a subshell. This GRINDS MY GEARS.
|
Do **NOT** use backticks ``` ` ``` to execute something in a subshell. This GRINDS MY GEARS.
|
||||||
`$(print "use parentheses")`
|
`$(print "use parentheses")`
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue