Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

301–310 of 368 posts

Re: Ruby: A great language for shell scripts

#301
post #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…

For both Ruby and Python most of time I use Emacs without an LSP, and it works better with Ruby than Python.

I never search _exactly_ why Ruby became so less popular than Python, but I think that at least two things:

- Having its popularity too much dependent of Rails; - Not having any other killer app (e.g. Python is not only Django, but NumPy, TensorFlow, Pandas, Flask and so on);

So, even if I love Ruby, Python is still my main language for most of things as it has a huge ecosystem and it is easy to use. But for writing shell scripts the advantages that I mentioned in the article generally I don't care too much about those things.

Re: Ruby: A great language for shell scripts

#302

I have what probably sounds like a niche use case, where most of the boxes I work on don't have access to the Internet. So for me, "is it installed in the base distribution" is the difference between being able to start immediately no matter which box I'm concerned with, and spending months trying to upstream a new program to be installed with our OS image team. I took a look around a vanilla Debian 12 box, and didn'…

Yeah, it makes sense.

Re: Ruby: A great language for shell scripts

#303

My first application of Ruby was to use it for shell auto-completions. I'm so grateful that I learnt Ruby first, and then Rails. Ruby is a great language to get some utility working out real fast. Rails is great for MVP. I fail to understand why people bitch about Ruby/Rails by comparing them to other languages/frameworks.

Yeah, as I mentioned, every time someone says something bad about Ruby for me, it is about Rails...

Re: Ruby: A great language for shell scripts

#304

I spend most of my time writing Rails or other backend Ruby, and I prefer my system-level scripts in bash. Philosophically I don't want to have to manage dependencies or broken gems (though inline deps obviate that, and it's not like I've never had to wrestle with apt)

Well, but what you do with Bash can be also done with vanilla Ruby...

Re: Ruby: A great language for shell scripts

#305
post #176

Side note: Firefox is offering to translate this blog post from Portuguese for me though the content is clearly in English. I noticed the ` ` element has a `lang="pt"` attribute. The site is generated by Jekyll, which I have not used in years, so I'm wondering if this is a site-level setting or could be overridden in frontmatter...

Thanks for the feedback!

I need to check it because my mother language is Portuguese and my personal page was initially only in Portuguese (everything there has also a version in Portuguese if you click the Brazilian flag). Some years ago I started to write in English but I didn't want to delete my older posts.

Re: Ruby: A great language for shell scripts

#306

Overall a nice lite write up! Bash is great, but it occasionally becomes untenable, usually around the time where HTTP and whatnot becomes involved. Same goes for shell exec exit codes, you can use an API like popen3 for this: https://ruby-doc.org/stdlib-2.4.1/libdoc/open3/rdoc/Open3.ht... You mention using threads and regex match global variables in the same write up. Please use the regex match method response inste…

Thanks for the comment!

Even though I wrote this about Ruby, I must admit that I am not a specialist.

Re: Ruby: A great language for shell scripts

#307
post #28

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.

This complaint comes up enough that I'm surprised nobody's created the Ruby equivalent of GraalVM, to compile a Ruby script, all its deps, and a WPOed subset of the Ruby runtime, into a native executable.

Given Ruby's lackluster type system, the amount of assumptions a compiler can take is significantly reduced. Moreover, analyzing that at a simple IR level would prevent it from understanding of what is actually referenced vs what isn't without making compile times take eternity and performing complex flow analysis with simulation.

Even with a good type system, a trimmer/linker has to be enlightened of many special idioms and patterns and perform flow analysis, and in the case of dynamically typed languages or languages with reflection - to analyze reachability of reflectable members and trim otherwise spaceous metadata. It took significant amount of work in .NET's ILLink in order for it to be able to produce as compact binaries/libraries as it does today with .NET's AOT build target, and it still required a degree of metdata compression and dehydration of pointer-rich data structures (something which, funnily enough, Go doesn't do, resulting in worse binary size).

Re: Ruby: A great language for shell scripts

#309

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

> I also have a revulsion to back ticks.

Yeah, I understand... But this is other language with a similar syntax for a similar functionality.

Re: Ruby: A great language for shell scripts

#310
post #255

Earlier quoted context omitted.

Even if you don't want to limit yourself to the stdlib, you can still use a zipapp : https://docs.python.org/3/library/zipapp.html

You need to introduce a build and release process then to do this then which still detracts from it being simple or the selling point being it's already installed.

With cpan it's the same, you need to install deps somehow.

You don't need it if it's just a python script with stdlib, just like with raw perl.

Post reply on HN