From 5c95039b5b4a93631977d9260a3e6f1e2c899c57 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 15 May 2021 09:44:59 +0100 Subject: add draft --- TODO.md | 43 ++++++++++++++ ...5-15-personal-bash-coding-style-guide.draft.gmi | 67 ++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 TODO.md create mode 100644 content/gemtext/gemfeed/2021-05-15-personal-bash-coding-style-guide.draft.gmi diff --git a/TODO.md b/TODO.md new file mode 100644 index 00000000..786b99c9 --- /dev/null +++ b/TODO.md @@ -0,0 +1,43 @@ +buetow.org Gemini capsule +========================= + +This is the source code of my Gemini capsule. You can reach the site(s) here: + +* Via Gemini/Gemtext : [gemini://buetow.org](gemini://buetow.org) +* Via HTTP/HTML: [https://buetow.org](https://buetow.org) +* [Markdown via HTML viewer](./content/md/index.md) +* [Gemini via webproxy](https://portal.mozz.us/gemini/buetow.org) + +## Software I use to maintain this capsule + +* Text editor: [Vim](https://www.vim.org) +* Gemini server: [a-h/gemini](https://github.com/a-h/gemini) +* Some Bash scripting + +## HTTP fallback software used + +* Web server: [Apache HTTPD](https://httpd.apache.org) + +## TODO + +Adjust code to reflect the google style guide. Use this to practice navigating the Vim quickfix list. + +* comment complex functions +* comment all lib functions +* TODOs always with a name in it, e.g. "TODO(paul): BLabla" +* Breaking long pipes: Here I disagree, use a different long pipe breaking method and not the one in the google style guide. +* case: indent body with 2 spaces +* not agreeing w "quote your variables", only quote them then its making things clearer +* fix signle vs double quotes: strings without var interpolation +* not a google style: use strings yes and no as my own bools +* prefer quoting words not bare words: yes vs 'yes' +* [[ ]] is preferred over [ ] +* what struck me: "probably unintended lexicographical comparison +* eval (evil) should be avoided: my own alternative for setting vars w.o eval +* arrays: i personally try to design the script to use pipes for list processing. +* bash -c 'help readarray' trick, zsh alias/function for bash help +* avoid a stand alone (( i++ )) +* rename ./modules to ./packages +* buetow.org.conf: declare -xr FOO=bar both constant and env. +* learned: PIPESTATUS stuff +* don't agree partially: prefer internal over external (e.g. sed) diff --git a/content/gemtext/gemfeed/2021-05-15-personal-bash-coding-style-guide.draft.gmi b/content/gemtext/gemfeed/2021-05-15-personal-bash-coding-style-guide.draft.gmi new file mode 100644 index 00000000..998fe918 --- /dev/null +++ b/content/gemtext/gemfeed/2021-05-15-personal-bash-coding-style-guide.draft.gmi @@ -0,0 +1,67 @@ +# Personal Bash coding style guide + +``` + .---------------------------. + /,--..---..---..---..---..--. `. + //___||___||___||___||___||___\_| + [j__ ######################## [_| + \============================| + .==| |"""||"""||"""||"""| |"""|| +/======"---""---""---""---"=| =|| +|____ []* ____ | ==|| +// \\ // \\ |===|| hjw +"\__/"---------------"\__/"-+---+' +``` + +> Written by Paul Buetow 2021-15-21 + +Lately, I have been polishing and writing a lot of Bash code. Not that I never wrote a lot of Bash, but now as I also looked through the "Google Shell Style Guide" I thought it is time to also write my thoughts on that. I agree to that guide in most, but not in all points. + +=> https://google.github.io/styleguide/shellguide.html Gogle Shell Style Guide + +I also highly recommend to have a read through the "Advanced Bash-Scripting Guide" (which is not from Google but written by Mendel Cooper). I learn something new every time I have a look at it. + +=> https://tldp.org/LDP/abs/html/ Advanced Bash-Scripting Guide + +## My modifications + +These are my personal modifications of the Google Guide. + +### 2 space soft-tabs indentation + +I know there have been many tab and soft-tab wars on this planet. Google recommends to use 2 space soft-tabs. + +My own reality is I don't really care if I use 2 or 4 space indentations. I agree however that tabs should not be used. I personally tend to use 4 space soft-tabs as that's currently how my personal Vim is configured for any programming languages. What matters most though is consistency within the same script/project. + +Google also recommends to limit line length to 80 characters. For some people that seem's to be an ancient habit from the 80's, where all computer terminals couldn't display longer lines. But I think that the 80 character mark is still a good practise at least for shell scripts. For example I am often writing code on a Microsoft Go Tablet PC (running Linux of course) and it comes in very handy if the lines are not too long due to the relatively small display on the device. + +I hit the 80 character line length quicker with the 4 spaces, but that makes me refactor the Bash code more aggressively which is actually a good thing. + +### Breaking long pipes + +### Quoting your variables + +### Prefer internal over external commands + +## My additions + +### Use of 'yes' and 'no' + +### Non-evil alternative to variable assignments via eval + +### Prefer pipes over arrays for list processing + +## Learned + +### Strucking me + +### PIPESTATUS + + + + + + +E-Mail me your thoughts at comments@mx.buetow.org! + +=> ../ Go back to the main site -- cgit v1.2.3