Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

231–240 of 368 posts

Re: Ruby: A great language for shell scripts

#231

Not denying Ruby is good, but other than process forking, why should I prefer it to Python?

Personally, I find Ruby's syntax more natural, (I'm going to be heavily biased though, having written Ruby for 10+ years). But for example, let's say I wanted to make a hash (dict) of files, keyed by their size (for some unknown reason), in Ruby it would look like: Pathname.glob('*').filter { |f| f.file? }.each_with_object({}) { |f, h| h[f.size] = f } Whereas the equivalent Python would be: result = {} for file_path…

You can capitalize a string in Python using functional style

  ' '.join(map(str.capitalize, string.split(' ')))
which is similar to the example in Ruby, except the operations are written in reverse order.

Re: Ruby: A great language for shell scripts

#232
post #141

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…

This is indeed why I use Perl over Ruby. As long as it's not for a Window machine, a Perl script is deployed by copying it over and that's it.

Perl is deeply underappreciated and needs a lot more love. One of the keynotes at the polyglot conference that I run is going to be Perl talk and I'm really looking forward to it.

Re: Ruby: A great language for shell scripts

#233

Earlier quoted context omitted.

I think the built in one is deprecated though right?

Are there distributions where this doesn't happen? I feel like I'm often installing or compiling new versions of packages and languages because they're outdated on Ubuntu

A rolling distro like Arch or Void.

Re: Ruby: A great language for shell scripts

#234
post #133
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…

> It's already installed on basically every Linux distribution out there, PEP 668 pretty much negates this though. To do anything you need a python environment set up per script/project w/e

Python ships with venv support. It’s not that difficult to bootstrap a venv before running your script, and that’s only if you actually need tooling other than stdlib, which you probably don’t.

Re: Ruby: A great language for shell scripts

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

yea as soon as I read through the post, I ssh'd into one of my many Ubuntu servers, ran `ruby -v` and then noped out. From past experience I want nothing to do with trying to wrangle RVM or rbenv and then making sure the paths work properly.

Re: Ruby: A great language for shell scripts

#236
post #192
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…

> meanwhile, a lot of tooling nowadays is written in Go, and I have no idea why What? Go is used because distributing a static binary without any dependencies is way better than asking each and every user to download an interpreter + libraries.

So stop using 3rd party libraries. Seriously, the number of times I’ve seen people importing requests to do a single HTTP GET, or numpy to use a tiny portion of its library is absurd. You can do a hell of a lot with the stdlib if you bother to read the docs.

Re: Ruby: A great language for shell scripts

#237

Not denying Ruby is good, but other than process forking, why should I prefer it to Python?

Personally, I find Ruby's syntax more natural, (I'm going to be heavily biased though, having written Ruby for 10+ years). But for example, let's say I wanted to make a hash (dict) of files, keyed by their size (for some unknown reason), in Ruby it would look like: Pathname.glob('*').filter { |f| f.file? }.each_with_object({}) { |f, h| h[f.size] = f } Whereas the equivalent Python would be: result = {} for file_path…

    result = {os.path.getsize(f): f for f in os.listdir() if os.path.isfile(f)}

    result = ' '.join(word.capitalize() for word in string.split(' '))
    result = ' '.join(map(str.capitalize, string.split(' ')))
    result = string.title()

Re: Ruby: A great language for shell scripts

#238
post #77

Earlier quoted context omitted.

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

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.

I think JavaScript as a backend language was a mistake, and that Node has single-handedly caused more damage to the entire tech industry than any other aspect.

That hasn’t stopped billions of dollars of revenue from being created with it.

At least Ruby is unpopular enough (compared to Node) that people who know it are probably decent at their job.

Re: Ruby: A great language for shell scripts

#239

Not denying Ruby is good, but other than process forking, why should I prefer it to Python?

Personally, I find Ruby's syntax more natural, (I'm going to be heavily biased though, having written Ruby for 10+ years). But for example, let's say I wanted to make a hash (dict) of files, keyed by their size (for some unknown reason), in Ruby it would look like: Pathname.glob('*').filter { |f| f.file? }.each_with_object({}) { |f, h| h[f.size] = f } Whereas the equivalent Python would be: result = {} for file_path…

  from string import capwords 
  result = capwords(string)
This does the split/capitalize/join dance, all in one.

The file example you gave could also be turned into a dict comprehension if desired. I’m on mobile, but I think this would work.

  result = { f:os.path.getsize(f) for f in glob.glob(“*”) if os.path.isfile(f) }
Post reply on HN