"more than enough rope"

Discussion in 'Ruby' started by Giles Bowkett, Dec 5, 2006.

  1. I just found out that Josh Susser'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?

    --
    Giles Bowkett
    http://www.gilesgoatboy.org
    http://gilesbowkett.blogspot.com
    http://gilesgoatboy.blogspot.com
    Giles Bowkett, Dec 5, 2006
    #1
    1. Advertising

  2. Giles Bowkett

    James Britt Guest

    Giles Bowkett wrote:
    > I just found out that Josh Susser'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?


    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 Britt

    http://web2.0validator.com - We're the Dot in Web 2.0
    http://www.rubyaz.org - Hacking in the Desert
    http://www.jamesbritt.com - Playing with Better Toys
    James Britt, Dec 5, 2006
    #2
    1. Advertising

  3. Giles Bowkett

    Ashley Moran Guest

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

    > I just found out that Josh Susser'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?



    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
    Ashley Moran, Dec 5, 2006
    #3
  4. --------------enig0882218D20CFBC7770F54816
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: quoted-printable

    Giles Bowkett 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?
    >=20


    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 Vallner


    --------------enig0882218D20CFBC7770F54816
    Content-Type: application/pgp-signature; name="signature.asc"
    Content-Description: OpenPGP digital signature
    Content-Disposition: attachment; filename="signature.asc"

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.5 (MingW32)

    iD8DBQFFdfyAy6MhrS8astoRAhHNAJ94RuN9iErjPt+1p2lsvPWkawc+PACfRyWa
    ekXEvXKZoYzG9mOLc6mXPZE=
    =63tH
    -----END PGP SIGNATURE-----

    --------------enig0882218D20CFBC7770F54816--
    David Vallner, Dec 5, 2006
    #4
  5. Giles Bowkett

    Guest

    Hi --

    On Wed, 6 Dec 2006, Ashley Moran wrote:

    >
    > On Dec 05, 2006, at 10:21 pm, Giles Bowkett wrote:
    >
    >> I just found out that Josh Susser'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?

    >
    >
    > 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.


    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

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Dec 6, 2006
    #5
  6. > 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.

    --
    Giles Bowkett
    http://www.gilesgoatboy.org
    http://gilesbowkett.blogspot.com
    http://gilesgoatboy.blogspot.com
    Giles Bowkett, Dec 6, 2006
    #6
  7. Giles Bowkett wrote:
    >> 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.


    That's hilarious :)

    -Justin


    (Still grinning)
    Justin Collins, Dec 6, 2006
    #7
  8. Giles Bowkett 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/

    If God had meant for carrots to be eaten cooked, He would have given rabbits fire.
    M. Edward (Ed) Borasky, Dec 6, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page