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
Enable Explicit Self Swiftlint rule #61
Comments
I'm not sure I agree this is a useful addition. Generally it just creates more noise in the code. It's a common accepted styling guide to omit it outside of initialisers and closures as the Swift compiler doesn't require it. The Swift core team struck a good balance I feel with this approach. I've seen it in other styling guides such as the one from Ray Wenderlich - to quote from the guide:
I prefer this style as it's 99% of the time clear where the definition is. Perhaps we should start a style guide and host it on the repo where people can collaborate on what should and shouldn't be in it? |
I want to link the Swift proposal for requiring explicit self as well as why it was rejected: I will post on r/swift to hopefully have a broader convo. I am okay with either way as long as we can consistently enforce one or the other. |
Personally, I'm in favor of requiring explicit |
I expect that everybody already knows this but I think it bears saying none-the-less. To require explicit self would be very much against all the most popular and established swift guidelines and most if not all of the ones in existence... Is that something you really want to do? https://github.com/raywenderlich/swift-style-guide#use-of-self
https://github.com/linkedin/swift-style-guide
https://github.com/github/swift-style-guide
https://www.appsfoundation.com/post/swift-code-convention-and-guidelines
https://engineering.vokal.io/iOS/CodingStandards/Swift.md.html#usage-of-self
|
@danielt1263 Thanks for the feedback. In general, guidelines are good practice to follow! That being said, they are guides, not rules. Different projects and project intentions may benefit from not following certain guidelines. Even the core Swift team is aware of this and mentioned it as a reason to why they did not accept a proposal to require explicit self:
There are some great arguments for and against enforcing explicit self usage. The author of the original proposal summed them up pretty well, I suggest you look through it: https://github.com/apple/swift-evolution/blob/master/proposals/0009-require-self-for-accessing-instance-members.md The two that interest me the most are:
|
@kgellci I don't agree that it would be less confusing if this particular project emits compiler errors when self is not used, despite the fact that the Swift Programming Language book says it's not required and every public guideline says not to use it. I think that would be more confusing, not less. I think it would be a PITA to have to constantly explain to new programmers why this project requires All that said, I'm not a maintainer nor do I plan on contributing anytime soon, so my comments probably aren't important. |
That is a good point and will probably be the main reason to not enforce. I am also considering enforcing not using explicit self, if that is the decision, but I do not see a clean way to do it. Maybe will open an issue on Swiftlint. |
After some debate, closing this issue. Main reason being, it may be confusing to swift noobs who are learning using multiple sources. |
https://github.com/realm/SwiftLint/blob/master/Rules.md#explicit-self
Enable explicit self in our swiftlint usage. This will help keep the code across the project consistent and make it more clear in a function if a variable being accessed belongs to the class or is defined somewhere in the function.
Instructions: https://github.com/realm/SwiftLint#configuration
The text was updated successfully, but these errors were encountered: