From 894f6c7e1a96cc89704ca3d6144cc1fb2f49dd3b Mon Sep 17 00:00:00 2001
From: Matias Barcenas <5618628+MPX4132@users.noreply.github.com>
Date: Tue, 9 Jan 2018 16:34:38 -0600
Subject: [PATCH] Added some conventions and clarified others.
---
Code-style-guide.md | 58 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 49 insertions(+), 9 deletions(-)
diff --git a/Code-style-guide.md b/Code-style-guide.md
index 0f701c8..77bb047 100644
--- a/Code-style-guide.md
+++ b/Code-style-guide.md
@@ -9,11 +9,41 @@ Not hard tabs. Not four spaces. Not however many spaces you feel like. **2 space
## Line Length
Be reasonable. Keeping within 80 characters is recommended, 120 is the **maximum**.
+## Functions
+* Use existing functions whenever possible to avoid pollution.
+* Identify functions using **snake-case**.
+* Prefix identifiers with the **lowercased** script name defining them.
+
+For example, "fluxion_set_language"
+
+This function is prefixed with "fluxion" to signify it belongs to the fluxion script. We use camel-case because identifiers look more like regular commands.
+
+
## Variables
* Limit the scope of variables to local if within a function.
-* Wrap your variables in ${curly} ${braces}.
-* Use ${snake_case} for your variables. NOT ${camelCase} or ${FuCk_you_iDoWhat_i_want}.
-* Use existing variables whenever possible.
+* Wrap your variables in ${curly} ${braces} for clarity.
+* Use existing variables whenever possible to avoid pollution.
+* Identify variables using **camel-case**.
+* Prefix identifiers with the **capitalized** script name defining them.
+
+For example, the global "FluxionLanguage"
+
+This global is prefixed with "Fluxion" to signify it belongs to the fluxion script. Using camel-case makes it clear it's not a subroutine.
+
+
+## Constants
+* Limit the scope of constants to local if within a function.
+* Wrap your constants in ${curly} ${braces} for clarity.
+* Use existing constants whenever possible to avoid pollution.
+* Identify constants using **camel-case**.
+* Prefix identifiers with the **uppercased** script name defining them.
+
+For example, "FLUXIONVersion"
+
+This global is prefixed with "FLUXION" to signify it belongs to the fluxion script. This makes it clear a constant was defined because it's uppercase-prefixed similar to old C constants.
+
+## Built-in Globals
+Use built-in globals when possible to avoid having to create sub-shells and save resources.
**Bad**
```
@@ -25,6 +55,7 @@ $(whoami)
${USER}
${PWD}
```
+
## Flow Logic
Place ; do ; then on the same line as while, for, and if.
@@ -32,12 +63,17 @@ Place ; do ; then on the same line as while, for, and if.
**Bad**
```
while true
-do
+do ...
+...
+done
```
**Good**
```
-while true;do
+while true; do
+...
+done
```
+
## Functions
**Use POSIX syntax:**
```
@@ -48,9 +84,13 @@ foo() {
NOTE: There are some exceptions but in general use POSIX.
## Misc
-Do NOT use backticks $() to execute something in a subshell.
+Do NOT use backticks (\`command\`) to execute something in a subshell.
+
Bad:
-`print "use parentheses"`
-
+```
+now=`date`
+```
Good:
-`print "use parentheses"`
+```
+now=$(date)
+```
\ No newline at end of file