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

strict access control and mutability annotations #1677

Open
bryanmontz opened this issue Oct 22, 2024 · 0 comments
Open

strict access control and mutability annotations #1677

bryanmontz opened this issue Oct 22, 2024 · 0 comments
Assignees

Comments

@bryanmontz
Copy link
Contributor

We should make our access control annotations (private, private(set), or not) and our mutability annotations (let vs var) as strict as possible.

Why?

  1. Cognitive load: These annotations are not only for the compiler; they make it easier to reason about what ought or ought not to happen. They help coders accurately describe data, data flows, and user flows according to Product requirements, and they help current coders prevent future bugs.
  2. Compiler optimization: If the compiler knows something is immutable, it can optimize for faster execution.

For access controls, coders should ask themselves with each API (property, function, class, etc): Do outsiders need to have access to this information or this function ("need to know" principle)? If not, it should be marked private (or sometimes fileprivate as the case may be). Or maybe outsiders need only read access and not write access (private(set)).

In short:

  1. If it could be private, it should be private.
  2. If it could be immutable, it should be immutable.
@bryanmontz bryanmontz self-assigned this Oct 22, 2024
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

No branches or pull requests

1 participant