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
    • 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
    • Versionless Interchange Format
      • lines of text, JSON
      • Oil: QSN, QTT
    • Feature Detection, not Version Detection
  • 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 with find -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 by find, test, and expr.
  • 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