Live data from Hacker News

ZX – A tool for writing better scripts

github.com

111–120 of 143 posts

Re: ZX – A tool for writing better scripts

#111
If I want to write better shell scripts I usually run shellcheck and adjust accordingly or if I need facilities not provided by the shell I switch to a full fledged programming language. And oh yes, `sh` is present almost on every BSD and Linux box for free so I consider it an important thing to at least be comfortable with.

shellcheck: https://www.shellcheck.net/

Re: ZX – A tool for writing better scripts

#112
post #37

Earlier quoted context omitted.

It's asynchronous, which is pretty neat

A script, by its very nature, is synchronous. You run, you get a result. If you want a service, don't use a script.

That’s a completely arbitrary limitation which should not exist. When my scripts contain independent non-instant subprocesses, I run them in parallel. I’m also using js/ts to write all my scripts, because why wouldn’t I use a proper programming language instead of that “bash” thing that can’t even handle its single datatype well and resorts to all sorts of gibberish to perform trivial operations on it.

Re: ZX – A tool for writing better scripts

#113
post #18

This looks really cool, actually, and I'm surprised I haven't heard of this before. My incorrect gut intuition is that JavaScript devs usually don't do very much in depth terminal level command work, but that's of course false on a Bayesian level. There are far more JavaScript developers in the world than there are even Python developers, to say nothing of the long tail of even less popular languages. If 30% of JS de…

> There are far more JavaScript developers in the world than there are even Python developers I don’t think that’s true. Anecdotally when I was interviewing at a recruiting company (and we let candidates pick any language to be assessed in), Python was by far the most popular choice, chosen by about 60% of candidates or something like that. Java and JavaScript came after, followed by a long tail of languages like C#…

According to Stack Overflow JavaScript is more popular.

https://survey.stackoverflow.co/2023#section-most-popular-te...

Re: ZX – A tool for writing better scripts

#114
I get the utility of it, and probably having everything in the repo of a project in the same programming language is a benefit, when onboarding new people. but...

Shell scripting has a long and glorious history, filled with incremental improvement in the tooling that have proven themselves over decades. The shell scripting languages themselves and all the awesome tools that come along with them on UNIX.

You are 100% guaranteed to be reinventing the wheel over and over (and poorly) if you write shell scripts without a good understanding of what is available "Off the shelf"

There are great benefits to had by using am appropriate language for the task at hand.

Re: ZX – A tool for writing better scripts

#115
GPT4 makes it so easy to write or translate scripts, I don't care if you write it in js or bash or powershell or batch files or python or ruby or whatever. Whatever is most convenient at the time is best, and it can be very easily translated if something else is preferred later.

Re: ZX – A tool for writing better scripts

#116

It looks like people don’t get it. This isn’t “better” than your tool of choice. This is a tool for JavaScript developers to write non-trivial scripts in a portable way without getting lost in POSIX hell. Who came up with this stuff? https://stackoverflow.com/a/13373256 If you can write shell code, Perl, Python, COBOL, suit yourself. This is for JavaScript developers in JavaScript projects.

> It looks like people don’t get it.

They're probably on the spectrum.

(I'll get my coat...)

Re: ZX – A tool for writing better scripts

#117
post #18

This looks really cool, actually, and I'm surprised I haven't heard of this before. My incorrect gut intuition is that JavaScript devs usually don't do very much in depth terminal level command work, but that's of course false on a Bayesian level. There are far more JavaScript developers in the world than there are even Python developers, to say nothing of the long tail of even less popular languages. If 30% of JS de…

> There are far more JavaScript developers in the world than there are even Python developers I don’t think that’s true. Anecdotally when I was interviewing at a recruiting company (and we let candidates pick any language to be assessed in), Python was by far the most popular choice, chosen by about 60% of candidates or something like that. Java and JavaScript came after, followed by a long tail of languages like C#…

Python seems to be popular for solving leetcode style interview questions, which might be something worth of note.

Re: ZX – A tool for writing better scripts

#118
post #77

It looks like people don’t get it. This isn’t “better” than your tool of choice. This is a tool for JavaScript developers to write non-trivial scripts in a portable way without getting lost in POSIX hell. Who came up with this stuff? https://stackoverflow.com/a/13373256 If you can write shell code, Perl, Python, COBOL, suit yourself. This is for JavaScript developers in JavaScript projects.

Here's an example: https://gitlab.com/vincenttunru/penny/-/blob/main/scripts/bu... That used to be a shell script. But this I can way more easily read (even after not touching it for a long time), I get autocompletion, and I can use the APIs I'm already familiar with. It's a pretty neat QoL improvement for me specifically.

Wouldn't the `await fs.move` run sync? Why not just return the Promise from fs.move() so that Promise.all() can run the multiple moves async?

  await Promise.all(
    unneededPages.map(async (page) => {
      await fs.move(page, `scripts/.cache/${page}`, { overwrite: true });
    })
  );
Similar to what you do on line 26.

Re: ZX – A tool for writing better scripts

#119
post #18

Earlier quoted context omitted.

> There are far more JavaScript developers in the world than there are even Python developers I don’t think that’s true. Anecdotally when I was interviewing at a recruiting company (and we let candidates pick any language to be assessed in), Python was by far the most popular choice, chosen by about 60% of candidates or something like that. Java and JavaScript came after, followed by a long tail of languages like C#…

If you need a programming language for you job, but you're not primarily a developer, and two languages would probably be overkill, then your one language is probably python. That's a lot of people.

That’s exactly how I chose Python.

Re: ZX – A tool for writing better scripts

#120

Earlier quoted context omitted.

Here's an anecdote to help your gut. I'm a platform engineer who's favorite language is Typescript. I LIVE in the terminal. The only reason I use vscode is cause it's easier to put him into vscode than it is to put vscode into vim. Otherwise I'd be in the terminal for everything but browsing.

Likewise! I use TypeScript everywhere possible, and zx is a godsend. Unfortunately, I've recently dealt with gobs of Python for ML software. After years of writing TypeScript, it's been a...sobering reminder of many painful coding issues that I'd forgotten even existed. Made me deeply appreciate what TS gives us haha.

Python now has type hints which makes it closer to typescript, and easier to code in.
Post reply on HN