Why Sponsor Oils? | blog | oilshell.org

Garbage Collection Makes YSH Different

2024-09-11

I made a table to emphasize a point I made in the last post: Most "Unix sludge" is string-ish, but YSH has garbage-collected data structures.

That is, YSH moves shell from the left to the right — from less powerful to more powerful.

 

No Garbage Collection Garbage Collection
(string-ish languages, often cursed by users)
Traditional Unix Shell
(GC implies general data structures)
YSH
Make
CMake
m4 (autoconf)
Lisp and Scheme,
Python, JavaScript,
Ruby, Lua
(arrays that can't be nested)
awk
fish
(mixed value/reference semantics)
Perl
PHP

Garbage-collected data structures lets you express a larger range of programs naturally, like ones that deal with build graphs.

Table of Contents
The Main Point
Examples of YSH
What About Other Shells?
Next
Appendix

The Main Point

Yesterday, I published:

So it's not just OSH that's smaller than bash, but all of Oils.

That includes YSH, and that's despite its greater power, which is due in part to garbage collection.

 

Note that I'm measuring lines of source, not binary size, and the oils-for-unix binary is currently ~2x larger than bash.

But lines of source is a more stable metric, and mycpp gives us leverage to make the binary smaller, if we want to. (It's more important to make it faster, but ideally we do both.)

Examples of YSH

Here are two long docs, with many examples:

And here's a short example, extracted from demo/url-search-params.ysh, a messy but real piece of code inspired by a problem that Samuel had. (We need syntax highlighting!)

proc test-query() {
  ### Oracle test for parsing URL: foo?name=foo+bar&k=v

  for s in (QUERY_CASES) {
    echo 'INPUT'
    echo "  $s"

    # Shell out to node.js as an oracle
    js-decode-query $s | json read (&js_pairs)
    echo 'JS'
    pp value (js_pairs)

    # Call YSH function
    var ysh_pairs = URLSearchParams(s)
    echo 'YSH'
    pp value (ysh_pairs)

    # Are they equal?  This compares structured data
    assert [ysh_pairs === js_pairs]
    echo
  }
}

What About Other Shells?

There are other shells with structured data, like PowerShell, nushell, Elvish, and dozens of other projects:

 

The main difference is that the design of Oils is "exterior" like POSIX shell and bash, not "interior".

This is a fancy way of saying that we use normal Unix processes and files, like JSON over Unix pipes.

We don't invent our own narrow waist of say Powershell cmdlets and objects. †

 

I wrote two blog posts about this:

These ideas will continue to appear on the blog.

 

† Based on feedback, I'll sometimes call a narrow waist an M × N waist.

Next

This is where we are in the current series:

  1. What Oils Looks Like in 2024
  2. After 8 Years, Oils Is Still Small and Flexible
  3. Garbage Collection Makes YSH Different - this post
  4. Missing Retrospectives on Oils
  5. Oils - Grand Ideas and Fiddly Details
  6. Oils 0.23.0 - User Feedback, Bug Bounty, and Writing YSH Code

The next post will be a bit critical!

Appendix