Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Access modifiers for callables and types #259

@cgranade

Description

@cgranade

Is your feature request related to a problem? Please describe.
When developing Q# libraries, it is common to introduce small functions and operations that are not intended for direct use, but which are helpful with partial application. At the moment, these functions and operations are given names starting with _ or ending with Impl, but that makes it easy to accidentally take a dependency on these functions and operations from other namespaces or compilation units.

Describe the solution you'd like
I would suggest the inclusion of an accessibility modifier attribute (or possibly multiple, depending on the level of granularity needed), paralleling the use of special-purpose keywords in other languages. In particular,

namespace Microsoft.Quantum.Core {
 
    @Attribute()
    newtype Private = Unit;

}

In code that calls a @Private() function or operation from another namespace or compilation unit, a warning could be raised indicating that about a possible accidental dependency on internal implementation details.

The new accessibility modifier attributes could also be used to simplify documentation generation logic, such that no documentation is generated for @Private() callables rather than depending on name-matching (paralleling the new @Test("…") attribute).

Describe alternatives you've considered

  • The current approach could continue to be used, in which the leading underscore convention is given special meaning by the compiler and documentation generation tool. This suffers the same disadvantages as relying on *Test names for unit testing.
  • New keywords (e.g.: private) could be introduced instead of new attributes.

Metadata

Metadata

Assignees

Labels

area: languageChanges to the Q# languageenhancementNew request or suggestion for an improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions