The Shifu Code


Preface

Those claiming to be Shifu are possessed of considerably higher standards than typical programmers. The training is a great deal more intensive and much more exclusive. It is geared towards weeding out the weak. Overt displays of scripting ability, such as advanced BASH commands, Makefiles, and shell environments are focused on. The associated terseness is not so much a training method as a test of the initiate's dedication.

Conventions

Young foo asked shifu ...

  for x in range(10):
    print(x)

 foo-example.py 
Shifu replies to young foo ...

  print([val for val in range(10)])

 shifu-example.py 
Master foo enlightens young foo

  print(range(10))

 master-foo-example.py 

Introduction

Something mysterious is formed, born in the silent void. waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.
 The Silent Void 1.1 

Shifu recognize mastery of their craft lie within techniques as opposed to tools. The wise programmer is told about Tao and follows it. The average programmer is told about Tao and searches for it. The foolish programmer is told about Tao and laughs at it. If it were not for laughter, there would be no Tao.

The Tao gave birth to machine language. Machine language gave birth to the assembler. The assembler gave birth to the compiler. Now there are ten thousand languages. Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao.

But do not program in COBOL if you can avoid it.
The Silent Void 1.2 

In parallel to a writing system, to transmit their canonical teachings, knowledge is often transmitted by presenting examples of the Tao; either by illustration or analogies.

The programmers of old were mysterious and profound. We cannot fathom their thoughts, ... Who can tell the secrets of their hearts and minds?

The answer exists only in Tao.
 The Ancient Masters 2.1 

Find your inner SHelf

Young foo asked: How can I find myself within the Tao?
Shifu replied: There are many paths to the Tao: light and dark; Yin and Yang; BASH and PowerShell.
Master foo launched a new terminal and typed

  > whoami
  master-foo
   whoami example 

Perplexed by master foo's response, young foo inquired

Surely I cannot find myself within the Tao in a single command field.
Young foo, have you not read Master foo and the 10,000 lines? There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.

After overhearing shifu, master foo asked

Would two fields be more enlightening?

  > echo $USER
  master-foo

 echo example 

  > man man
  ...
 manpage example 

man(1)                                        man(1)

NAME
       man  -  format and display the on-line manual
       pages

SYNOPSIS
       man [-acdfFhkKtwW] [--path] [-m  system]  [-p
       string]  [-C  config_file]  [-M pathlist] [-P
       pager] [-B browser] [-H htmlpager]  [-S  sec-
       tion_list] [section] name ...


DESCRIPTION
       man  formats  and displays the on-line manual
       pages.  If  you  specify  section,  man  only
       ...

 manpage for manpages 

Upon running every combination of the commands, young foo was enlightened.

Exit Status

After studying studying the man pages, young foo was perplexed.

The man pages for echo describe an Exit Status ...

Before young foo could finish shifu typed in the terminal


  > man echo | head -30 | tail -2
  EXIT STATUS
     The echo utility exits 0 on success, and >0 if
     an error occurs.

 EXIT STATUS for echo 
... continue ...
Shifu, how can I know the EXIT STATUS? Upon success, the program executes; upon failure it does not.
Young foo, an EXIT STATUS is not associated with any single utility. It is a Yin paradigm within the Tao; each value assigned a purpose. Should one abandon context if in error?

Without speaking, master foo opened a terminal and typed


  > echo $USER
  master-foo
  > echo $?
  0
  > error
  sh: command not found: error
  > echo $?
  127
  > echo $?
  0
  > echo '$USER'
  $USER

 Determining an EXIT STATUS 
Young foo, return home, meditate on this example, and study string interpolation. Then you will be enlighted in the Tao.

After saying these things, master-foo returned $HOME as if he had never left.


> pwd
/Users/master-foo
> echo ~
/Users/master-foo
> echo $HOME
/Users/master-foo
> file $HOME
/Users/master-foo: directory
cd ~

 $HOME directory example