Curious what's the design rationale for making all state variables private

As stated in Style Guidelines, all state variables should be private, and I'm wondering what's the benefit of doing this?

1 Like

Well, for one, your users don't get to see a bunch of "uninteresting" functions when they view your contract on Etherscan.

More generally, you want to expose (as getter functions) only the variables that you actually intend for your clients to use.

Exposing any other variable will just confuse them.

1 Like

Although a truly private variable does not exist on a blockchain, that is all state variables can be accessed by some proper tools and methods, it is generally considered a good practice to ensure a design with higher security than one that is more exposed.

2 Likes

The link in the post is wrong, should be https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/GUIDELINES.md

1 Like