[Propousal] Readable using statments #3048
Replies: 17 comments
-
For me as for JS hater this syntax look odd. PS. Some languages does not have namespaces at all (Objective-C, Swift) so why not to just remove namespaces from C#? (sarcasm) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
There's nothing to learn here. Never memorize which type lives in which namespace. The tooling today also discourage this: when you hover on a type name, the tooltip will show its full name. When you typing an unimported type, the importer will provide the namespace for you.
It's strongly depending on the organization of standard library. .NET's standard library is organized in multi-level hierarchy. Using a namespace only import a group of types. Given the sample case, writing that |
Beta Was this translation helpful? Give feedback.
-
What if you are viewing code on GitHub ? What kind if tool will help you ? Code should be readable by default without any external tool ... Otherwise we can put in tool all features of language !!!!! |
Beta Was this translation helpful? Give feedback.
-
When reading code on GitHub, I never look at the |
Beta Was this translation helpful? Give feedback.
-
It is not about obvious things like Thread in System.Threading, but about readability !! Looking at code in C# you never now where is type located !! |
Beta Was this translation helpful? Give feedback.
-
I’ve worked on multiple large .Net projects (large meaning >1M loc) and I can literally count on one hand the number of times this has been an issue. It’s also worth noting that the C# using statement is not about importing types, it’s about convenience - it’s always possible to use the fully qualified type name, once the project has an assembly reference. This makes it very different from languages like Javascript and Typescript. |
Beta Was this translation helpful? Give feedback.
-
But if it would be possible to show which types are used in file than it will improve readability !!
If some feature is different it does not mean that it is better ;) |
Beta Was this translation helpful? Give feedback.
-
The language team was well aware of how C# does not work the way the languages you referenced work. You're not importing specific types from a module or package. You're working with namespaces, and bringing them into scope. This is exactly how |
Beta Was this translation helpful? Give feedback.
-
And in world of C++ it is considered to be antipattern using whole namespace
If Visual Studio will add by default a new using statement than during the time it will be possible to change situation 😉 |
Beta Was this translation helpful? Give feedback.
-
True enough. Except that you're arguing that other languages do this thing you want, so C# should do it too. But, those languages don't do the thing you think they do, so the analogy is weak.
Readability is a subjective measure - a matter of opinion & familiarity. For example, when I'm working on Angular projects, all the extra stuff at the top of the file just looks to me like a mess - it's all cluttered and difficult to read. Having to explicitly list each separate type that I want to use feels like useless boilerplate. This doesn't mean that it's wrong for TypeScript to explicitly include the types; just that it's different - and that one person's improved readability is another's cluttered mess. Instead of arguing that it improves readability, you need to demonstrate how this solves real problems that are commonly encountered by other developers. |
Beta Was this translation helpful? Give feedback.
-
Only for https://stackoverflow.com/a/26722134/2900606
That will certainly not happen. At best you could hope for would be an opt-in formatting option, which most developers wouldn't enable (or want to enable). |
Beta Was this translation helpful? Give feedback.
-
This sounds like something that could be written as an extension, like
CodeLens, but I certainly don't think it should be part of the language.
…On Thu, 26 Dec 2019, 23:47 HaloFour, ***@***.***> wrote:
@redradist <https://github.com/redradist>
And in world of C++ it is considered to be antipattern using whole
namespace
Only for std and only because it's massive and flat. .NET does not suffer
from that problem. It's also an anti-pattern to import namespaces in header
files since that impacts source files that include said header, which is
also not a problem in C# since using directives are always scoped to the
current source file and never impact other files.
https://stackoverflow.com/a/26722134/2900606
If Visual Studio will add by default a new using statement than during the
time it will be possible to change situation
That will certainly not happen. At best you could hope for would be an
opt-in formatting option, which most developers wouldn't enable (or want to
enable).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/csharplang/issues/3048?email_source=notifications&email_token=ADIEDQLXDAZ7YUOXJHCNXJTQ2U67ZA5CNFSM4J6LTWXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHWI6FQ#issuecomment-569151254>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADIEDQPBACX4QRLNID2O7XLQ2U67ZANCNFSM4J6LTWXA>
.
|
Beta Was this translation helpful? Give feedback.
-
I think this approach is feasible, sometimes you can’t get the context of the code or assembly, for example when browsing the code on github, but the syntax is a bit ugly, there may be ways to improve.May be |
Beta Was this translation helpful? Give feedback.
-
From my point of view it is bad, 'cause it is not obvious the hierarchy of class in namespaces |
Beta Was this translation helpful? Give feedback.
-
It also doesn't work in left-to-right intellisense. |
Beta Was this translation helpful? Give feedback.
-
@redradist |
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.
-
When we want to use some library we have to add using statement:
but ... it make hard reading and learning from the code ... (
Consider to enhancement using by default the following syntax:
Share your opinion ...
Also be aware that this feature is taken from such languages as Java, Python, Rust, Javascript ...
And it could mean that this feature has been proved as useful ;)
Beta Was this translation helpful? Give feedback.
All reactions