1
0
Fork 0
mirror of synced 2024-11-21 15:15:34 -05:00

Updated Code Style Guide (markdown)

Eric Nielsen 2022-01-11 19:52:26 -05:00
parent 1cc3006502
commit f438642d9b

@ -28,16 +28,16 @@ Use `${snake_case}` for your variable names.
Use existing variables whenever possible:
```diff
- print "$(whoami) in $(pwd)"
+ print "${USER} in ${PWD}"
-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:
```diff
- : ${VAR=1}
+ if (( ! ${+VAR} )) typeset -g VAR=1
-: ${VAR=1}
+if (( ! ${+VAR} )) typeset -g VAR=1
```
Flow logic
@ -59,10 +59,11 @@ Functions
---------
Use POSIX syntax:
```
foo() {
print 'bar'
}
```diff
-function foo {
+foo() {
print bar
}
```
NOTE: There *is* a difference between this and ksh style, but unless you know what it is and you're **sure** you need it, use POSIX.