nep1: guidelines for getters and setters (#17645)

* nep1: guidelines for getters and setters
* address a comment
This commit is contained in:
Timothee Cour 2021-04-09 00:09:04 -05:00 • committed by GitHub
commit 826ad2f36f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -301,3 +301,12 @@ Miscellaneous
let a = """foo
bar
"""
- A getter API for a private field `foo` should preferably be named `foo`, not `getFoo`.
A getter-like API should preferably be named `getFoo`, not `foo` if:
* the API has side effects
* or the cost is not `O(1)`
For in between cases, there is no clear guideline.
- Likewise with a setter API, replacing `foo` with `foo=` and `getFoo` with `setFoo`
in the above text.