Skip to content
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

nep1: prefer self to this #16927

Merged
merged 1 commit into from
Feb 4, 2021
Merged

nep1: prefer self to this #16927

merged 1 commit into from
Feb 4, 2021

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Feb 3, 2021

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)
  • self is more common than this for this purpose:
    in nim repo:
    rg '(this: '| wc -l
    56
    rg '(self: '| wc -l
    235
  • self is more searchable than this because this is 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: self is common in python (but this is common in js)

future work

@juancarlospaco
Copy link
Collaborator

juancarlospaco commented Feb 3, 2021

Another PR to replace all remaining this with self.

We should also remove {.this: self.} to be consistent, been several years Deprecated already.

@timotheecour
Copy link
Member Author

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)

@dom96
Copy link
Contributor

dom96 commented Feb 3, 2021

I like this change :)

@Araq Araq merged commit 534a95a into nim-lang:devel Feb 4, 2021
@timotheecour timotheecour deleted the pr_nep1_self branch February 4, 2021 17:36
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants