Coder Social home page Coder Social logo

Comments (7)

ddsferreira avatar ddsferreira commented on July 22, 2024 2

My thoughts on this matter:

  • I believe public interface and protected interface should be self contained.
  • To emphasise this I like to enforce self in public and protected methods inside their classes or modules so that their - usage is conscious enough.
  • This way the developer is forced to pay for the cost of an extra method exposed in those interfaces.
  • Code readability is also improved by showing to the reader the nature of each one of the methods in use.
  • Public and protected method recursive calls should be reduced to the bare minimum.
  • Refactor code to use auxiliary classes.
  • Make intensive use of private methods.
  • By doing it we will be using self explicitly only in limited situations.

from ruby-style-guide.

bbatsov avatar bbatsov commented on July 22, 2024

This is not something that's specific to Ruby and I've rarely seen someone coding like this in Ruby. That said - send me a pull request with your suggestions and I'll consider it for inclusion.

from ruby-style-guide.

KL-7 avatar KL-7 commented on July 22, 2024

I don't see it too often, but often enough to get a bit annoyed.

Seems like most of the ruby programmers tend to omit self unless it's absolutely necessary (e.g., when using an attribute writer), but some relatively new rubist use self everywhere either for the sake of readability (I'd argue that it has the opposite effect) or just because of the habit developed while working with some other language (e.g., python).

As it's an open choice for a newcomer I think the established way of dealing with self's worse mentioning in the style guide.

@marcandre, are you going to create a pull request?

from ruby-style-guide.

marcandre avatar marcandre commented on July 22, 2024

@KL-7 Agreed. More explicit is not necessarily clearer. If you can do it, that would be great, otherwise I will at some point.

The codebase I'm working on is full of redundant self., which is why I opened the issue in the first place. Indents are tabs too, so...

There are also a lot of nil? and ! blah.nil?, same idea here, unless one wants to distinguish between false and nil?, I feel it's better to leave these off. I guess I'll open another issue?

from ruby-style-guide.

philc avatar philc commented on July 22, 2024

+1. It would help to take a position on the usage of self, with some rationale. I've seen it used a lot.

from ruby-style-guide.

meh avatar meh commented on July 22, 2024

+1.

from ruby-style-guide.

marcandre avatar marcandre commented on July 22, 2024

Ok, finally got around writing some stuff up. Let me know what you guys think.

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.