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

File-scoped namespace statements #98

Open
4 tasks done
cgranade opened this issue May 26, 2021 · 0 comments
Open
4 tasks done

File-scoped namespace statements #98

cgranade opened this issue May 26, 2021 · 0 comments
Labels
UnderReview Suggestion for which a full proposal is being worked out

Comments

@cgranade
Copy link
Contributor

Suggestion

Allow namespace statements to end with a semicolon instead of a block, indicating that the namespace declaration applies to the entire file.

Considerations

Most Q# source files declare exactly one namespace, such that the extra level of indenting is unnecessary in most common cases. Allowing namespace declarations to be file-scoped would cut down on the amount of boilerplate and nesting, making Q# source files easier to read (esp. for newer users).

A similar discussion has led to the proposal and likely adoption of a similar feature into C# 10 (https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/file-scoped-namespaces.md).

Context

This proposal would not change any Q# semantics, but would provide a useful shorthand for existing features and semantics.

Examples

Example 1:
Using file-scoped namespaces to apply a namespace to all declarations in a file.

namespace Microsoft.Quantum.Foo;

// This function is declared with the fully
// qualified name Microsoft.Quantum.Foo.A.
function A() : String {
    return "aaaaaa";
}

Example 2:
Mixing file- and block-scoped namespaces is forbidden.

namespace Microsoft.Quantum.Foo;

namespace Bar { // 💣: can't mix file- and block-scope namespace declarations.
    
}

Affidavit (please fill out)

Please add ticks by placing a cross in the box:

  • I have searched both open and closed suggestions and proposals on this site and believe this is not a duplicate.
  • I believe that the spirit of this suggestion is aligned with the design principles and general vision for Q#.

Please tick all that apply:

  • This is not a breaking change to the Q# language design
  • I or my organization would be willing to help implement and/or test this
@bettinaheim bettinaheim added the UnderReview Suggestion for which a full proposal is being worked out label Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
UnderReview Suggestion for which a full proposal is being worked out
Projects
None yet
Development

No branches or pull requests

2 participants