code folding

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 13 16:24:35 PDT 2017


On Monday, March 13, 2017 19:51:59 Inquie via Digitalmars-d-learn wrote:
> 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.

I mean that the code folding itself is not a language feature. It's
something that the IDE does. The compiler doesn't care one whit about code
folding. If #region in C# is there to tell the IDE that the programmer wants
that to be foldable, and that's all it does, then the language has a feature
to help inform IDEs about how the program wants the code to be foldable.
It's still not the language or compiler that does the code folding.

And as I said, if C# has something like this, it's because Microsoft assumed
that you were going to be using Visual Studio, which they control. Languages
don't normally have any features that have anything to do with code editors,
because they don't normally assume anything about the editor that you're
using. C++ doesn't have anything like it (though it looks like Microsoft
added a non-standard extension for it). Neither does Java, python, ruby,
javascript, or PHP - just to name a few. There may be _some_ other language
out there that does, but it's simply not the sort of thing that most
languages do, because they're not usually written with specific editors in
mind. Microsoft with C# is the oddball here, because they control both the
language and the primary editor.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list