Code Monkey home page Code Monkey logo

Comments (8)

bbatsov avatar bbatsov commented on May 11, 2024

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.

mitio avatar mitio commented on May 11, 2024

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.

burke avatar burke commented on May 11, 2024

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.

burke avatar burke commented on May 11, 2024

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.

mitio avatar mitio commented on May 11, 2024

+1 for "style 2" (no identation, ARel style, etc :)

from ruby-style-guide.

DAddYE avatar DAddYE commented on May 11, 2024

In padrino we use this:

class SomeClass
  def public_method
  end

  private

    def private_methods
    end
end

from ruby-style-guide.

burke avatar burke commented on May 11, 2024

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.

DAddYE avatar DAddYE commented on May 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.