Whither Ruby's Text::Balanced?

jjore on 2009-08-31T19:07:40

Today at work the toy problem of extracting some data from $more_json in a line like "$json|$more_json". The obvious thing seemed to use Text::Balanced to skip the first $json, snip off the '|' and then use a real JSON parser on the next json blob.

So uh... there's no Text::Balanced in Ruby. Not that I can find. We solved our work problem by just declaring that we'd only use delimiters which didn't occur in our input so we wouldn't need to find a Ruby Text::Balanced. I'm thinking maybe the easiest thing to do if we do turn out to need this in Ruby will be to write a gem that embeds a Perl interpreter. Then Ruby's Text::Balanced is just a short adapter over the Perl version.

It's just a thought though.


Or...

jk2addict on 2009-08-31T19:53:16

rubycritic...or rubytidy

And while I'm at it, where's perls Rake? imho, it kicks Makefile.PL in the ass sometimes.

Re:Or...

Alias on 2009-09-02T02:17:57

What's Rake? Details man, details. What are we missing exactly?

Re:Or...

jjore on 2009-09-02T02:26:29

It's make, except in Ruby. Module::Build isn't perl's Rake because M::B is focused on modules. Rake encompasses comparable gem tasks as M::B but is also a generally useful tool, just like make, except not evil.

Re:Or…

Aristotle on 2009-09-02T05:51:57

Think “DSL around Algorithm::Dependency for typical file-munging tasks” – roughly. Using the Rake Build Language has a bunch of examples where you can see how it looks.

TinyMake could be a rendition in Perl, but I find it a bit too underengineered to be truly useful…

I had some notes somewhere and have made a few starts at building a Rake clone, but I haven’t felt I got quite far enough with the concepts to start building something.

nitpick

jjore on 2009-08-31T21:33:28

Ruby has nitpick at http://github.com/kevinclark/nitpick/tree/master. FWIW, tt's oppressively slow and has the following checks:

  • An assigment is being used as a condition: ...
  • The method ... is empty
  • The branches of 'if (...)' are identical
  • A rescue is capturing Object or Exception, which may hide errors.
  • A rescue is returning ... directly and may not handle an error.
  • One or more variables are being shadowed (...)
  • A block is being yielded to without a check for block_given?
  • The argument ... is unused
  • The variable .. is unused
  • No need for an if. Just return '...' as a boolean

Like it or not, the stock perlcritic has 136 checks which is over 10x as many things. Nitpick just hasn't had the same love and attention applied.