Skip to content

Why Use Oil?

bar-g edited this page May 28, 2022 · 28 revisions
Clone this wiki locally

Related: Carrots

This is a DRAFT. On the site: Why Use Oil?

Concise overview of oilshell features

A first, terse, plain-text version as starting point:

(Came out of https://github.com/oilshell/oil/pull/1145#issuecomment-1138108066)

# The Oilshell Feature List -- A Comparative Overview
(Only single mentions where best applicable and comparing.)

Features in comparison to contending shells

  osh  --  The POSIX and bash compatible interpreter (**/bin/osh**).
     starts fewer processes
     (backend) interfaces for modern interactive features
     ...

  oil:upgrade  --  The mode that enables NEW features in osh:
    native, typed expressions and real data structures* (not broken as in bash): const, var, setvar
    ... : proc
    robust shell I/O idioms*: read --line, read --all, write (and all taking --qsn)
    reliable errexit (problems solved, enabled by defalt): try boolstatus* <...>
    reliable error handling*: try {...} case $_status {...}
  
      *No side effect beyond occupying namespace, thus these are even active in plain osh mode by default,
       and may only break in other shells if not shipping a fallback.
  
  oil:all  --  The final migration target (mode), same as the "clean slate" **/bin/oil** interpreter:
    includes all features that oil:upgrade adds to legacy shell
    disables some bits of shell syntax
       Now "@..." always means splice, any legacy ext.glob @(...) must be changed to ,(...) 
    deprecates some shell syntax
      ...
    discourages the use of
      ...
    


Features in comparison to programming languages
  
  oil
    exposes unix system abstractions directly, no unnecessary abstraction layers or verbose syntax
    allows direct execution of any code or program
    makes it simple to use all cpu cores
    has more powerful and simpler loop constructs than Python: for i, key, value in (dict) {...}

Can consolidate the following into it:

Why Upgrade to OSH and Oil (2022) ?

A framing from: https://github.com/oilshell/oil/pull/1145

Fixed with Basic OSH -- you get it for free, with compatibility

  1. Static Parsing enables better error messages and tools. (TODO: color error messages)
  2. Fix common problems while retaining compatibiity with other shells -- shopt --set strict:all). The "runtime linter".
  3. Safely process used supplied-data (QSN and shopt --unset unsafe_word_eval)

A large number of new Oil features: Python-like expressions, Eggex, named and typed arguments to procs, new builtins, ... (see below)

Fixed With a Seamless Upgrade with oil:upgrade

  1. Eliminate Quoting Hell / !qefs / Simple Word Evaluation
  2. Reliable Error Handling (command_sub_errexit, try and more)

Even more features unlocked (with parse_paren): Ruby-like blocks for DSLs, which enables QTT / functions / coprocesses

Oil (oil:all and bin/oil)

  1. A clean shell-like language with almost no legacy! We kept the good parts, got rid of the bad parts, and added useful new features.

Seven Features of Oil

Note that many of these are on by default.

  1. Assignment keywords (var, const, setvar) and Python-like expressions on typed data
  2. Egg Expressions for Statically Parsed and Composable Regexes -- / d+ /
  3. Ruby-like blocks and typed arguments for DSLs
  4. Procs have signatures and fixed scoping
  5. Test framework and argument parsing (TODO)
  6. QTT and Tabular Data (TODO)
  7. Functions and Coprocesses (TODO)

Older (moved to Why Use Oil?)

For Users Who Want a Compatible Shell

  • Oil runs your existing POSIX shell scripts and bash scripts. It doesn't fragment your codebase and contributors into distinct languages.
  • Oil starts fewer processes than other shells (it's faster, while remaining compatible)
  • If you're not ready to switch to Oil wholesale, you can use it as a dev tool that improves your existing shell scripts (run under bash or another shell)
    • More error messages due to static parsing (e.g. ble.sh benefitted from this)
    • More precise error messages -- column info.
    • Oil prevents programming errors (opt in with shopt)
      • Strict modes: strict_argv, strict_tilde, etc.

For Users Who Want To Enhance Existing Shell Scripts

  • Oil fixes problems with shell I/O
    • read --line and read --all
      • buffered I/O in addition to unbuffered (getline as opposed to read)
      • read -r should be the default
      • exit code, trailing new line corner cases
  • Oil fixes problems with errexit
  • Oil doesn't confuse flags and files (dashglob)

For Users Who want a New, Legacy-Free Shell Language

  • Expression mode, etc.
  • Real Data Structures like arrays and associative arrays (that are not broken as in bash)

For programmers (e.g. in Python/JS) who have never used shell

  • Shell helps you understand Unix. Don't abstract away the operating system behind portability layers you don't need. Unix is already a portability layer over hardware -- in many applications, you don't need yet another one.
  • Shell lets you use all your cores
  • #shell-the-good-parts

For Users Who Only Want an Interactive Shell

  • Oil is a better foundation for an interactive shell
    • See posts tagged #interactive-shell
    • You have a better language to build features

(But learning shell with save you time in the end; it's the best tool for many kinds of automation)

Because You Can Contribute To It

  • It's easy to modify
    • Written in a set of high-level DSLs, not low level C. One of them is bog-standard Python. The code is short, and you have convenient data structures. You don't have to worry about memory management.
    • It's the only shell that's statically typed. Other shells are written in C, but dynamically typed with small integers and bit flags (e.g. see bash's word structure). Oil uses MyPy and ASDL types, and we generate analogous code that adheres the C++ type system.
    • Good continuous build infrastructure