-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndentationWidth opinion for Ruby 2.1 is questionable #1092
Comments
I prefer your second option: private def foo
# ...
end I'd like to throw in a couple more options, just for completeness (not because I like them): private \
def foo
# ...
end private(
def foo
# ...
end
) |
@chendrix We could definitely add a configuration option to support the style you prefer. Maybe it would be better to extract the @mikegee I think the extra examples you supplied will be covered too (maybe not the last one) if we do something like DefEndAlignment:
AlignWith: start_of_line
SupportedStyles:
- start_of_line
- def |
I agree with @mikegee. Weigh the benefit o having the access modifier be so screamingly obvious against the sacrifice of a good chunk of the maximum line length. Looking at the code I work with, I'd rather have the space. Besides,
private
def foo
# ...
end
public
# ...
class Widget
# ...
protected
def foo
# ...
end
private
# ...
end # class Widget I've been using that system since the UCSD p-System days and IWFM. Thoughts? |
@jdickey I personally always either disable or significantly lengthen the I've always always hated the traditional way of access modifiers as seen in your 2). Design principles (and in particular Gestalt) state that "objects or shapes that are close to one another appear to form groups", the principle of Proximity. The opposite to this is visual Rhythm. class Widget
# ...
protected
def foo
# ...
end
private
# ...
end # class Widget shows significant Rhythm, as scanning with the eye shows all keywords are left aligned and that every single "chunk" (def, private, protected) is separated from the one above and below it by a single space. This means that there is no Proximity and that your protected and private sections do not get visually associated into groups. Compare that to class Widget
# ...
##################################
protected
def foo
# ...
end
##################################
private
# ...
end # class Widget which breaks the visual Rhythm and promotes Proximity groupings. It's much harder to accidentally miss the access modifiers in this version than in the "best practices" one. So instead of trying to make proximity based groupings of access control which likely can only be done with clunky comments or some other form of spacing-scheme, we can pull a style from Java-land and instead specifically tag our private and protected method class Widget
# ...
protected def foo
# ...
end
private def bar
# ...
end
private def baz
# ...
end
end # class Widget Then at this point it's a matter of preference between the various "tagged access" forms that myself and @mikegee stated. |
@chendrix: I'm actually OK with your last example, where the access modifier is simply part of the method signature (thus implying that it should be supplied for every method?). I was just voicing my disbelief that anyone would actually use your original example's indentation style as a horrendous waste. But if we used the style you just proposed, then a) we'd need a cop to remind us when we forgot an access specifier, and b) we'd take even more flak from those who think Ruby is "starting to look too much like Java". Finally, I wonder how much of this is really a way of avoiding addressing a code smell; i you've got more than a reasonably-sized source file, you may well have an SRP violation such as Feature Envy.I periodically go through my then-current project's sources, looking hard at any that are more than 2 sigma over the mean, or 120 lines, whichever is less. As often as not, I find that I've conflated multiple concepts unintentionally and, with a little thought, can come up with better code. |
|
And others like me won't see any benefit, but sure enough would Why not this here instead? def foo I prefer this style, or: private def foo Is also ok. But: private def uargh is awful. I however concur that RuboCop should be easily able to allow you to BTW chendrix on your comment at you even used another style than you originally |
@shevegen Agreed on all counts. @chendrix, when in your initial comment you said
you were exactly right; and I think that most of the folks pushing back against your new style probably don't see your I hereby move that the issue be closed without action. |
So will Rubocop move to not implement all things its core developers deem
|
Also @shevegen
I have to believe you're being contrarian for the sake of being contrarian if you seriously consider that a viable, aesthetic, and meaningful alternative. It's another one of the many styles where you lose scannability of your access modifiers. |
@chendrix I'd be happy to implement something similar to what I proposed earlier in this discussion. I've been busy with bug fixes for a while and am now on vacation, and that's the main reason why it hasn't been done already. @mikegee @jdickey @shevegen You've all argued why you prefer the currently enforced style. This is interesting but not crucial, since we'll keep that style as the default. Only if @chendrix's style didn't hold up logically would it be proper to close the issue without action. I've seen nothing that suggests it is so; it's just a matter of preference. |
Because of the change in Ruby 2.1 that causes method definitions to return a symbol of their method name, we can now do things like
Now this may just be my opinion, but things like
private def foo
is much preferable thanand you couldn't even do the ingenious
cached def bar
before.So this brings up the question of preferences between two styles:
I personally much prefer the former as it specifically highlights the distinct nature of this kind of method declaration.
If you do it this way, RuboCop complains about the
IndentationWidth
being larger than 2, about theEndAlignment
, and aboutEmptyLinesAroundAccessModifier
, which I question.The text was updated successfully, but these errors were encountered: