Last week someone was looking over my shoulder as I typed a command to run a script. It was something mundane, like
./script/test. He said, “you know, you don’t have to type the dot slash,” and I thought, “Wow, he’s right; I’ve been typing those extra characters for years!”
Just a little later, I ran a different command in the script directory and this time I didn’t use the dot slash.
SCREEN_NO scandeps.pl schemagen script
sc scandeps5.12.pl scp scselect
sc_auth sccmap screen scss
sc_usage sched screencapture scutil
Oh, right! Tab completion works much better with just the tiniest bit of context, so if I use the dot slash and script is the only thing in that directory that starts with
sc, I end up typing the whole command faster. Of course, by the time I realized this there was no longer someone looking over my shoulder!
We programmers develop a million of these little tricks over the years and often don’t realize it when we do. At least I wasn’t aware enough at that particular moment to explain to my backseat driver why the dot slash flew off my fingers. Maybe I didn’t even come up with that trick on my own. Sometimes we inherit best practices from others’ experience.
Ruby coding style is no exception. You don’t have to parenthesize your arguments when you call a method, but if you usually don’t, there will be some times when you do—method chaining, for instance—and you’ll have to go back and put them in. Or consider why we prefer
and. You can use
and, but you have to keep the order of operations in your head, and that’s one more thing to keep track of.
&& is generally the operator prescedence that you’re intending.
That’s not to say GitHub sets the standard for Ruby development. They just forked Bozhidar Batsov’s style guide, and he developed it out of his experience, various Ruby books, and no doubt reading thousands of programs over his career. If you had a thousand Ruby coders write style guides and then averaged them, I’d wager it would be very close to GitHub’s.
Having a backseat driver isn’t all bad. I did a
cd .. followed by
cd that-same-directory to pick up some automatic per-directory settings (RVM, probably) and he suggested
cd . instead. Great! An obviously possible combination, but something that han never occurred to me. Even spectator programming (as opposed to pair programming, which has been rocking my socks all year) has its advantages.