Update Indentation and Flow Logic sections
parent
ef9c24d8f0
commit
b724a02cb5
1 changed files with 19 additions and 9 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
|
||||
-----------
|
||||
|
@ -9,6 +9,15 @@ Not hard tabs. Not four spaces. Not however many spaces you feel like.
|
|||
|
||||
2 spaces.
|
||||
|
||||
When using line continuations, indent with 2 extra spaces:
|
||||
|
||||
```
|
||||
for x in a very very very very \
|
||||
very very very long line; do
|
||||
print ${x}
|
||||
done
|
||||
```
|
||||
|
||||
Line Length
|
||||
-----------
|
||||
|
||||
|
@ -19,22 +28,23 @@ Variables
|
|||
|
||||
Limit the scope of variables to `local` if within a function.
|
||||
|
||||
Wrap your variables in `${curly}` `${braces}`.
|
||||
Wrap your variables in `${curly} ${braces}`.
|
||||
|
||||
Use `${snake_case}` for your variables.
|
||||
**NOT** `${camelCase}` or `${FuCk_you_iDoWhat_i_want}`.
|
||||
|
||||
Use existing variables whenever possible.
|
||||
|
||||
| Bad | Good |
|
||||
| --- | ---- |
|
||||
| `$(pwd)` | `${PWD}` |
|
||||
| `$(whoami)` | `${USER}` |
|
||||
Use existing variables whenever possible:
|
||||
* Good: `${PWD}` `${USER}`
|
||||
* Bad: `$(pwd)` `$(whoami)`
|
||||
|
||||
Flow Logic
|
||||
----------
|
||||
|
||||
Place `; do` `; then` on the same line as `while`, `for`, and `if`.
|
||||
For short single commands, prefer one-liners:
|
||||
* `for` with the zsh syntax: `for x (foo bar) print ${x}`
|
||||
* `&&` instead of if: `(( ! ${+FOO} )) && FOO='bar'`
|
||||
|
||||
Otherwise just place `; do` `; then` on the same line as `while`, `for ... in`, and `if`.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
|
Loading…
Reference in a new issue