Twisting the rope: looking for code examples

— September 10, 2006 at 10:56 PDT


In just about six weeks I'll be giving my talk at RubyConf 2006 called "More than enough rope to hang yourself". The talk will address the pitfalls of overzealous use of some of the more powerful feature in Ruby, such as metaprogramming, method chaining and method_missing hacks. Often these techniques are quite useful, but when overused they can really make your life miserable. Or more often, they mess up some poor sucker who has to deal with the code someone else wrote.

I'm working on writing the presentation itself now. I've got some good examples of excessively clever code, but could always use more. So here's your chance to help contribute to a RubyConf presentation. If you have a good example of Ruby code that is overly clever and makes you want to pull your hair out, I'd love to see it. Email me code examples at (josh (at) hasmanythrough (dot) com).

Thanks!

5 commentsevents, rubyconf

Comments
  1. JohnnyC2006-09-11 00:27:37

    You win:

    has_many :wiki_refs_as_source, :as => :source,
                                   :foreign_key => 'source_id', :class_name => 'WikiRef',
                                   :dependent => :destroy
    has_many :targets, :through => :wiki_refs_as_source
    
    has_many :wiki_refs_as_target, :foreign_key => 'target_id', :class_name => 'WikiRef',
                                   :dependent => :destroy
    has_many :source_articles, :through => :wiki_refs_as_target,
                               :conditions => "wiki_refs.source_type = 'Article'"
    has_many :source_comments, :through => :wiki_refs_as_target,
                               :conditions => "wiki_refs.source_type = 'Comment'"
    
  2. Josh Susser2006-09-11 08:22:25

    @JohnnyC: Ha! Fair enough though. Rails does use some ugly tricks in the API. And yes, I'll be talking about that too in my talk. Though just to be clear, it's not wordiness or complex APIs alone that I'm talking about. It's things that make it hard to understand what code is doing even if you understand the API.

  3. jamie hill2006-09-11 12:18:43

    Active Web Service is pretty bad. I had an incident last week where I was creating a controller on-the-fly (don't ask!) and AWS tries to find a related _api file... I don't want a webservice on that controller!!, in the end I just disabled AWS it altogether. All kinds of weirdness going on in there.

  4. jamie hill2006-09-11 12:18:53

    Active Web Service is pretty bad. I had an incident last week where I was creating a controller on-the-fly (don't ask!) and AWS tries to find a related _api file... I don't want a webservice on that controller!!, in the end I just disabled AWS it altogether. All kinds of weirdness going on in there.

  5. Kevin Olbrich2006-11-15 05:35:34

    I like to say that 'Ruby gives you enough rope to hang yourself and six of your closest friends'.

Sorry, comments for this article are closed.