# "more than enough rope"

**URL:** <https://www.ruby-forum.com/t/more-than-enough-rope/78460>\
**Category:** Ruby\
**Created:** [December 5, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460 "2006-12-05T23:22:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 5, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/1 "2006-12-05T23:22:59Z")

</div>

I just found out that Josh S.'s cancelled presentation at RubyConf  
was going to be called “More than enough rope to hang yourself,” and  
was going to be about how to avoid misusing Ruby’s power. I’ve  
definitely written code where my main goal was getting my head around  
lambda() or things like that – now I have code on my hands where I’m  
trying to decide, is this beautiful, well-written stuff, or was I just  
indulging in a bunch of gratuitous cleverness because I had the  
option?

Obviously this is a judgement call – but does anyone know good  
resources for those questions like, when do I use metaprogramming,  
when do I just use more normal techniques?

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 5, 2006, 11:41pm UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/2 "2006-12-05T23:41:02Z")

</div>

Giles B. wrote:

> resources for those questions like, when do I use metaprogramming,  
> when do I just use more normal techniques?

1. If you’re still not thinking of metaprogramming as a normal  
technique, then perhaps you should not use it. (But that’s a catch-22.)

2. If you go back and look at code after a week or two, and have a hard  
time readily understanding what’s going on, then perhaps it’s too  
clever.

–  
James B.

[http://web2.0validator.com](http://web2.0validator.com) - We’re the Dot in Web 2.0  
[http://www.rubyaz.org](http://www.rubyaz.org) - Hacking in the Desert  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 5, 2006, 11:43pm UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/3 "2006-12-05T23:43:03Z")

</div>

On Dec 05, 2006, at 10:21 pm, Giles B. wrote:

> resources for those questions like, when do I use metaprogramming,  
> when do I just use more normal techniques?

I’ve wondered this too after I’ve written something that looks a bit  
too clever for its own good.

I usually ask myself these questions:

- do I only think it looks too clever because I couldn’t do it in Java?
- when I come back to it 6 months later, will it be more obvious what I  
was doing than the longhand version?
- could I factor out the cleverness into a library, or is it more of  
a design pattern?

answers.should == %w[Yes] \* 3 # 🙂

If the test passes, it’s probably good. Usually, when something  
looks like Ruby for Ruby’s sake, it’s because before I wrote it, I  
wasn’t good enough to understand it (never figured out how that  
works…). If I feel like a better programmer afterwards, it stays.

Ashley

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 6, 2006, 12:11am UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/4 "2006-12-06T00:11:09Z")

</div>

Giles B. wrote:

> Obviously this is a judgement call – but does anyone know good  
> resources for those questions like, when do I use metaprogramming,  
> when do I just use more normal techniques?

My personal take to the when is: Depends, sparingly if in doubt.

If you’re not engaging in external code-clobbering, knock yourself out.  
If you can keep your own private language to your code, then if you feel  
that your code is indeed cleaner with metaprogramming, just go ahead and  
use it. The worst thing that can happen is that you’ll shoot yourself in  
the foot, get a subtle bug, fix it, and learn how to avoid doing it  
again - a gift that keeps on giving! _ducks_

However, watch it in interfaces to external code. Code to be consumed by  
third parties, or with high probability maintained by third parties  
should if nothing else keep a well-defined interface that doesn’t change  
on a whim except by explicit library client request with methods to do  
precisely that. (This doesn’t apply to libraries that are mainly  
metaprogramming aids like traits et al.) For code with others  
maintaining it, writing more exhaustive documentation is a good  
self-test. If you can trace back your own code like you do with the  
harder snippets on the mailing list in your head and unravel the  
workings into words up to the “Ah-hah!” point, and then put a digest of  
your mind’s core dump into docs, you should be set - this would imply  
there’s actual sense behind the meta code structure instead of just  
threading hacks together in something that works out yet is just a shiny  
notation for something trivial.

David V.

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 6, 2006, 3:13am UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/5 "2006-12-06T03:13:34Z")

</div>

> I’ve wondered this too after I’ve written something that looks a bit  
> too clever for its own good.  
> …  
> Usually, when something  
> looks like Ruby for Ruby’s sake, it’s because before I wrote it, I  
> wasn’t good enough to understand it (never figured out how that  
> works…). If I feel like a better programmer afterwards, it stays.

The “if I feel like a better programmer afterwards” thing seems to be  
the litmus test. The main thing I’m thinking of, it was actually a  
thread here a little while back, it uses eval() and  
instance\_variable\_set() to create a little search controller in Rails  
that can handle simple searches on a wide range of models. It does a  
lot in a very small space, I was very proud of it. In fact I love it  
so much that sometimes I buy it chocolates and sing to it. I showed it  
to somebody as a code sample, in an interview process. The person I  
showed it to dissed it. I told him that he must be a Philistine and a  
servant of Satan, and the company broke off the interview process,  
apparently upset that it had gotten so Biblical.

Anyway, I think by these standards it qualifies as good code. I think,  
though, I’m going to redo it as a generator or maybe a method in the  
before\_filter style. The thing that the experience brought to my  
attention is that eval() and instance\_variable\_set() are kind of  
unusual for many programmers, possibly even disconcerting, and I’m  
beginning to think that adding a layer of indirection, like a curtain  
for the Wizard of Oz to stand behind, might actually be a very good  
thing. If you’re creating something in Rails, your client programmers  
can be graphic designers and marketing people. Expecting them to  
understand metaprogramming might be overly optimistic.

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 6, 2006, 2:53am UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/6 "2006-12-06T02:53:31Z")

</div>

Hi –

On Wed, 6 Dec 2006, Ashley M. wrote:

> > option?
> 
> understand it (never figured out how that works…). If I feel like a better  
> programmer afterwards, it stays.

Doesn’t looking like Ruby for Ruby’s sake mean that it’s clear,  
expressive, elegant, and maintainable? 🙂 Those are the  
characteristics I associate with what I think of as the most  
Ruby-esque Ruby code, anyway.

David

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 6, 2006, 3:25am UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/7 "2006-12-06T03:25:35Z")

</div>

Giles B. wrote:

> thread here a little while back, it uses eval() and  
> instance\_variable\_set() to create a little search controller in Rails  
> that can handle simple searches on a wide range of models. It does a  
> lot in a very small space, I was very proud of it. In fact I love it  
> so much that sometimes I buy it chocolates and sing to it. I showed it  
> to somebody as a code sample, in an interview process. The person I  
> showed it to dissed it. I told him that he must be a Philistine and a  
> servant of Satan, and the company broke off the interview process,  
> apparently upset that it had gotten so Biblical.

That’s hilarious 🙂

-Justin

(Still grinning)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [December 6, 2006, 3:41am UTC](https://www.ruby-forum.com/t/more-than-enough-rope/78460/8 "2006-12-06T03:41:38Z")

</div>

Giles B. wrote:

> If you’re creating something in Rails, your client programmers  
> can be graphic designers and marketing people. Expecting them to  
> understand metaprogramming might be overly optimistic.  
> My experience has been that marketing people don’t understand marketing  
> and graphic designers don’t understand graphic design, but _everybody_  
> thinks he or she is a programmer until required to deliver working code.  
> 🙂

–  
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)  
[http://borasky-research.blogspot.com/](http://borasky-research.blogspot.com/)

If God had meant for carrots to be eaten cooked, He would have given  
rabbits fire.
