[Proposal] Using directives at class level #2981
Replies: 6 comments
-
Nitpick, but the semicolon makes the syntax inconsistent with all other class-level syntax elements (such as |
Beta Was this translation helpful? Give feedback.
-
@DaZombieKiller, I removed the semicolons, thanks. |
Beta Was this translation helpful? Give feedback.
-
😕 Why is this a good idea? As far as I can see, the only result of this would be to make it significantly harder to reason about the source in that file, it would be a fertile source of hard to understand bugs. For example, relocating a method from a sub-class to a parent-class might completely change the nature of the method in an incompatible way. Worst of all, this isn't pay-to-play because the mere presence of this feature in the language would require everyone to pay a price, regardless of whether it was used or not. |
Beta Was this translation helpful? Give feedback.
-
I never say it was, it's an effect of the proposal.
Indeed like using aliases actually do when you relocate some code from one file to an other and the using aliases are not the same in the two files.
Sorry, I don't get your point, could you expand on that ? |
Beta Was this translation helpful? Give feedback.
-
@Orace 👋🏼 I would challenge that why aren't you asking for this at lower levels than the class? Why not even go all the way down to the method-level? |
Beta Was this translation helpful? Give feedback.
-
@Orace asked
If an existing C# project uses aliases (the vast majority of those that I've seen do not), they'll be found at the top of the file, with effect for the entire file. Moving a piece of code from one place to another within that file (say, by promoting a method into a parent class, or by demoting it into a subclass) won't change the definition of any of the types used by that method. If every class is potentially defining it's own type aliases, perhaps even with the same name, simple refactoring becomes much more dangerous because the type It destroys my ability to reason about the code I'm reading. Currently, type aliases in C# are rarely used - it's a feature useful for disambiguation of conflicting simple type names, and mostly it's not needed. This is a good thing. C# doesn't need additional features that encourage obfuscation of code for the benefit of saving a few moments of typing. Code is read far more often than it's written. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Actually
using
directives are declared at the head of a namespace or before any namespace.This proposal is about adding using directive at class level.
Especially using alias and using static directives:
This is a prelude to #2936
Beta Was this translation helpful? Give feedback.
All reactions