Skip to content

Review namespaces and folder structure coupling #3422

Closed
@mrlacey

Description

@mrlacey

Describe the problem this feature would solve

The way namespaces are currently used across the codebase is inconsistent.

This is a follow-on from the discussion started around #3405

Describe the solution

Ideally, there should be a standard that is defined for how namespaces are used. This should be documented.
The existing code should then be updated to this standard.

I propose that a single namespace should be used by each package unless there is a need or strong reason not to, or it is necessary for compatibility with external standards (such as the attribute classes being in the System.Diagnostics.CodeAnalysis namespace.
Using multiple namespaces when they are not required can lead to confusion on the part of the developer consuming them.
Having to use multiple namespaces when they are not necessary also adds overhead to the consuming code (even if just in adding using directives).
VS Tooling is able to infer the desired namespaces and offer suggestions to add them but they don't add any value when all they do is reflect the folder structure of the underlying source.

This may result in some breaking changes and so should be done as part of a major release.

Describe alternatives you've considered

Live with the inconsistency that currently exists.

Additional context & Screenshots

From a quick scan across the codebase, different projects/packages typically either use one namespace of everything or have lots of namespaces that reflect the folder structure.

Some noted from my quick review:

  • Parsers have great inconsistency, especially in Core and MarkDown folders
  • files in Services/Core folder inconsistently use the core namespace
  • One of the Weibo files has repeated text in the namespace
  • All the "UWP.Helpers" have lots of subdirectories but only use a single namespace
  • Adaptive/AdaptiveHelper.cs is in the M.T.Uwp.Notifications.Adaptive namespace but all other classes in that folder are in the M.T.Uwp.Notifications namespace
  • Classes in the Adaptive/Elements folder are in their own namespace but most of the other NOtifications classes are in the main namespace
  • WebViewExtensions.cs is in a WebVIew subdirectory but not in the Extensions namespace
  • UWP.UI/Helpers.DesignTimeHelpers isn't in the Helpers namespace but everything else in the folder is
  • UWP.UI/Animations has lots of namespaces
  • most of UWP.UI.Controls are in a single namespace apart from the MarkdownRenderer & TextToolbar
  • DataGrid.Utilities/DoubleUtil.cs seems to be missing a .UI. form the namespace

The above is based on a brief review of the current code.
I'd be happy to take a fuller look at all the code if further investigation of this issue and adopting a consistent convention is agreed upon.

Note also that the HighPerformance and MVVM packages are some of the biggest users of multiple namespaces. As there are the newest packages, changes in them may be impactful. However, if changes are to be made to the MVVM package it will be better to do this as soon as possible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions