-
-
Notifications
You must be signed in to change notification settings - Fork 163
Why Use Oil?
bar-g edited this page May 28, 2022
·
28 revisions
Related: Carrots
This is a DRAFT. On the site: Why Use Oil?
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:
A framing from: https://github.com/oilshell/oil/pull/1145
- Static Parsing enables better error messages and tools. (TODO: color error messages)
- Fix common problems while retaining compatibiity with other shells --
shopt --set strict:all
). The "runtime linter". - 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)
- Eliminate Quoting Hell / !qefs / Simple Word Evaluation
- 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
- 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.
Note that many of these are on by default.
- Assignment keywords (
var
,const
,setvar
) and Python-like expressions on typed data - Egg Expressions for Statically Parsed and Composable Regexes --
/ d+ /
- Ruby-like blocks and typed arguments for DSLs
- Procs have signatures and fixed scoping
- Test framework and argument parsing (TODO)
- QTT and Tabular Data (TODO)
- Functions and Coprocesses (TODO)
Older (moved to Why Use Oil?)
- 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.
- Strict modes:
- Oil fixes problems with shell I/O
-
read --line
andread --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)
- Expression mode, etc.
- Real Data Structures like arrays and associative arrays (that are not broken as in bash)
- 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
- 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)
- 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