Basically, would you rather want everything in a class/module/struct/whatever to be inaccessible by anything else unless you give a keyword saying it’s public (like Rust) or have everything accessible unless you make it private (like Ruby and Crystal)? Why?

Also, what do you think of languages that make you write public or private for every member, or ones that inherit the default state from whatever the parent member is?

  • ☆ Yσɠƚԋσʂ ☆
    link
    52 years ago

    I think it depends on whether the language defaults to mutability or immutability. In a language defaulting to mutable data it’s important to keep tight control over data access and what’s exposed.

    In a language where immutability is the default this problem largely goes away since changes only affect the local context. The only case where you might want to make something private would be to hide implementation details. If something isn’t part of the public API then it can be changed later on without becoming a breaking change for the users of the API.