Namespace and Class Directives #4177
Unanswered
TylerDM
asked this question in
Language Ideas
Replies: 2 comments
-
See: #137 I don't see that being extended to |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Namespace and Class Directives
Summary
Allow
namespace
andclass
to have Using Directive-like syntax.Motivation
Detailed design
If you've ever taken a C# course, you've probably seen a class like this at least once.
I propose removal of the braces from
using
andclass
and assume they contain the entire file;This is quite a lot better! We've eliminated the boiler plate code that never changes in 99% of C# files. We've also eliminated 2 tabs on nearly the entire file. Costs? None. We can take this just a hair further as well:
The basic concept works well for
record
and other similar concepts.Drawbacks
I personally do not like having multiple syntaxes for the same feature. In this case, however, I think it makes sense. You can use the old syntax for multiple namespaces or classes in a single file, should you want to. The old syntax would also be useful for nested classes. And then use the new syntax for the 99% of the time that those things aren't desired or needed.
This does reinforce a specific coding style of having one class per file. I have mixed feelings about catering C# to any particular style or use case. That said, the one class per file style is so ubiquitous that I believe the pragmatic benefits outweigh the philosophical drawbacks.
Alternatives
Combine the
namespace
andclass
directives into a single directive.You could also allow multiple namespaces and class per file by allowing multiple directives, with the latest one taking precedence.
Unresolved questions
None known.
Design meetings
None thus far.
Beta Was this translation helpful? Give feedback.
All reactions