Patterns and Anti Patterns - oils-for-unix/oils GitHub Wiki
UNDER CONSTRUCTION
This page is about how to use shell.
Related: Slogans, Fallacies, and Concepts
Terms
- procs
- "first word" -- external binary, builtin, or proc. (No alias in Oil)
Shell Programming Patterns
- Shell Functions / procs
- Bernstein Chaining / Chain Loading
- $0 Dispatch Pattern (sudo, xargs -P, find -exec)
- "Task file" pattern -- with
runproc
- no data dependencies?
- TODO: Shell Scripts Are Executable Documentation
- Same pattern as https://github.blog/2015-06-30-scripts-to-rule-them-all/ , except they use a DIRECTORY, not a single file
- Proc-like: argv -> status, and stdin/stdout/stderr
- command annotations can tame this generality, but we want proc-like
- Proc as function: stdout is the "return value" (like Elvish). Return value is for errors.
- PPPT: Parameterized Parallel Process Table
- you can add a column to a table in parallel
- data dependencies: shell vs. make/Ninja
- Software Evolution
- Avoid Mini-Languages in Other Tools
xargs -I {}
can be replaced with a shell function and$1
'\n'
in cut, xargs, etc. can be replaced with$'\n'
xargs -L
special tokenization rules should just be-n
find -exec foo +
(for batching args) can also be replaced withfind -print0 | xargs -0
(avoiding weird;
vs.+
)
Anti-Patterns
- The YAML problem. The sh-in-{yaml,docker,systemd,chef,vagrant,python} problem.
- actually 2 variants of this: sh-in-YAML, and YAML-based languages like Github Actions (and Gitlab)
- Whitespace Joining Antipattern
- SSH quoting
- eval builtin
- echo builtin
- I'm Too Lazy to Write a Lexer. Instead I'll just use the
argv
array. Used byfind
,test
, andexpr
. - Deserialize a huge blob -> trivial in-memory operation -> Serialize huge blob. This is bad for performance.
- instead use lazy deserialization
- Distributed OS Design: The Inner Platform Anti-Pattern
- Kubernetes suffers from this