Comments (7)
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.
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.
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.
@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.
+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.
+1.
from ruby-style-guide.
Ok, finally got around writing some stuff up. Let me know what you guys think.
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.