nep1: prefer self to this by timotheecour · Pull Request #16927 · nim-lang/Nim (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation3 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
settles Anybody using self or this for procedures operating on "class" style object types? - Nim forum
rationale
- self is better (more DRY) than repeating type name with underscore:
proc fun(someLongTypeName: SomeLongTypeName, a: int)
selfis more common thanthisfor this purpose:
in nim repo:
rg '(this: '| wc -l
56
rg '(self: '| wc -l
235selfis more searchable thanthisbecausethisis more common in english:
crude stats because some references might correspond to this as a param name, but still illustrative:
rg '\bthis\b' | wc -l
3580
rg '\bself\b' | wc -l
764
- 50-50 argument:
selfis common in python (but this is common in js)
future work
Another PR to replace all remaining this with self.
We should also remove {.this: self.} to be consistent, been several years Deprecated already.
Another PR to replace all remaining this with self.
We should also remove {.this: self.} to be consistent, been several years Deprecated already.
ok to both but in another PR (note that renaming 1st param from this to self is a potential breaking change in case user writes foo(this = bar, ...), but this is unlikely in practice; anyways, this can be discussed in another PR)
ardek66 pushed a commit to ardek66/Nim that referenced this pull request