Hacker News new | ask | show | jobs
by danso 4308 days ago
I would love Ruby to become the goto "glue" language between different platforms and applications. I confess to not being more than a layperson in Perl, even though Ruby is heavily inspired by it...could Ruby ever replace Perl as the "Swiss-army chainsaw of scripting"? Or are their technical hurdles (such as performance) that would keep Ruby from being that kind of status quo?
9 comments

Perl, Ruby, Python all have the necessary toolkit to fitful this roll. And all run within the same ballpark of speed. Honestly most of these scripting languages (or even perl in most of these cases) is doing the same thing a shell script can do.

Just Perl made string manipulation a lot easier then the standard shell. Also Perl got there first, which is slightly important.

I'm already using Ruby for this. It's great for making little scripts and utilities to automate things and glue things together. Being able to interface with just about anything without much boilerplate while also having all of the tools of a high-end language make it really nice. Performance may not be as great - I don't know how it compares to Perl - but it's rarely an issue for these sorts of tasks. You could be 10x slower and still not notice the difference.
Do you have any experience with Python? IMHO I think python fits that niche better than ruby or perl.
Ruby is generally more concise and easier to write though probably harder to maintain.

For example, when shelling out, ruby lets you do it many ways, including the familiar backtick syntax. In python, you shell out with popen -- you need to contruct argument lists, wire up stdout and stderr, etc.

Python's way might actually be better (more explicit, less ambiguity, easier to handle errors) but often you might just want something that's simple and readable.

For the record, there are nicer python APIs and safer ruby APIs. These are just general comments on the different ecosystems.

Try the python 'sh' module (https://github.com/amoffat/sh). For example:

  from sh import git
  print git('version')
I think that both Python and Ruby can serve this purpose well, but both the block and method_missing functionality in Ruby can result in highly flexible and concise APIs. Correct me if I'm wrong, but I don't think there's a precise analog in Python to the Proc/Block syntax found in Ruby, maybe with the exception of lambdas. Furthermore, delegation using method_missing can result in APIs/libraries being very concise and readable.
In Python, since functions can be defined anywhere, and decorators can execute arbitrary code (including registering and running the functions they decorate) and be passed variables from the scope they're used, you can make some pretty powerful DSLs. And method_missing delegation can largely be replaced by defining classes at runtime, especially now that people are getting used to passing hashes as arguments (in fact, Rails seems to be slowly deprecating find_by_foo_and_bar in favor of where(foo: _, bar: _)?).
Can you give reasons?
Python is installed by default on most linux distros, from my experience it is rare if ruby is pre-installed.

Python in my opinion is easier to write, and reading it is usually like reading plain english.

Python has a much larger community/ecosystem than ruby outside of web frameworks (rails kills django in popularity).

I think Ruby already serves this use case well. When I have to do file munging or sysadmin tasks that are a bit too complex for bash, Ruby always seems to have an elegant and readable way of getting done what I want to do. It's a combination of the syntax, standard library and ecosystem, and it does a great job.
One of the (many) great features of the Amiga was ARexx. Most non-trial productivity applications had an ARexx port (API), allowing workflows to be scripted, tasks to be automated, and functionality to be extended.

True preemptive multitasking probably also helped.

AppleScript doesn't come close, and on Windows sketchup is the only app I know of with anything similar, which happens to be Ruby. But you can't create great workflows in an ecosystem of 1, and I expect that ship has long since sailed.

Chef. Tungsten Replicator-a powerful infrastructure orchestration tool-is all Ruby.
The advantage that Python or Perl has over Ruby is that they are included by default with most major Linux distros. I don't think (I may be wrong) that Ruby is. This might hurt adoption somewhat.
Some Linux distributions are not including Perl now.
Ruby is included in most major distros.
Thats what I use it for.
Ruby replaced Perl as my swiss-army chainsaw a long time ago.