C# without braces? Let indentation do the job. #9603
Replies: 2 comments
-
C# is not a whitespace sensitive language. Attempting to retrofit it to be one would be an enormous amount of work and introduce ambiguities for no real benefit. IMO this is akin to asking python to support curly braces for scoping in addition to indentation. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Effectively a duplicate of #496, though this goes further. The answer to that one is that it will never happen, and this is similar. Have you tried F#? |
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.
-
Proposal: Optional Braces for Block Structures Based on Indentation (Python-style syntax for C#)
Summary
Introduce an optional syntax mode in C# that allows developers to omit curly braces
{}
for block structures (e.g.,if
,for
,while
, methods, classes), relying instead on indentation to define scope — similar to Python.This would be an opt-in feature that preserves full backward compatibility with existing C# syntax.
Motivation
Examples
Current C# syntax
Proposed indentation-based syntax
This would apply to all block structures, including loops, methods, classes, etc.
Opt-In Mechanism
To avoid breaking existing code and tooling, this feature would be explicitly enabled via one of the following:
#pragma indentBlocks
.editorconfig
setting/langversion:preview
)Technical Considerations
Drawbacks
Conclusion
This proposal aims to offer a modern, concise alternative to traditional C# syntax without replacing it. By making braces optional through indentation, developers gain flexibility and clarity — especially in clean, functional-style codebases.
The feature would be opt-in, ensuring full compatibility and developer choice.
Related Discussions
None found at the time of writing. This appears to be a novel proposal.
Beta Was this translation helpful? Give feedback.
All reactions