News for hackers. Stuff that matters.
Re:Modernish: a shell moderniser library by chatmasta on Tuesday February 06, 2018 @05:49AM (#16315471)
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 the right approach, by augmenting existing functionality with syntactical sugar for safer programming. The wrong approach is the many libraries attempting to make a “new” shell language, or a “superset” of shell. The beauty of shell programming is its portability, but that’s lost once you have even a single feature relying on non-POSIX functionality.

I like the Modernish approach because it’s just a library, but writing it can feel like writing a cleaner version of shell. The docs say Modernish was inspired by jquery, but I would argue it’s more akin to underscore or lodash in this sense.

Following the trend of shell/JS similarities, what I would like to see is a compiler and packaging system similar to webpack and npm. I’m not talking about a package manager that downloads libraries and binaries into some directory in $PATH, but rather a bundler that compiles all libraries imported from an entrypoint into a single executable shell script.

Re:Modernish: a shell moderniser library by oweiler on Tuesday February 06, 2018 @08:17AM (#16316022)
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 by chubot on Tuesday February 06, 2018 @01:11PM (#16318097)
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 by chatmasta on Tuesday February 06, 2018 @09:13AM (#16316291)
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.