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

All state variables should be private #1174

Closed
come-maiz opened this issue Aug 8, 2018 · 3 comments
Closed

All state variables should be private #1174

come-maiz opened this issue Aug 8, 2018 · 3 comments
Assignees
Labels
breaking change Changes that break backwards compatibility of the public API. contracts Smart contract code.
Milestone

Comments

@come-maiz
Copy link
Contributor

come-maiz commented Aug 8, 2018

Solidity adds public getters to public state variables. This is kind of magical and dark, and could lead to mistakes.

We should be more explicit on everything we do, to make the code clearer and easier to review. So let's get rid of the automatic getters making all the public state variables private. If the variable has to be accessed from outside of the contract, we should add a getter function that should be either internal or public, depending on how the contracat is designed.

This gives us an extra benefit because the state variables will be implementation details and this allows us to make some changes without modifying the public API of the contract.

@come-maiz come-maiz added kind:improvement contracts Smart contract code. labels Aug 8, 2018
@come-maiz come-maiz added this to the v2.0 milestone Aug 8, 2018
@frangio
Copy link
Contributor

frangio commented Aug 12, 2018

The main benefit of this IMO is encapsulation of a contract's state, because private state variables cannot be modified by derived classes. This enhances the auditability of a modular set of contracts.

@frangio
Copy link
Contributor

frangio commented Aug 12, 2018

Keep in mind that the previous #1097 is a subset of this dealing specifically with StandardToken, and is being addressed in #1197.

@frangio
Copy link
Contributor

frangio commented Sep 5, 2018

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Changes that break backwards compatibility of the public API. contracts Smart contract code.
Projects
None yet
Development

No branches or pull requests

2 participants