Comments on: In Defence of class https://blog.mattwynne.net/2008/12/01/in-defence-of-class/ Matt Wynne taking it one tea at a time Wed, 21 Aug 2019 13:02:06 +0000 hourly 1 https://wordpress.org/?v=6.2 By: Brian Takita https://blog.mattwynne.net/2008/12/01/in-defence-of-class/comment-page-1/#comment-335 Wed, 10 Dec 2008 20:05:07 +0000 http://blog.mattwynne.net/2008/12/01/in-defence-of-class/#comment-335 @Pat – def self.foo isn’t clear when it needs to reference self.bar (or self.class.bar) (what is self now?) and instance variables that are a part of the class object.

Regarding the refactoring:
Sure, its easy to do a replace, but the mechanical steps are the easy part of the refactoring.
def self.foo makes it difficult to see that there is a separate object. Its an imperative operation instead of being declarative.

The visual scattering happens all the time with projects that use def self.foo. I’m currently on a project where its driving me nuts. Its simply more difficult to understand the code because I have to parse the entire file to see all of the def self.foo methods.

]]>
By: Pat Maddox https://blog.mattwynne.net/2008/12/01/in-defence-of-class/comment-page-1/#comment-330 Thu, 04 Dec 2008 06:10:20 +0000 http://blog.mattwynne.net/2008/12/01/in-defence-of-class/#comment-330 I think that the refactoring benefits of class << self are dubious. M-x replace-string def self., def. Even lesser editors will make that refactoring a breeze 😉 I kind of sympathize with the argument that the visual grouping can alert you to an object that should be extracted, but I’m not sure how common that really is, from my experience. In my book, the clarity of def self.foo trumps the other arguments.

]]>
By: Brian Takita https://blog.mattwynne.net/2008/12/01/in-defence-of-class/comment-page-1/#comment-329 Thu, 04 Dec 2008 05:47:07 +0000 http://blog.mattwynne.net/2008/12/01/in-defence-of-class/#comment-329 I find my editor’s code folding/unfolding features very useful in identifying the eigenclass scope when it spans more than one page.

If I’m unsure, I do a quick fold all command, and then unfold until I get to my cursor. The unfolding is a quick way to identify whether you are in the eigenclass or class scope.

It would be useful if ruby editors could somehow identify the lexical scope you are in (like a breadcrumb in the editor status area).

]]>
By: Mark Wilden https://blog.mattwynne.net/2008/12/01/in-defence-of-class/comment-page-1/#comment-328 Wed, 03 Dec 2008 22:40:02 +0000 http://blog.mattwynne.net/2008/12/01/in-defence-of-class/#comment-328 Nice summation. Just one thing: you can declare class methods private with private_class_method

]]>
By: Avdi https://blog.mattwynne.net/2008/12/01/in-defence-of-class/comment-page-1/#comment-327 Wed, 03 Dec 2008 15:21:07 +0000 http://blog.mattwynne.net/2008/12/01/in-defence-of-class/#comment-327 Congrats, I came here expecting to think “WRONG WRONG WRONG”, but you’ve effectively summed up both the pros and cons and made a cogent and reasonable argument for using class << self to define class methods. Nicely done.

]]>