dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.75k stars 1.07k forks source link

Global Usings for Console Apps #32130

Open yaserbalaghi opened 1 year ago

yaserbalaghi commented 1 year ago

Hi everyone, I suggest that when creating a console project, the following global direction should also be added to the GlobalUsings.cs auto-generation file.

global using static global::System.Console;

So, along with the "Top-Level Statements" feature to teach C# to beginners, the initial confusion will be less and actually it will also be better for professionals.

Screenshot 2023-04-29 104536 Screenshot 2023-04-29 104601

Thank you for your attention.

dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

nagilson commented 1 year ago

I see where you're coming from, though I'm not sure we would do that as it'd likely break a lot of people. @marcpopMSFT Are we the right place for this feedback? IDK if this should go to Roslyn or if it goes to C# lang

marcpopMSFT commented 1 year ago

@nagilson this feels more like a @baronfel question and a template question.

baronfel commented 1 year ago

IIRC @DamianEdwards and @KathleenDollard had some input into what set of Global Usings were originally decided on. What heuristics were you all going off of? I'm inclined to thing that Console is a step too far, but some kind of data-backed frequency analysis here might be useful.

the initial confusion will be less and actually it will also be better for professionals

I'm not sure I agree with this assertion on its face. Console is a highly domain-specific area of code, and in most apps I'd say that it is silo'd off into a specific area of the app (notably the CLI arg parsing section) and the rest of your app doesn't ever care about it. To me that's an argument for a file-local using static, not a project-global `using static.

DamianEdwards commented 1 year ago

Agreed. Adding global static usings is definitely a step beyond what we've thought to date is appropriate for our defaults.