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?

  • Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    3 years ago

    To me, it comes down to: Is it dumb data or not?

    If it is dumb data that gets passed through my program, then everything should be public (and ideally immutable).

    If it’s not dumb data, but rather the state of a piece of logic (typical in OOP), then I want everything private.

    If the language doesn’t distinguish between those, then I prefer private by default, because it’s hard to forget making it public, if you actually need to access it from the outside.