[rspec-users] class << self considered harmful... really?

Avdi Grimm avdi at avdi.org
Sun Nov 30 16:39:45 EST 2008

On Sun, Nov 30, 2008 at 4:30 PM, Matt Wynne <matt at mattwynne.net> wrote:
> I think Brian has argued eloquently that class << self leaves more readable
> and maintainable code behind.

I don't think so.  Nothing that has been said here has changed my
feeling that using class << self for class methods is an overly-clever
hack that makes it impossible to tell whether you're looking at a
class or instance method in any class more than a page long.  There's
a reason Matz recommends against it, and a reason we recommend against
it in our codebase where I work.  This isn't just esthetics - I've
seen my own code comprehension speed noticeably diminished by files
where I had to keep scrolling up and down to keep track of what kind
of method I was looking at.  If you keep all your classes to under a
page in length, good for you; but most Ruby programmers don't have
that discipline in my experience.  I don't think it's a practice worth


Home: http://avdi.org
Developer Blog: http://avdi.org/devblog/
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

More information about the rspec-users mailing list