Curious: why are variables marked as private and then made accessable via public fns

Hey I've always wondered, this is where I'll prolly find the answer.

why are variables often marked as private/internal and then made accessable via public fn, and not directly mark the variable as public? example below

in erc20.sol _name made accessible via name()
in ownable.sol _owner made accessible via owner()

why not address public owner

so whats it O.O?

It allows inheritance. Many times, an ERC20 contract will be inheritated to create a new token contract. If _name and _owner are public, it would make the child contract difficult to make customized changes. Having them private and accessible by virtual functions allows more flexibility in child contracts.

Yes, it's related to inheritance. We want the variables to be private to control how they're modified. For example, on ERC20 we want to guarantee that minting tokens modifies both the balances and total supply variables together, and at the same time emits the proper event.