Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

291–300 of 368 posts

Re: Ruby: A great language for shell scripts

#291
post #204

Earlier quoted context omitted.

Mentioning 1.9 migration and ruby being slow? Python 2 to 3 was waaaaay worse and more negatively impactful, and equally slow (slower in most cases). Ruby never had US market penetrative as perl or python, which were basically invented in the US, and congregated people from the academic realm. These things aren't decided based on meritocracy (no things ever are).

> Mentioning 1.9 migration and ruby being slow? Python 2 to 3 was waaaaay worse and more negatively impactful Python 2-to-3 was mainly worse than Ruby 1.8 to 1.9 because Python had already won, and had a much bigger and more diverse ecosystem.

That's disingenuous. Python 3 was released around 2008, rails popularity was still rising. The community refused to upgrade for at least 10y, and several prominent libraries took as much to provide first grade python 3 support.

Ruby 1.8 to 1.9 migration was by contrast way milder. It took 6 or 7 patch releases and around five years to release 1.9.3, the first from the 1.9 series people actually considered stable, but after that the community migrated because it was *significantly* faster than 1.8 . Python 3 on the other hand was slower overall than python 3 at least until 3.6. The fact that the community stuck with python through it all does say a lot about human psychology and sunken cost syndrome.

Re: Ruby: A great language for shell scripts

#292

Earlier quoted context omitted.

I think the quality of a language for shell scripting is often secondary. What’s of greater significance is where it is at. I.e., does it have it already installed? The answer with Linux and Bash is almost always “yes”. Not so with ruby. The moment you start asking the user to install things, you’ve opened up the possibility for writing a program rather than a shell script. The lifecycle of a piece of software is alm…

> I.e., does it have it already installed? The answer with Linux and Bash is almost always “yes”. Not so with ruby. True, not true for Ruby, but with Golang and Rust you have an almost-no-dependencies final binary so the argument there does not apply. > which grep you got, buddy? For dev machines it's not such a tall order to require `rg` be installed these days.

One advantage of a scripting language for scripts is that you can read it and see what it does one month later...

Re: Ruby: A great language for shell scripts

#293
post #292

Earlier quoted context omitted.

> I.e., does it have it already installed? The answer with Linux and Bash is almost always “yes”. Not so with ruby. True, not true for Ruby, but with Golang and Rust you have an almost-no-dependencies final binary so the argument there does not apply. > which grep you got, buddy? For dev machines it's not such a tall order to require `rg` be installed these days.

One advantage of a scripting language for scripts is that you can read it and see what it does one month later...

Sure, especially every bash script that goes over 200-250 lines is super readable. /s

Or when you have to start using all the combinations of characters to achieve f.ex. proper iteration through an array without word splitting. Etc. to infinity.

I've danced this dance hundreds of times and got sick of it. Gradually moving away from scripts and to Golang programs and so far it has been an improvement in almost every way, I'd say easily in 90% of the cases.

Re: Ruby: A great language for shell scripts

#294
post #283

Earlier quoted context omitted.

I'd suspect you could do that with Open3, but if you are, why not just read the file and process with Ruby instead?

I'm currently working with 150MB worth of gzipped JSON - marshalling the full file from JSON to ruby hash eats up a lot of memory. One tweak that allows for easier lazy iteration over the file (while keeping temporary disk Io reasonable) is to pipe it through zcat, jq in stream mode to convert to ndjson, gzip again - for a temp file that ruby zlib can wrap for a stream convenient for lazy iteration per read_line...).…

Hmm. I don't typically mind throwing memory at a problem like that, but I can certainly see the issue.

Is lazy marshalling something that other languages handle better?

Re: Ruby: A great language for shell scripts

#295
post #260

Earlier quoted context omitted.

fluentd today is a popular (most popular?) log collector in k8s land.

Wow didn't know fluentd is a Ruby production. Who said Ruby is slow?

It still is a slow language that does not offer anything over competitors that are an order of magnitude faster to justify its performance characteristics.

Re: Ruby: A great language for shell scripts

#296
post #275

Earlier quoted context omitted.

> I don’t where these myths get started, but someone needs to justify the Ruby-is-slow thing with actual data. As an outside observer of the Ruby world, I have an impression that it was Ruby MRI that was slow. CPU-bound synthetic benchmarks like the much-criticized Benchmarks Game showed Ruby ≤ 1.8 a good deal slower than CPython 2. Here is an illustrative comment from that time: https://news.ycombinator.com/item?id=…

ruby 3.3.0 vs ruby 1.8.7 https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Also

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: Ruby: A great language for shell scripts

#297
post #63
post #33

Ruby is slow and encourages an esoteric convention over configuration style of OO code. If you enjoy it, more power to you. However, Python is everyone's second favorite or least favorite language, and it runs laps around Ruby any day. Then there's Go if you need some extra oomph!

Ruby performance has improved a lot in the last few years, especially with the introduction of the JIT (YJIT), and it keeps improving with every new release. I think the notion of Python being the faster of the two may be outdated. You can see some comparisons in the Benchmarks Game [1] (ignore the reference to PHP and Erlang in the URL, seems to be a typo by the website's maintainer, although my link will break if t…

Thanks for the nudge:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: Ruby: A great language for shell scripts

#298
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 only touch Go when using tools CNCF projects decided to write in Go.

Other than that, OS scripting is done in traditional UNIX tools, or Powershell.

Re: Ruby: A great language for shell scripts

#299

Earlier quoted context omitted.

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 whi…

Years ago, this was almost exactly my experience at my first software job, a large Rails monolith in the Ruby-on-Rails heyday. Obviously I was inexperienced, but aside from that, the application code itself was so hard to understand that I was seriously considering whether I was cut out for professional software development. It was just impossible to tell where things were defined, where data was coming from, when things were actually executing, etc.

It was only after working on other projects in other languages (Clojure, Java, Scala, Nodejs, Elixir, Rust) that I started to realize that maybe not all languages lead to teams writing code that is this difficult to follow.

People always say "oh, you can write terrible code in any language", and while this is true, it's a tautology. It doesn't actually tell you anything useful. I now think there is actually a pretty large spread in what kinds of code the various languages/frameworks encourage people to write. I'm not saying it guarantees what kind of code people will write, but, just for example, there absolutely is a difference between what the average Clojure programmer will write and what the average Java programmer will write.

If all of the various languages and frameworks and libraries all just ended up with the same effort producing the same results, no one would ever make anything new, because it would be pointless to do so.

Re: Ruby: A great language for shell scripts

#300
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…

> why we don't see ruby used for shell stuff more often Simple, ruby is not installed by default. Even Python, while it is on (almost?) all modern Linux distributions, is not installed on the BSDs.

Maybe this is something that we need to deal no matter what are using (perhaps except if we use sh).

Alpine for example doesn't ship Bash. Mac OS ships Ruby and its Bash is quite old.

Post reply on HN