Updated Code Style Guide (markdown)
parent
1cc3006502
commit
f438642d9b
1 changed files with 9 additions and 8 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue