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:
|
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.
|
||||||
|
|
Loading…
Reference in a new issue