[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

"more than enough rope"

Giles Bowkett

12/5/2006 10:22:00 PM

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.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

9 Answers

James Britt

12/5/2006 10:41:00 PM

0

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.0val... - We're the Dot in Web 2.0
http://www.... - Hacking in the Desert
http://www.jame... - Playing with Better Toys

Ashley Moran

12/5/2006 10:42:00 PM

0


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

David Vallner

12/5/2006 11:11:00 PM

0

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

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

dblack

12/6/2006 1:52:00 AM

0

Giles Bowkett

12/6/2006 2:13:00 AM

0

> 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.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

Justin Collins

12/6/2006 2:24:00 AM

0

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)

M. Edward (Ed) Borasky

12/6/2006 2:41:00 AM

0

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

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


Christopher A. Lee

3/19/2013 9:59:00 PM

0

On Tue, 19 Mar 2013 14:52:18 -0700 (PDT), hypatiab7
<hypatiab7@comcast.net> wrote:

>On Mar 19, 4:16?pm, sbalneav <sbaln...@alt-atheism.org> wrote:
>> In alt.atheism Man of God <Mano...@biblelife.com> wrote:
>>
>> > "God hates fags!"
>>
>> >http://kroq.cbslocal.com/2013/03/18/90s-alt-folk-rocker-now......
>>
>> Several enlightened venues immediately say "No thanks!" to bigotry, and cancel
>> her shows.
>>
>> On a related note, I threw out all my Orson Scott Card novels a year or so ago.
>
>Just a year ago? I gave mine to a local library when his Mormonism
>became more and
>more obvious in his writing. This was years ago. I only kept about
>three of his early books.
>It was like he was trying to get away from Mormonism for a few years,
>then got dragged
>back in.

I didn't even realise he was a Mormon until after I'd read the first
two or three Ender books, but to me they started getting a bit silly.

nature bats_last

3/20/2013 4:19:00 AM

0

On Mar 19, 2:59 pm, Christopher A. Lee <ca...@optonline.net> wrote:
> On Tue, 19 Mar 2013 14:52:18 -0700 (PDT), hypatiab7
>
>
>
>
>
>
>
>
>
> <hypati...@comcast.net> wrote:
> >On Mar 19, 4:16 pm, sbalneav <sbaln...@alt-atheism.org> wrote:
> >> In alt.atheism Man of God <Mano...@biblelife.com> wrote:
>
> >> > "God hates fags!"
>
> >> >http://kroq.cbslocal.com/2013/03/18/90s-alt-folk-rocker-now.......
>
> >> Several enlightened venues immediately say "No thanks!" to bigotry, and cancel
> >> her shows.
>
> >> On a related note, I threw out all my Orson Scott Card novels a year or so ago.
>
> >Just a year ago? I gave mine to a local library when his Mormonism
> >became more and
> >more obvious in his writing. This was years ago. I only kept about
> >three of his early books.
> >It was like he was trying to get away from Mormonism for a few years,
> >then got dragged
> >back in.
>

;
> I didn't even realise he was a Mormon until after I'd read the first
> two or three Ender books, but to me they started getting a bit silly.

Famously, DC Comics hired Card recently to write an issue
or two of one of their "Superman" lines. The furor
was immediate and very very loud -- nothing to do with
his religion, but with his notorious bigotry regarding
gays. Comics stores all over (including mine) refused
to carry these issues; the artist withdrew, and DC finally
reneged on the whole thing.




NBL