[rspec-users] class << self considered harmful... really?
zach.dennis at gmail.com
Tue Nov 25 13:04:02 EST 2008
On Tue, Nov 25, 2008 at 12:51 PM, Mark Wilden <mark at mwilden.com> wrote:
> On Tue, Nov 25, 2008 at 8:34 AM, Zach Dennis <zach.dennis at gmail.com> wrote:
>> > Nevertheless, I regard the practice as a bit of
>> > an affection - 'look at me, ma, I'm opening the eigenclass!' - or as the
>> > imitation of an affection. It confuses newbies to no purpose, and
>> > confuses
>> > everyone when 'class << self' has scrolled off the top of the screen.
>> A lot of things confuse newbies. I don't think that's a very good
>> point for why you don't do something.
> I believe potential confusion is a good argument against something, ceteris
> paribus. However, as I indicated at the end of my message, ceteri are not
> always paribi. In other words, we all do things that would confuse newbies,
> but (like #each) they have obvious benefits. That's why we use them.
>> Educating people so they understand why and when it should be avoided
> Well, sure, but I'm just talking about cutting some code, here, not writing
> a blog article.
>> is better then raising a fire alarm (unless it's really a fire).
>> Contrary to your statement though, I don't use class << self to feel
>> special, and my ma could care less about how I code. ;)
> Sorry! I didn't mean to seem like I was addressing you personally, Zach.
I didn't think you were. Did my wink-smily not come through?
> fact, I was thinking of a blog entry I read the other day where a single
> method was enclosed in 'class << self.' The only reason I could think of for
> that was 1) because it looked cool to the author, or 2) he thought it would
> look cool to others. It just looked like a couple of lines of wasted space
> to me.
> I don't know about any fire alarms - I think the important thing to consider
> is what benefits the practice has. In most cases I've seen, there aren't
> any, and it does have the disadvantages I mentioned.
More information about the rspec-users