From b724a02cb51b46d5243ac59fb26cd5d2d286f5aa Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 24 Apr 2018 19:46:47 -0500 Subject: [PATCH] Update Indentation and Flow Logic sections --- Code-Style-Guide.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Code-Style-Guide.md b/Code-Style-Guide.md index ff6bc1c..a6811b9 100644 --- a/Code-Style-Guide.md +++ b/Code-Style-Guide.md @@ -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 ---------