I love Reg's writing. It's consistently good and well thought out.
But man do I cringe every time I see him do backflips to hack around the warts in Ruby. I don't understand why he spends so much effort trying to work around fundamental problems in Ruby.
Use a better language, or pull an rhickey and make another good language worth using. Reg is obviously smart enough to do it.
"I cringe every time I see him do backflips to hack around the warts in Ruby. I don't understand why he spends so much effort trying to work around fundamental problems in Ruby."
Reasons to do backflips:
1. They're fun in their own right.
2. I learn something about the quality of good vs. poor tools by fixing shortcomings in tools.
3. Sometimes the backflip is an exercise intended to get someone who thinks in Ruby to think about things outside of Ruby.
4. Rule 3 applies to Reg as much as his readers :-)
And oh yes, I should be very clear that I am not ready to declare that everyone should be programming in Ruby with anaphora. They are interesting, and I am personally happy with String#to_proc, but beyond that... Hard to say...
On of my friends wrote his Ph.D. thesis on anaphora resolution. In it, he used homoerotic literature as the corpus. (It's much harder to figure out which "he" the text means when every character is male.)
3. "github.com" - Maybe it's just a new project? Nah, I've never heard the word "Anaphora" before, so it's probably raganwald writing about some weird/nifty/awesome thing.
4. "raganwald" - Yes, yes, yes. But is it homoiconic?
I've read a lot of Ruby code over the years and never seen "if [..] then" used so much as in this (otherwise fun) piece. Have I just been lucky and it's actually more commonly used than I think? :)
You need "then" or a colon when compressing an if statement onto one line. My production code generally puts the test expression in trail (foo if bar) when things fit on one line and therefore I almost never use it.
It's in the blog piece because when talking about things resembling an English sentence, sometimes writing them on one line highlights the relationship.
I guess I was trying to be consistent. I'll fix the multi-liners. if it helps any, I forgot how to write a one line if with the test expression in head position and had to look it up.
Typical dreamer behaviour, can babble about anaphora but if asked to write an if expression on one line in a job interview would bomb out...
This is one reason I like Ruby so much though. Replaying recorded messages is how I use syntax like "asm.mov [EAX * ECX + base], 0xdeadbeef" in my x86 assembler library (or DSL if you're trendy).
Although point-free style achieves (or surpasses) the brevity of anaphoric style, it does so in a manifestly different way. To use two Ruby examples,
(1..100).map(&:to_s)
(1..100).map(&it.to_s)
The first example reads to me as mapping a method over the numbers, while the second reads to me as a very terse way of describing a function that sends a method to each number.
I am not doing a good job of explaining the difference in my head, but I do know that sometimes I really like point-free style because I am thinking in operations and methods rather than in functions.
But man do I cringe every time I see him do backflips to hack around the warts in Ruby. I don't understand why he spends so much effort trying to work around fundamental problems in Ruby.
Use a better language, or pull an rhickey and make another good language worth using. Reg is obviously smart enough to do it.