Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

161–170 of 368 posts

Re: Ruby: A great language for shell scripts

#161

Earlier quoted context omitted.

Ruby is fantastic for the main project language, too! And is also standard on many Linux distros.

Ruby's fine for small to medium-sized projects. It's pretty great for small DSLs. In my professional experience on medium to large-sized projects, its lack of explicit typing, the habit of Rubyists to use its fairly-substantial metaprogramming capabilities at the drop of a hat, and (for projects that include pieces or all of Rails) the system's implicit library loading make such projects a nightmare to reason about a…

This has been my experience too reading the Gitlab code. It's absolutely impossible to follow - you can't use static typing to follow flow because there isn't any, and you can't even grep for identifiers because half of them are dynamically generated. Every time I've wanted to understand something I've been unable to even find the relevant code.

Contrast that with gitlab-runner (Go) or VSCode (Typescript) both of which I have been able to not only read easily but contribute features to. VSCode is at least as big a codebase as Gitlab.

That experience has made me want to avoid Ruby like the plague!

Re: Ruby: A great language for shell scripts

#162

Earlier quoted context omitted.

It got a lot better recently. You should take a second look.

I tried last month and it was still a mess. The old Ruby extension used to work fine and the new LSP one from Shopify doesn't want to work for whatever reason.

> ... the new LSP one from Shopify doesn't want to work for whatever reason.

Sorry, but calling it "a mess" simply because you can't get it to work is quite unfair. I've been using the LSP from Shopify since it came out, it works great, is very stable and updates come in on a regular basis.

Re: Ruby: A great language for shell scripts

#163
post #77

Earlier quoted context omitted.

Ruby is unsuitable for large projects for the same reason python is, but it also lacks the huge ecosystem and labor pool that python has. When I'm interviewing and a company tells me ruby is the main language, I end the call.

“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.)

It's absolutely possible to have a successful product with an unsuitable language. It doesn't mean it doesn't cost you.

Re: Ruby: A great language for shell scripts

#164
post #134

Earlier quoted context omitted.

It got a lot better recently. You should take a second look.

I mean, I was trying to set up editor support for a Ruby script last week. So unless it was improved really recently, it's not where I'd like it to be.

> but it's temperamental and I have trouble getting it working.

> I was trying to set up editor support

Not sure what problems you had exactly, but saying that editor tooling is bad, simply because you can't get it to work, is not fair. I've been using the LSP from Shopify since it came out, it works great, is very stable and updates come in on a regular basis.

Re: Ruby: A great language for shell scripts

#165

Nothing about dependencies! A scripting language needs a way to declare dependencies in a locked-down way, inside of the script that requires them. They must be portable across platforms.

Bundler inline works great for that: https://bundler.io/guides/bundler_in_a_single_file_ruby_scri...

Re: Ruby: A great language for shell scripts

#166
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.

If a client has certified a specific Linux distro as an approved platform, that's what we use.

We can either deliver a single executable (Go) or a Python script, as python is preinstalled on their distro.

If we'd want to use Ruby, it'd be a huge hassle of re-certifying crap and bureauracy and approvals and in that time we'd have the Python solution already running.

Re: Ruby: A great language for shell scripts

#167
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 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 spent a weekend going through all my old python scripts with Gemini and ChatGPT, rewriting them to Go just because of this.

Most of them were so old that I would have had to skip like 3 generations of package managers to get to the one that's used this year (dunno about next year) if I wanted to upgrade or add dependencies.

With Go I can just develop on my own computer, (cross)compile and scp to the destination and it'll keep working.

Re: Ruby: A great language for shell scripts

#168
post #104

Earlier quoted context omitted.

What tooling do you use that’s written in Go? I’d have said that Python is the most popular language for tooling, by a country mile. The only tooling I know that’s written in Go is Docker.

lots of CLIs are written in Python, absolutely, but many started more recently are almost exclusively Go unless there is serious interest in using Rust. It's almost certainly the ease of cross compilation plus the ability for users to run it without changes to their system.

This is the key.

I can easily provide precompiled packages for all sane combinations and users can just download one executable, edit the config file and be running.

Instead of having to mess with virtual environments and keeping them updated (they tend to break every time you upgrade the system python version).

Re: Ruby: A great language for shell scripts

#169

For me, the problem with shell scripting is that I do it only occasionally. I’ve always been tempted by higher-level languages. The arrival of tools like ChatGPT has made me much more comfortable writing scripts of intermediate complexity. I find shell scripting more interesting now.

Similar case for me, but I think the author says it well:

> That is, most of the cases Bash for me is enough, but if the script starts to become complex, I switch to Ruby.

Even if ChatGPT lets you bang out more complex shell scripts easily, if you have to come back to it later on to fix an error or add a new feature, it's really hard to understand it (if you don't deal with such scripts on a daily basis). If you start with Ruby (or Python or similar) from the beginning, it's much easier to understand and extend later on.

Re: Ruby: A great language for shell scripts

#170

Sadly, 9 out of 10 environments lack a Ruby interpreter out of the box. Are you going to add 5 minutes to your docker build to compile Ruby? Probably not. Luckily, I've found that Perl has most of the best features of Ruby, and it's installed everywhere. It's time to Make Perl Great Again.

> Sadly, 9 out of 10 environments lack a Ruby interpreter out of the box.

Please name those 10 environments you are talking about. In my experience, a reasonably recent Ruby version is present almost everywhere.

> add 5 minutes to your docker build

Why on earth would it take 5 minutes to install anything? If you install Ruby through a package manager (it's present in pretty much all of them: https://www.ruby-lang.org/en/documentation/installation/#pac...) it takes only seconds.

Post reply on HN