1. 2

    So why is Rav1e as slow as it is? How can it be sped up to real-time? Threads? Chunk-based encoding?

    From what I understood from T.Daede’s presentation when it was new, is that its speed advantage comes from being brutally simple, such as only using the smallest transform.

    1. 4

      The reference implementation is purely for accuracy, and doens’t care about speed at all.

      They also don’t have --release in their README; I wonder if this number was created without it, if so, doing just that should show anywhere from 2x-100x improvements.

      EDIT: sent a PR for the README; they said their test scripts use it, so that must not be the case.

    1. 1

      FWIW, I also made a tool like this: pyxxd

      1. 22

        May I recommend putting in paragraph zero, “Use shellcheck, dummy!”?

        1. 3

          It’s in the readme. The linked document is meant as an addendum. I’ll think about it.

          Update: Added a preface.

        1. 4

          I’m still waiting for a [any sensible/modern language]-to-bash transpiler that will be nice enough to use to become widespread.

          1. 4

            Me too. I might attempt this at some point as an extension to shellharden.

            Possibilities for a sensible/modern language:

            • Fish - basically apply Wikipedia’s bash/fish translation table. Interstingly, every variable in fish is an array, so the corresponding bash code would be verbose ($var"${var[@]}"), but so be it. I’m a daily fish user, btw.
            • ion. I don’t know much about it.
            • The hypothetical Oil language (andyc’s post above).
            • Noob-style bash without quoting: Use shellharden as your transpiler. Hey, that’s possible today!
          1. 3

            Quite a nice list! One thing that stands out to me is the #!/bin/bash shebang, since I’m a NixOS user and it won’t work there (this is NixOS’s fault for not following FHS, but it has compelling reasons for doing so ;) ).

            I always use #!/usr/bin/env bash, which AFAIK looks up bash from the current PATH; this lets the user use their preferred bash (e.g. somewhere in ~), or propagate an augmented PATH through subprocesses (e.g. PATH=/my/favourite/bash/bin:$PATH ./my-top-level-script).

            By using /usr/bin/env for bash, python, runhaskell, etc. we only need to hard code a single path (which we can even special-case, e.g. with a find/replace, so the path itself doesn’t even need to exist!)

            1. 1

              Thanks. That’s something I haven’t thought much about, but your reasons make a lot of sense. I’ll change it.

            1. 3

              Informative post about shell/bash syntax, with a focus on quoting. Nice first post, @anordal.

              1. 2

                Thanks my friend!

              1. 18

                Special remark: Using curly braces is no substitute for quoting, so don’t pretend it is:

                Extra bad (adds confusion): ${my_var}

                I actually completely disagree, and I would argue that you should always add the curly braces. I’ve never heard of anyone thinking curly braces equated to quoting, but I’ve heard of many, many people (myself included) who don’t know all the rules about what constitutes the boundaries of a variable name. (Quick: does "$my-var" expand the variable my or my-var?) The author actually stumbles upon one of these confusing cases further down ("$10" versus "${10}") and uses it to add a special exception to their no-curly-braces rule.

                1. 12

                  Seconded. Always add the braces. I’ve also never seen (or even heard) of anyone confusing them with quotes. I used both braces and quotes. If anything, they make it clear that it’s a variable.

                  And you need to use them if you are expanding something like filename${num}blah.dat.

                  1. 4

                    Maybe that wasn’t well explained. Whenever braces are needed to limit the boundary of the variable name, you can achieve the same by the placement of the quotes:

                    • Good: "${my}-var"
                    • Good: "$my"-var

                    Thus, depending on where you like to insert quotes, you may typically end up removing curly brances when fixing bad code like the unquoted ${my}-var.

                    The exception case needs quotes to extend the boundary of the variable name.

                    1. 7

                      If you simply put every variable in its own set of quotes, you never need braces. Except for the exception.

                      You can avoid any exceptions by always using braces. It also clearly deliniates it as a variable in any context.

                      The only “good” one to me, of the ones listed above is "filename${num}blah.dat", although all three are safe, so it’s really a style issue. (I realize this is different from my example which didn’t have double quotes but it was just for illustrative purposes.) I personally find filename"$num"blah.dat quite distasteful.

                      The rest of the advice in the article seems reasonable to me.

                    2. 2

                      With sensible variable naming (a-z, A-Z and underscore) this should not be a problem and curly brackets should not be needed for regular variables. Reserving curly brackets for special cases also makes it easier to spot the locations where parameter expansion (like ${asdf%%asdf}) is happening.

                    1. 3

                      People immediately think of std::optional as a great thing to return, but it isn’t. You lose the failure reason! Use a result type (a la rust) for that.