Closed 3442853561 closed 7 years ago
You should explain in the first post what #region does, since not all know C#.
If I recall correctly, it's just a directive for the IDE that allows defining a "logical" region of source code, which the editor can, for example, collapse. It doesn't affect the actual code semantics in any way.
It should be noted also, that Rust allows already attributes using syntax #[attribute]
. Maybe using the already existing attribute syntax for IDE region hints could be feasible?
You can just put it in comments as it done for C, C++, etc.
As a C# developer, the only time I've seen #region
used properly was to allow you to collapse the licensing text at the top of a source file. The other 99% of the times it has been to hide the fact that the file is way too long. If your file/class/function is big enough that you need to use regions, it's past time to break things up.
lot of c# programmers discourage use of region, you can do collapsing with ide or you can split the code in files
I think this should be re-opened. There are uses for #region
that aren't to "hide the fact that the file is way too long". Using #region
for splitting up Public, Protected & Private members and methods helps to keep files tidy irrespective of whther they are long or short files.
As a C# developer, the only time I've seen
#region
used properly was to allow you to collapse the licensing text at the top of a source file. The other 99% of the times it has been to hide the fact that the file is way too long. If your file/class/function is big enough that you need to use regions, it's past time to break things up.
Dear Wesley Wiser,
As a C# developer, the only time I've seen
#region
used properly was to allow you to collapse the licensing text at the top of a source file. The other 99% of the times it has been to hide the fact that the file is way too long. If your file/class/function is big enough that you need to use regions, it's past time to break things up.
I don't think the C#/Java OOP tendency to separate everything every little chunk of state+function into it's own file is necessarily a good habit. Especially for a systems programming language long files can be expected. Systems do not get less complex just because their complexity is amortized over the filesystem. #region #endregion are a way to program in this systems programming style while still offerings progs softer methods to group and compartmentalize features within a single file.
Personally I'm a big fan of the way Swift/Xcode handle this. Swift uses comments with specific keywords such as: // MARK: xxx
, // MARK: -
, // TODO: xxx
, // FIXME: xxx
, etc. In my opinion, this is in line with Rust, as we already have the /// xxx
format for documentation. Also, it would not require any changes to the language itself: this is just an addition to the common practices of the language. Finally, it would easily be picked up by any IDE (example of how this works for Swift in Xcode).
Edit: I would also make the argument that comments are better suited for non-code/documentation/organizational information than #region
or [#attribute]
or other more "code-like" constructs (at least, this is my preference).
Swift uses comments with specific keywords such as:
// MARK: xxx
,// MARK: -
,// TODO: xxx
,// FIXME: xxx
, etc.
I've seen (and used) the TODO
/FIXME
ones (or, my favorite, HACK
) in most languages I've used.
// FIXME: ...
(and the "attributed" variant, e.g.: // FIXME(eddyb) ...
) comments are widely used in the Rust compiler itself, and have been for the past decade.
And some IDEs will highlight some of those comments across multiple languages.
However, I haven't seen anything that common for collapsible regions.
But a quick search for VSCode reveals https://marketplace.visualstudio.com/items?itemName=maptz.regionfolder which after some quick testing does seem to work with /* #region ... */
/* #endregion */
comments in Rust (sadly it doesn't support //
comments for Rust but it does for C, so it can likely be fixed to treat Rust like C, or the instructions in its documentation can be used to locally add support).
So IMO, there are two separate issues here:
// #region
)kwrite
/kate
/kdevelop
, which I used before VSCode) appear to support //BEGIN
and //END
{
in the start comment and }
in the end comment (instead of the end
word) feels like something I may have seen, but I have no idea where (maybe doc comments in a language other than Rust? maybe it involved @{
? not sure)// FIXME
or folding)
OTOH, I would not expect non-comment alternatives to be a viable proposal (that is, one could try to open an RFC for them, but I doubt it would receive a lot of support).
My best guess as to how this could move forward, would be someone posting to the internals and/or users forums to gather some opinions on what people might want to use (i.e. subjective aesthetics).
If this does lead to some kind of agreement, there are a few places where I've seen/added a non-doc comment (with empty lines before and after it), to indicate the start of a new "section", that could use it.
add "#region" like C#