Top level statements and member declarations (embrace scripting dialect) (VS 16.8, .NET 5)
The C# compiler currently understands a dialect of the language used for various scripting and interactive purposes. In this dialect, statements can be written at the top level (without enclosing member bodies) and non-virtual members (methods etc) can be written at the top level (without enclosing type declarations). Usage of the scripting dialect has been relatively minor, and in some ways it hasn't kept up with the "proper" C# language. However, usage is picking up through Try.NET and other technologies, and I am concerned with being stuck with two incompatible dialects of C#. I think there is merit to allowing top-level program code instead of requiring the "program" to be in a `Main` method. And I think there is merit to allowing functions to be declared at the top level of a program, without needing to be enclosed in a class. I think these allow small programs to be meaningfully simpler, and make the language easier to learn. ``` c# public int Fac(int x) => x < 0 ? x * Fac(x-1) : 1; // Top-level function Console.WriteLine(Fac(5)); // Top-level statement ``` As opposed to: ``` c# public class Functions { public int Fac(int x) => x < 0 ? x * Fac(x-1) : 1; // Top-level function } public class Program { static void Main() { Console.WriteLine(Functions.Fac(5)); // Top-level statement } } ``` I believe we should consider putting these extensions into C# "proper" and do away with the separate scripting dialect. In doing so we should not feel too b
Posted by MadsTorgersen on Aug 30, 2019, 11:30 PM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
Top level statements and member declarations (embrace scripting dialect) (VS 16.8, .NET 5)
The C# compiler currently understands a dialect of the language used for various scripting and interactive purposes. In this dialect, statements can be written at the top level (without enclosing member bodies) and non-virtual members (methods etc) can be written at the top level (without enclosing type declarations). Usage of the scripting dialect has been relatively minor, and in some ways it hasn't kept up with the "proper" C# language. However, usage is picking up through Try.NET and other technologies, and I am concerned with being stuck with two incompatible dialects of C#. I think there is merit to allowing top-level program code instead of requiring the "program" to be in a `Main` method. And I think there is merit to allowing functions to be declared at the top level of a program, without needing to be enclosed in a class. I think these allow small programs to be meaningfully simpler, and make the language easier to learn. ``` c# public int Fac(int x) => x < 0 ? x * Fac(x-1) : 1; // Top-level function Console.WriteLine(Fac(5)); // Top-level statement ``` As opposed to: ``` c# public class Functions { public int Fac(int x) => x < 0 ? x * Fac(x-1) : 1; // Top-level function } public class Program { static void Main() { Console.WriteLine(Functions.Fac(5)); // Top-level statement } } ``` I believe we should consider putting these extensions into C# "proper" and do away with the separate scripting dialect. In doing so we should not feel too b
Comments (0)
No comments yet. Start the discussion.