Live data from Hacker News

ZX – A tool for writing better scripts

github.com

61–70 of 143 posts

Re: ZX – A tool for writing better scripts

#61
post #56

>Write your scripts in a file with an .mjs extension in order to use await at the top level. If you prefer the .js extension, wrap your scripts in something like void async function () {...}(). Shebang scripts shouldn't have a file extension in the first place, so requiring one here is a dealbreaker. And having the file extension be used to switch between two different incompatible source formats is really a terrible…

> And having the file extension be used to switch between two different incompatible source formats is really a terrible design. Isn't that what all file extensions do? Distinguish between incompatible formats?

I've very rarely seen, say, image viewers which can't handle a JPEG with a .png extension or vice versa, but they're badly designed. Most handle this from the file magic automatically. Keying on extension is definitely an antipattern IMO.

I don't see people naming C++ files .c++03, .c++11, .c++17. I don't see people naming Perl files .pl-strict-mode.

Yes, it's normal for people to use file extensions, but having programs impose forced usage and semantics to them is a crutch and a sign of bad design.

How am I supposed to put a script written using this tool in $PATH?

This bad design seems to be a thing in the TS/JS ecosystem now. At least some language ecosystems (Deno? Not sure.) seem to be encouraging people to do 'import ".../Foo.ts"'. Which is abysmal: Firstly these are URLs, yet file extensions are against web principles and good URL design. Secondly they couple a consumer of a module to what language the module was written in and expose this as part of an API, which is terrible design.

Re: ZX – A tool for writing better scripts

#62
post #56

>Write your scripts in a file with an .mjs extension in order to use await at the top level. If you prefer the .js extension, wrap your scripts in something like void async function () {...}(). Shebang scripts shouldn't have a file extension in the first place, so requiring one here is a dealbreaker. And having the file extension be used to switch between two different incompatible source formats is really a terrible…

> Shebang scripts shouldn't have

Should not have or should not need to have? You can perfectly write a script with a shebang and an extension, stick it in your path, and use it without extension.

Therefore, I fail to see how this is a "dealbreaker". Or is it just because "I don't like it!"?

Re: ZX – A tool for writing better scripts

#63
"Bash is great, but when it comes to writing more complex scripts, many people prefer a more convenient programming language."

https://google.github.io/zx/getting-started

I read this and think "1. Bash is not great. 2. Why assume that I want to write complex scripts."

I like simple scripts. I am embarassed by any complexity. It is the mark of a cluttered mind.

As it happens, there have been and still are others that dislike complexity, though they may be greatly outnumbered.

Right now there is another submission in /active on HN titled, "A 2024 Plea for Lean Software. Why Bloat is Still Software's Biggest Vulnerability"

"I want to end this post with some observations from Niklaus Wirth's 1995 paper:

"To some, complexity equals power. (...) Increasingly, people seem to misinterpret complexity as sophistication, which is baffling-the incomprehensible should cause suspicion rather than admiration."

I've similarly observed that some people prefer complicated systems. As Tony Hoare noted long ago, "[T]here are two methods in software design. One is to make the program so simple, there are obviously no errors. The other is to make it so complicated, there are no obvious errors." If you can't do the first variant, the second way starts looking awfully attractive perhaps."

And scripts are not even systems. The idea of intentionally creating "complex scripts" is indeed baffling.

The HN title could be something like "ZX - A tool for writing complex scripts". Or "ZX - A tool for writing better complex scripts". Instead it's "ZX - A tool for writing better scripts".

Re: ZX – A tool for writing better scripts

#66
post #56

>Write your scripts in a file with an .mjs extension in order to use await at the top level. If you prefer the .js extension, wrap your scripts in something like void async function () {...}(). Shebang scripts shouldn't have a file extension in the first place, so requiring one here is a dealbreaker. And having the file extension be used to switch between two different incompatible source formats is really a terrible…

> Shebang scripts shouldn't have Should not have or should not need to have? You can perfectly write a script with a shebang and an extension, stick it in your path, and use it without extension. Therefore, I fail to see how this is a "dealbreaker". Or is it just because "I don't like it!"?

So how am I supposed to put such a script in $PATH? e.g. if I hypothetically want to make a replacement for say 'ls', what am I supposed to do, force people to type 'ls.mjs' rather than 'ls'?

Re: ZX – A tool for writing better scripts

#67

"Bash is great, but when it comes to writing more complex scripts, many people prefer a more convenient programming language." https://google.github.io/zx/getting-started I read this and think "1. Bash is not great. 2. Why assume that I want to write complex scripts." I like simple scripts. I am embarassed by any complexity. It is the mark of a cluttered mind. As it happens, there have been and still are others that…

> I am embarassed by any complexity. It is the mark of a cluttered mind.

It is the mark of a cluttered world.

Sometimes, there is no simple solution. You have to parse this file, you have to use software to do it, and you can't fix up every little quirk in the file's actual grammar versus the grammar you wish the file had. Tag soup HTML is one example, but there are thousands of others, around the world, doing important things for business and education.

Sometimes you get to parse JSON. Sometimes you have to parse SQL.

Re: ZX – A tool for writing better scripts

#68

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.

Would a python developer feel the same in reverse?

Re: ZX – A tool for writing better scripts

#69
post #56

>Write your scripts in a file with an .mjs extension in order to use await at the top level. If you prefer the .js extension, wrap your scripts in something like void async function () {...}(). Shebang scripts shouldn't have a file extension in the first place, so requiring one here is a dealbreaker. And having the file extension be used to switch between two different incompatible source formats is really a terrible…

> And having the file extension be used to switch between two different incompatible source formats is really a terrible design. Isn't that what all file extensions do? Distinguish between incompatible formats?

Extensions are predefined mapping to the executing program. There is no real concept of compatibility there. Useful for media files where you e.g. pick your image-viewer-of-choice, less useful when the script file already has a very strong opinion as to the expected executing binary. Compatibility can be hinted at, but really only determined on the application level.

If the script runtime binary then looks at the filename and does something differently based on it, it's likely not correct, and if it is done, it'd better be because of some necessity. The "we prefer it this way" is not a necessity. Plus it breaks conventions and expectations.

Enforcing file name extensions at execution, because you want to help an editor figure out how to lint or highlight the file, is also, arguably, letting a specific use case affect something it shouldn't.

Post reply on HN