cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[SUGGESTION/RFC] Replace scope resolution operator '::' with member access operator '.'

Open mhermier opened this issue 1 year ago • 11 comments

Hi,

The idea behind that change is to change/simplify the syntax of how we access namespaces components. If the notion of namespace is shifted a little bit to an instantiated "static sparse struct", then the scope resolution operator '::' can simply be replaced with member access operator '.'.

PROS:

  • It unifies the syntax when accessing static/constexpr variables.
  • It simplify the teaching of the navigation in the symbol namespace by eliminating the special case of the scope operator.
  • It eases moving code from namespace variables to member variables. As such it should also be an opportunity to reduce diffs in scm.
  • It should also simplify tools like code generators, by unifying the syntax we don't need a special case for generating namespace member access.

CONS:

  • There might be some corner cases when trying to access types, but I'm quite convicted the ease of write surpass the burden of theses corner cases.
  • I wonder how error prone the unary left '.' operator can be when accessing the global scope.

For now I don't consider it a complete suggestion, but I wonder what other people think about that idea, hence the RFC.

mhermier avatar Nov 24 '24 17:11 mhermier