[rspec-users] class << self considered harmful... really?
Matt Wynne
matt at mattwynne.net
Sun Nov 30 16:30:47 EST 2008
On 28 Nov 2008, at 16:52, David Chelimsky wrote:
> On Thu, Nov 27, 2008 at 8:17 PM, Mark Wilden <mark at mwilden.com> wrote:
>> On Thu, Nov 27, 2008 at 5:57 PM, Brian Takita
>> <brian.takita at gmail.com>
>> wrote:
>>>
>>> I'm wondering if this is a discussion about taste.
>>
>> I think you're right. I've been using the 'def self.foo' style in
>> various
>> languages for almost 20 years, so of course it feels more natural
>> to me.
>> These languages (except for Smalltalk) had nowhere near the
>> metaprogramming
>> capability nor 'objects all the way down'-ness of Ruby, and 'class
>> << self'
>> is one of those things.
>>
>> ///ark
>
> FWIW, the blog that led to this discussion suggested a performance
> impact as well. As RSpec has gotten dinged for being slower than
> alternatives, that interested me, so I did a little experiment def'ing
> methods 10k times with def self.method and class << self; def method
> ....
>
> def self.method ran an average of 10% faster.
>
> Based on just that, I've all but eliminated class << self from rspec
> in git.
>
> Crazy?
I think so.
I think Brian has argued eloquently that class << self leaves more
readable and maintainable code behind. I don't know the RSpec code
very well, but I'd be surprised if the number of class methods used
would be significant enough that speeding them up will cause a
noticeable increase in the performance of RSpec overall, and it might
make the project harder to hack on, which would be a shame.
We have just under 4000 examples in the songkick code, taking about 7
minutes to run. If I get a chance I'll try out both forks and see if I
can get you some stats.
Matt Wynne
matt at songkick.com
More information about the rspec-users
mailing list