[sf-lug] sh, awk, Perl, ... Re: calculating meeting dates ...

aaronco36 aaronco36 at SDF.ORG
Tue Jun 4 16:43:40 PDT 2019


As somewhat related to "sh, awk, Perl" and to "calculating meeting dates", 
Akkana Peck <akkana at shallowsky.com> wrote in [1]:
> How's this? (Add to your .bashrc or wherever.)
>
> dayofweek() {
>    echo -n "Date as YYYY-MM-DD: "
>    read d
>    date --date=$d
>}
>
>If you really only want the day, change the last line to
>
>    date --date=$d +%a

IMHO, one major benefit this bash-script function has over other coding 
constructs is its *incredibly* straightforward Readability.
Readability as in the ease of figuring out what the code is really 
supposed to do, as well as the more extensive and respective Software 
Engineering Stack Exchange and Psychology of Code Readability treatments 
of the same in refs [2] and [3].

Well, sure, *of course*(!!) the following and longer command pipeline is 
easier to enter and may be more efficient to run than most bash scripts...
'$ (cd /usr/bin && ls -iL $(apropos awk | awk '{if(($1 ~ /awk/)&&($1 
!="igawk"))print $1;}') | sort -bn); read -rsp $'Press any key to 
continue...\n' -n1 key; (for a in mawk awk; do echo "$a" $(echo $(man "$a" 
| col -b | expand | grep '[^ ]' | wc -l)/66 | bc -l); done)'

But such a command pipeline is more efficient at the cost of any semblance 
of good Readability (again, IMHO).

It also greatly helps Readability to have appropriate comments placed 
throughout a bash script, such as those which the author of this bash 
script [4] does ;->

-A


Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.
Martin Fowler

Programs should be written for people to read, and only incidentally for 
machines to execute.
Abelson and Sussman


============================================================
References
============================================================
[1]http://linuxmafia.com/pipermail/sf-lug/2019q2/014174.html 
[2]https://softwareengineering.stackexchange.com/questions/162923/what-defines-code-readability 
[3]https://medium.com/@egonelbre/psychology-of-code-readability-d23b1ff1258a 
[4]http://www.rawbw.com/~mp/unix/sh/examples/shrink2fs
============================================================

aaronco36 at sdf.org
-------------------



More information about the sf-lug mailing list