qdk icon indicating copy to clipboard operation
qdk copied to clipboard

File-scoped namespace declarations

Open Regenhardt opened this issue 1 year ago • 1 comments

As described in https://github.com/microsoft/qsharp-language/issues/98 in the old repository, file-scoped namespaces should be a thing to reduce boilerplate and nesting. My search didn't turn up this feature request in this current repo.

Original issue text, by cgranade:


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:

  • [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

Regenhardt avatar Jan 29 '24 19:01 Regenhardt

Hi @Regenhardt! Thanks for the issue filing. I think this is going to be somewhat addressed by #493, where we will introduce implicit namespaces based on your project structure.

sezna avatar Mar 05 '24 23:03 sezna

Closing as #493 addresses this, albeit with a different design.

sezna avatar Aug 15 '24 17:08 sezna