From 1c890e4af958d9b9075356572145a264302623e4 Mon Sep 17 00:00:00 2001 From: Khas'Mek Date: Sun, 31 May 2015 08:24:16 -0400 Subject: [PATCH] Consistency in design and formatting update. --- Coding-style-guide.md | 189 ++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 82 deletions(-) diff --git a/Coding-style-guide.md b/Coding-style-guide.md index 6ba7601..62605f5 100644 --- a/Coding-style-guide.md +++ b/Coding-style-guide.md @@ -1,35 +1,39 @@ -## General Code Style ## +## General Code Style While you should follow the code style that's already there for files that you're modifying, the following are required for any new code. -### Indentation ### +### Indentation Indent 2 spaces. No tabs. Use blank lines between blocks to improve readability. Indentation is two spaces. Whatever you do, don't use tabs. For existing files, stay faithful to the existing indentation. -### Line Length and Long Strings ### +### Line Length and Long Strings Maximum line length is 80 characters. If you have to write strings that are longer than 80 characters, this should be done with a "here document" or an embedded newline if possible. Literal strings that have to be longer than 80 chars and can't sensibly be split are okay, but it's strongly preferred to find a way to make it shorter. -``` -# Bad: +##### _Bad:_ +```shell long_string_1="I am an exceptionalllllllllllly looooooooooooooooooooooooooooooooooooooooong string." +``` -# Good: +##### _Good:_ +```shell cat <&2 exit 1 fi +``` -# Good: use "$?" to get the last return value +##### _Good:_ use "$?" to get the last return value +```shell mv "${file_list}" "${dest_dir}/" if [[ "$?" -ne 0 ]]; then echo "Unable to move ${file_list} to ${dest_dir}" >&2 @@ -397,28 +420,30 @@ if [[ "$?" -ne 0 ]]; then fi ``` -## Features and Bugs ## +## Features and Bugs -### Command Substitution ### +### Command Substitution Use `$(command)` instead of backticks. Nested backticks require escaping the inner ones with `\`. The `$(command)` format doesn't change when nested and is easier to read. -``` -# Bad: +##### _Bad:_ +```shell var="`command \`command1\``" +``` -# Good: +##### _Good:_ +```shell var="$(command \"$(command1)\")" ``` -### Eval ### +### Eval Eval is evil! Eval munges the input when used for assignment to variables and can set variables without making it possible to check what those variables were. Avoid `eval` if possible. -## References ## +## References - [Shell Style Guide](https://google-styleguide.googlecode.com/svn/trunk/shell.xml) - [BASH Programming - Introduction HOW-TO](http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html) -- [Linux kernel coding style](https://www.kernel.org/doc/Documentation/CodingStyle) \ No newline at end of file +- [Linux kernel coding style](https://www.kernel.org/doc/Documentation/CodingStyle)