Live data from Hacker News

Modernish: a shell moderniser library

github.com

11–16 of 16 posts

Re: Modernish: a shell moderniser library

#11

This looks really, really good. I’ve been looking for something like this for a while, even considered building it myself. Javascript and Shell programs are actually pretty similar IMO. Both are loosely functional languages that can run in many different environments, with different feature sets in each. Both run from a single entry point. A lot of JS tooling could be applied to Shell scripting. This library takes th…

Shell is so much not functional. Most shells don't even have proper functions. And while pipes resemble function composition to some extent, you have side-effects and mutations everywhere.

Re: Modernish: a shell moderniser library

#12
post #11

This looks really, really good. I’ve been looking for something like this for a while, even considered building it myself. Javascript and Shell programs are actually pretty similar IMO. Both are loosely functional languages that can run in many different environments, with different feature sets in each. Both run from a single entry point. A lot of JS tooling could be applied to Shell scripting. This library takes th…

Shell is so much not functional. Most shells don't even have proper functions. And while pipes resemble function composition to some extent, you have side-effects and mutations everywhere.

Agreed. Hence why I said “loosely functional” (you could say the same about JS).

For both languages you can write code as functional or non functional as you want. Input/output redirection (pipes), IMO, could qualify as functional programming just as JS promise chaining could.

Re: Modernish: a shell moderniser library

#13
While I applaud the effort and extensive documentation I'd never use something like this in production.

For example have a look at the definition of `sfor`

    sfor 'i=1' '[ "$i" -le 10 ]' 'i=$((i+1))'; do
        print "$i"
    done
Doesn't look too bad at first, until you realize `sfor` is an alias which is defined as

    alias sfor='_Msh_sfor_init=y && while _Msh_doSfor'
So it's an alias which expands to two commands.

No have a look at the definition of `_Msh_doSfor`

    _Msh_doSfor() {
        case ${#},${_Msh_sfor_init+y} in
        ( 3, )	eval " $3" || die 'sfor: loop command failed' || return ;;
        ( 3,y )	eval " $1" || die 'sfor: init command failed' || return
                unset -v _Msh_sfor_init ;;
        ( * )	die "sfor: 3 arguments expected, got $#" || return ;;
        esac
        eval " $2" || case $? in
        ( 1 )	return 1 ;;
        ( * )	die "sfor: test command failed" ;;
        esac
    }
No thanks, I'd rather use Python.

Re: Modernish: a shell moderniser library

#14
post #11

This looks really, really good. I’ve been looking for something like this for a while, even considered building it myself. Javascript and Shell programs are actually pretty similar IMO. Both are loosely functional languages that can run in many different environments, with different feature sets in each. Both run from a single entry point. A lot of JS tooling could be applied to Shell scripting. This library takes th…

Shell is so much not functional. Most shells don't even have proper functions. And while pipes resemble function composition to some extent, you have side-effects and mutations everywhere.

If you think of stdin and stdout as your function inputs and outputs, then shell becomes very functional:

Pipelines Support Vectorized, Point-Free, and Imperative Style

http://www.oilshell.org/blog/2017/01/15.html

In a sense, a shell can only return an exit code. But it's better to think of that as an error handling mechanism rather than the return value, much like in C. In C, it's idiomatic for functions to return values with "out params" (i.e. a dynamically allocated a string).

Just like you can write C code that composes, you can also write shell code that composes. And in many ways it composes better than code in other languages.

Re: Modernish: a shell moderniser library

#15
post #13

While I applaud the effort and extensive documentation I'd never use something like this in production. For example have a look at the definition of `sfor` sfor 'i=1' '[ "$i" -le 10 ]' 'i=$((i+1))'; do print "$i" done Doesn't look too bad at first, until you realize `sfor` is an alias which is defined as alias sfor='_Msh_sfor_init=y && while _Msh_doSfor' So it's an alias which expands to two commands. No have a look…

I think the point of this library is that all those gory details necessary for sane error handling are encapsulated, so you can build on that work if you absolutely need to write shell scripts. Otherwise, yeah, I hope that Oil will be the promised better shell and make bash & co. obsolete.
Post reply on HN