On Monday, 13 March 2017 at 18:26:22 UTC, Jonathan M Davis wrote:
On Monday, March 13, 2017 17:29:41 Inquie via
Digitalmars-d-learn wrote:
Does D have any nice way to specify a block for cold folding?
I have a very large set of structs and I'd like to be able to
code fold them all at once and together.
I have been using
static if(true)
{
... junk
}
but the static if is uninformative since that is the only line
that is shown when folded. A comment helps but still kinda
ugly.
C# has #regions and hopefully D has something as useful.
Code-folding is an IDE thing, not a language thing. So, it's
not the sort of thing that would normally be built into a
language. If Microsoft did it with C#, it's only because they
assumed that everyone would use Visual Studio, but I would
guess that #region actually does more than just enable code
folding. However, since I've done relatively little with C#, I
don't know.
So, how code folding works is going to depend entirely on
whatever IDE or code editor you're using. If you told us which
IDE you were using, maybe someone here could give you some
tips, but it's going to be specific to your IDE. Normally, I
think that folks just code fold based on braces if they're
doing fode folding, but I don't know. I've certainly never
heard of anyone adding anything to a source file just to enable
code folding.
- Jonathan M Davis
This is wrong. It is a language feature.
#region lets you specify a block of code that you can expand or
collapse when using the outlining feature of the Visual Studio
Code Editor. In longer code files, it is convenient to be able to
collapse or hide one or more regions so that you can focus on the
part of the file that you are currently working on. The following
example shows how to define a region:
Obviously it is useful for the IDE, but if it was not a language
feature then the code would not compile(as it's not a comment).
I use visual studio and if it was an IDE feature then I could
insert #regions in it and it would compile. This would, of
course, break anyone else code that doesn't use an IDE that
supports it... hence it has to be a language feature(or some type
of meta comment thing, which it is not in this case).
Just because you have never heard of it doesn't mean much... it
is anecdotal... before the year 0BC no one ever heard of
computers... or antibiotics, or spacecraft, or transistors, or
just about anything we have to day.