Access control let programmers to encapsulates parts of the implementation details.

There are certain design choices of implementation, including the syntax, default visibility, and what kind of language construct (files, modules or classes) does access control apply.

Syntax

Various languages has different way to implement access control syntax. 1

Modifier Keywords

public, private, protected, internal in each declaration. Languages: Java, C#, Rust, PHP, etc

Verbose

Modifier Sections

C++ has modifier keywords apply to all subsequent declarations. This is less verbose but makes the language context-sensitive.

Sigils in the Names

  • Go: Public/private
  • Python (not enforced)/dart: public/_private

These are less verbose

Downsides:

  • obscure and harder to learn and search for new learners
  • They show up at the user sites
  • tends to limit the language to two distinct visibility mode (public and private)

Export Manifests

See: Ocaml module interface

Most of ML families and Lisps have some kind of separate syntax for listing exports. This is way more verbose, but achieves strict interface/implementation segregation.

JavaScript modules uses a hybrids approach where programmer can export both at declaration site or separately.

Default Visibility

Language can default access control to public, private, or some middle option. See my thought on this topic

Footnotes

  1. Access Control Syntax – journal.stuffwithstuff.com