Comments (8)
I've generally favoured the latter style (it's the one used in TRPL book and in the ruby-mode authored by Matz), but I'm not quite fond of it, so I've decided to merge the Rails style indentation you've suggested. We'll see how the community would react - I personally think that on some level it improves the readability of the code.
from ruby-style-guide.
I've seen and use the latter style of indenting access modifiers (with the appropriate blank lines around the modifier).
However, AFAIK Rails uses a modification of the first version and also the second version (again showing lack of consistency). They use the "first" version in modules and the "second" one in classes, but I can't say that this is consistent and I also don't like it. This is the modification of the first version it uses:
class SomeClass
def public_method
end
private
def private_methods
end
end
I haven't seen @burke's first option used in Rails.
Again, I would vote for the indented access modifier, i.e. the latter version.
from ruby-style-guide.
Yeah, I definitely want to avoid deferring to Rails here. This is one part of the project's coding style that absolutely baffles me.
This is a good article discussing the options http://fabiokung.com/2010/04/05/ruby-indentation-for-access-modifiers-and-their-sections/
I can get behind either style 2 or style 3 (The ones in my earlier comment). I don't think 1 and 4 should be considered, nor should Rails' style.
I just skimmed my gems directory (sans rails) and found a pretty even split between 2 and 3.
Maybe it would be a good idea to model after ARel's style here? https://gist.github.com/1227301
from ruby-style-guide.
Aaron is a pretty inconsistent with his spacing around access modifiers, but I would write that out as something along the lines of:
- Do not indent access modifiers (
public
/private
/protected
). - Leave a blank line above and below access modifiers, except where the modifier appears at the top of a class context. In this case, omit the blank line above.
[examples]
from ruby-style-guide.
+1 for "style 2" (no identation, ARel style, etc :)
from ruby-style-guide.
In padrino we use this:
class SomeClass
def public_method
end
private
def private_methods
end
end
from ruby-style-guide.
I get the appeal of the rails/padrino style, but to me it feels even more wrong than out-denting the access modifiers, since it implies a scope has been opened. It makes it very difficult to trace a method back up to its enclosing context, since there are now either 2 or 4 spaces of indentation between the class
line and the def
line. This gets to be a real challenge in files like active_record/base.rb
(not to imply that a 2200-line file isn't a code smell in and of itself).
After thinking about this some more, I think I'm going to have to re-cast my vote for style 2. It may not stand out as much, but it is semantically much more consistent and clear.
EDIT: It also does have the benefit of being more widely-published.
from ruby-style-guide.
Im pretty open to this, I tried all 3 versions and I can't say what is better, I prefer the 3° way only for esthetic reason, btw yep, you are right.
from ruby-style-guide.
Related Issues (20)
- Typo in loop with break? HOT 1
- New exception classes HOT 1
- File naming with acronyms HOT 3
- `extend`ing objects at runtime HOT 2
- Usage of do...end block syntax in conditionals HOT 1
- Compact case statements: is there a way to enforce single-line when? HOT 4
- Add a rule for method calls in multiline blocks HOT 3
- Good practice - Heredocs in hash HOT 2
- Whitespace around certain operators HOT 6
- Prefer `grep` and `grep_v` to `select`/`reject` that does a regexp match (Ruby 3+)
- Numbered parameters HOT 2
- Is there a typo in the Suppressing Exceptions section? HOT 2
- Add guidance for safe navigation operator (`&.`) HOT 3
- Why not allowing multi-line ternary operator? HOT 2
- `using` in "Consistent Classes" HOT 6
- The '%w' and '%i' syntax for arrays is just a bad idea HOT 10
- Consider definining `#nil?` method a bad practice HOT 4
- Enforce no parentheses for `include`, `extend`, etc?
- [Idea] Write "good" before "bad" examples HOT 2
- /.,m/.,m/.,m/.,m./,m.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-style-guide.