Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

121–130 of 368 posts

Re: Ruby: A great language for shell scripts

#121

Earlier quoted context omitted.

“X is unsuitable for large projects” when there are many readily discovered existence proofs to the contrary (including but not limited to $1B+ businesses, massive communities, deep thoughtful and disciplined engineering spokespeople, etc.) strikes me as a common trope here on HN. (Which is not to say X is flawless even at scale or a clear best fit along all axes. That is true for no X that I know of.)

The fact that a language is used for large, successful businesses/projects doesn't mean another language wouldn't be better. It's just terribly difficult to measure such things.

Another language being "better" is very different than the language being "unsuitable"

Re: Ruby: A great language for shell scripts

#122

Earlier quoted context omitted.

I think golang is used because you can easily create a single static binary, which is incredibly easy to distribute. I often find non-trivial CLI tools written in Python cumbersome because of the dependency wrangling necessary.

> I often find non-trivial CLI tools written in Python cumbersome because of the dependency wrangling necessary. I'm thinking of trying out Mojo in large part because they say they're aiming for Python compatibility, and they produce single-file executables. Previous to that I was using PyInstaller but it was always a little fragile (I had to run the build script a couple of times before it would successfully complet…

Fun fact, you can use D language as compiled scripting using rdmd with powerful and modern programming features although it has much faster compilation than comparable C++ and Rust [1]. The default GC make it intuitive and Pythonic for quick scripting more than Go. Its recent native support for OS lingua franca C is the icing on the cake [2].

From the website, "D's blazingly fast compilation allows it to be used as a high level, productive scripting language, but with the advantages of static type checking" [3].

[1]Why I use the D programming language for scripting (2021):

https://news.ycombinator.com/item?id=36928485

[2]Adding ANSI C11 C compiler to D so it can import and compile C files directly:

https://news.ycombinator.com/item?id=27102584

[3] https://dlang.org/areas-of-d-usage.html#academia

Re: Ruby: A great language for shell scripts

#123
post #114
post #108

Earlier quoted context omitted.

> I sometimes wonder why we don't see ruby used for shell stuff more often. The reason we don't see Ruby used more for shell stuff is because Python won this particular war. It's already installed on basically every Linux distribution out there, and this simple fact outweighs all other language considerations for probably >95% of people who are writing shell scripts in something that isn't Bash. Personally, I don't m…

How hard is to install it though? That doesn't sound like a reason not to use it.

Depends on you, your team, your target hardware/os, your project, and many other factors. Considering all of those things, the hurdle of installation might just be too large for it to be worth it.

Re: Ruby: A great language for shell scripts

#124

As a self proclaimed shell advocate I am… intrigued. As a self proclaimed shell advocate, I also have a revulsion to back ticks.

You can also use %x(ls some/dir), which is a syntax used in other places too, like %w[word word word] (array of word strings, notice you can choose the delimiter).

Re: Ruby: A great language for shell scripts

#126
post #96

Earlier quoted context omitted.

> ... maybe extract those files to required files, add gems, whatever. CPAN is the killer feature of Perl. It just works. First off, most of the time I don't need a CPAN module for doing shell scripting in perl. Perl itself is rich enough with the file manipulations that are needed for any script of less than 100 lines. My experiences with Ruby and installing gems have been less pleasant. Different implementations of…

Does anyone under age 50 or so even know Perl?

Make it 30 and it's actually a question.

Re: Ruby: A great language for shell scripts

#127
post #8

The greatest feature for this is inline deps, something very rare to have built-in (I've only found Deno to have a similar feature): https://bundler.io/guides/bundler_in_a_single_file_ruby_scri...

Also been loving that Nix can give you this for shell scripts, e.g.:

  #!/usr/bin/env nix-shell
  #!nix-shell -i bash -p cowsay imagemagick

  identify "$1" | cowsay
https://nixos.wiki/wiki/Nix-shell_shebang

Re: Ruby: A great language for shell scripts

#128
post #108
post #9

I sometimes wonder why we don't see ruby used for shell stuff more often. It inherited most of the good stuff for shell scripting from Perl, and Perl took a lot of it's syntax from sh and sed and awk, so almost anything you can do in shell script you can do in ruby, but with an option of making it gradually less terse and more readable, while having sane variables and data handling from the start. Also ruby is great…

> I sometimes wonder why we don't see ruby used for shell stuff more often. The reason we don't see Ruby used more for shell stuff is because Python won this particular war. It's already installed on basically every Linux distribution out there, and this simple fact outweighs all other language considerations for probably >95% of people who are writing shell scripts in something that isn't Bash. Personally, I don't m…

This is also the reason perl was used before python began to dominate. It was installed everywhere before python was installed everywhere.

Re: Ruby: A great language for shell scripts

#129
Ruby's a great language- I've always enjoyed its ergonomics and clarity. But its editor tooling hasn't kept up with its one-time competitor, Python.

I've mostly been in the Python ecosystem for the past few years and the LSP investment from Microsoft has really shown. Rich Python support in VSCode is seamless and simple. Coming back to Ruby after that caught me off guard - it feels like I'm writing syntax-highlighted plain text. There's an LSP extension from Shopify, but it's temperamental and I have trouble getting it working.

Editor support isn't everything (the actual language design is still the most important), but it definitely affects how eager I am to use it. I basically never choose Ruby over Python given the option, which is too bad. Ruby's a cool language!

Re: Ruby: A great language for shell scripts

#130
post #114

Earlier quoted context omitted.

How hard is to install it though? That doesn't sound like a reason not to use it.

Mitigating the risk of downloading a script from the internet and executing it -- even from a "trusted" website or package manager -- is absolutely a good reason not to use it.

Any decent distro has it. So you don't need to execute any random scripts, just install it or prepare the image with it for your OS install. That's it.

I don't really get this whole defaults being a blocker for tools choice.

Post reply on HN