2006-04-10

You complete me

Being the lazy typist, like most programmers, I use command/file-name completion A LOT. I probably press "tab" more than I do "return". That works fine for the commands and for the file arguments.
However, there are a few command-line programs that are collected into toolkit style and operate on the form:

command subcommand subargs

It's sometimes a useful thing to do to wrap a bunch of little but related commands into a single command line, especially when the subcommands would otherwise share a bunch of code and procedures. Sadly, completion doesn't fill in choices for the secondary command; how can it? So one has to remember what choices there are and type the whole thing. This also applies to commands where the argument is another command, string, or filename that may not exist yet, as in makefiles.

But no more! Found another little *nix gem that's been in existence for who knows how long but lost on me because I never bothered reading the complete bash man page. I was alerted to it during my dig on Ruby Rake tips. Basically it concerns being able to write your own bash completion. Way cool!

In the makefile (and rakefile) example, it's very convenient to type "make [tab]" and get a list of possible targets of make. And in my toolkit example, I can type "command [tab]" and get a list of possible subcommands and a completion when it's unique. Very handy. It can save seconds at a time and has some good "wow" potential since I haven't seen anyone else in my group use this feature. I don't feel so bad that I missed this little time-saving gem all these years, but I wish I had known of it earlier.

2006-04-07

Perl fondly

I've read a many complaints about how Ruby took on too many Perl-isms. Actually, that's probably one of the bigger criticisms, and I completely disagree. In fact, I think Ruby is missing a few Perl-isms.

Some things about Perl that keep me coming back or I just appreciate.
  • THE BEST regex syntax, which basically was inherited from awk/sed and the like. I am puzzled that while Ruby smartly has "=~" they didn't include the substitution syntax form "s/.../.../g" which is so common, ingrained, and best of all, compact. WHY WHY WHY?!! I mean, Ruby can still keep the sub() and gsub() (so as not to munge in-place). This is why I still use Perl for all of my command-line hacks [perl -pe] instead of Ruby. BTW, Python's regexps suck balls.
  • Variables are easily identifiable because ALL variables begin with a $ or @ or %. Since Ruby is OO and has good data structures, only one symbol would be needed, say the $ (which means global in Ruby though). When I first learned Perl, the constantly having to type $, I admit, was kind of annoying. But I learned to appreciate it.
  • Because of the regex syntax and the "everything is a string" paradigm, it really is nice and convenient to quickly manipulate strings which is what I spend a good chunk of the time doing at work.
But generally, I've outgrown Perl for most of my scripting tasks; it's just not practical or convenient since the data structures are rather weak. I wish others in my group would follow suit.