1
0
Fork 0
mirror of synced 2024-11-22 07:25:33 -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: Use existing variables whenever possible:
```diff ```diff
- print "$(whoami) in $(pwd)" -print "$(whoami) in $(pwd)"
+ print "${USER} in ${PWD}" +print "${USER} in ${PWD}"
``` ```
Limit the scope of variables to `local` when within a function. 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: When declaring a global variable, be explicit and do it using `typeset -g`. This avoids warnings when `WARN_CREATE_GLOBAL` is set:
```diff ```diff
- : ${VAR=1} -: ${VAR=1}
+ if (( ! ${+VAR} )) typeset -g VAR=1 +if (( ! ${+VAR} )) typeset -g VAR=1
``` ```
Flow logic Flow logic
@ -59,10 +59,11 @@ Functions
--------- ---------
Use POSIX syntax: Use POSIX syntax:
``` ```diff
foo() { -function foo {
print 'bar' +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. 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.