From 1cc3006502e19105ca2b8367400f49425c6b34a3 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 10 Jan 2022 14:57:08 -0500 Subject: [PATCH] Use diff in Code Style Guide, as shown in https://calmcode.io/til/md-diffs.html --- Code-Style-Guide.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Code-Style-Guide.md b/Code-Style-Guide.md index 1dbbd5b..8564d70 100644 --- a/Code-Style-Guide.md +++ b/Code-Style-Guide.md @@ -22,19 +22,23 @@ Be reasonable. Keeping within 80 characters is recommended, 120 is the maximum. Variables --------- -Limit the scope of variables to `local` when within a function. - Wrap your variables in `${curly} ${braces}`. Use `${snake_case}` for your variable names. Use existing variables whenever possible: -* Good: `${PWD}` `${USER}` -* Bad: `$(pwd)` `$(whoami)` +```diff +- print "$(whoami) in $(pwd)" ++ print "${USER} in ${PWD}" +``` + +Limit the scope of variables to `local` when within a function. When declaring a global variable, be explicit and do it using `typeset -g`. This avoids warnings when `WARN_CREATE_GLOBAL` is set: -* Good: `if (( ! ${+VAR} )) typeset -g VAR=1` -* Bad: `: ${VAR=1}` +```diff +- : ${VAR=1} ++ if (( ! ${+VAR} )) typeset -g VAR=1 +``` Flow logic ----------