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).
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:
[x] I have searched both open and closed suggestions and proposals on this site and believe this is not a duplicate.
[x] I believe that the spirit of this suggestion is aligned with the design principles and general vision for Q#.
Please tick all that apply:
[x] This is not a breaking change to the Q# language design
[x] I or my organization would be willing to help implement and/or test this
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.
Example 2: Mixing file- and block-scoped namespaces is forbidden.
Affidavit (please fill out)
Please add ticks by placing a cross in the box:
Please tick all that apply: