Live data from Hacker News

Show HN: Rb – Turns Ruby into a command line utility

github.com

31–40 of 79 posts

Re: Show HN: Rb – Turns Ruby into a command line utility

#33
post #21
post #3

Earlier quoted context omitted.

It's using Ruby to replace Awk, the way Perl once tried to.

Why the hell would anybody want to replace AWK? It’s super fast, extremely light on resources, doesn’t have any dependencies, does auto memory management and type inference, and is extremely powerful for large dataset processing, not to mention easy to learn and program.

> easy to learn and program

I think that's relative and it certainly hasn't been my experience. If I program in Ruby, Node, Python, etc for 8 hours of every day, it makes sense that I would reach for that over a command line tool with a syntax that looks a bit arcane. The best tool for the job sometimes is the tool you know best.

Re: Show HN: Rb – Turns Ruby into a command line utility

#34

$ docker ps | rb drop 1 | rb -l split[1] $ docker ps | perl -anE 'say $F[1] if $.>1' perl solved this problem a long time ago, people

Yeah, just like eating dirt solved the problem of world hunger.

Look again at your code. I'm not 100% sure what the Ruby version does, but once I do figure out the exact semantics of drop and split, it's going to be waaaaaaaaaaaaaaaaay easier to remember, understand and modify the Ruby version than the Perl one.

Your post comes off as something from reddit's /r/nottheonion, you're just making the case against Perl for Perl-haters :)

Re: Show HN: Rb – Turns Ruby into a command line utility

#36
post #17

The command should process stdin in streaming fashion rather than slurping it all at once: code = ARGV[0] STDIN.each_line do |l| puts l.instance_eval(code) STDOUT.flush end

OP apparently wants to process an array of lines, not just each line separately.

Re: Show HN: Rb – Turns Ruby into a command line utility

#37
post #21

Earlier quoted context omitted.

Why the hell would anybody want to replace AWK? It’s super fast, extremely light on resources, doesn’t have any dependencies, does auto memory management and type inference, and is extremely powerful for large dataset processing, not to mention easy to learn and program.

> easy to learn and program I think that's relative and it certainly hasn't been my experience. If I program in Ruby, Node, Python, etc for 8 hours of every day, it makes sense that I would reach for that over a command line tool with a syntax that looks a bit arcane. The best tool for the job sometimes is the tool you know best.

> The best tool for the job sometimes is the tool you know best.

That's like hammering in screws because you know your hammer and screwdrivers seem arcane to you.

For ad-hoc stuff `ruby -e` is more than enough, and if you want to write a program once and use it a lot, it's worth investing the time in doing it the way it works best, which in this case, would be a (fast) language like awk that makes it easier to process line-by-line instead of reading until EOF and making the rest of the pipeline wait.

Re: Show HN: Rb – Turns Ruby into a command line utility

#38
- Reading all the lines into an array is a big error.

- It's a bit unintiuitive because you don't really know what strings to escape on the bash command line. In the example, some are escaped and others aren't.

- In the end I think this could be achieved with a simple bash function:

    $ rb() { ruby -lane "print \$_.instance_eval(\"$@\")"; }
    $ echo hello | rb capitalize
    $ Hello

Re: Show HN: Rb – Turns Ruby into a command line utility

#39
post #17

The command should process stdin in streaming fashion rather than slurping it all at once: code = ARGV[0] STDIN.each_line do |l| puts l.instance_eval(code) STDOUT.flush end

Someone did a PR[1] with something similar. He also found a way to speed things up by creating a Proc first and feeding it to the eval instead of the string.

[1] https://github.com/thisredone/rb/pull/2

Post reply on HN