Jump to page: 1 2 3
Thread overview
code folding
Mar 13, 2017
Inquie
Mar 13, 2017
Jonathan M Davis
Mar 13, 2017
Inquie
Mar 13, 2017
bachmeier
Mar 13, 2017
Jonathan M Davis
Mar 13, 2017
XavierAP
Mar 13, 2017
Inquie
Mar 14, 2017
Vladimir Panteleev
Mar 14, 2017
XavierAP
Mar 14, 2017
Inquie
Mar 14, 2017
Inquie
Mar 14, 2017
bachmeier
Mar 14, 2017
Inquie
Mar 14, 2017
Mike Parker
Mar 14, 2017
bachmeier
Mar 14, 2017
Inquie
Mar 14, 2017
flamencofantasy
Mar 18, 2017
Entity325`
Mar 18, 2017
Entity325`
Mar 14, 2017
Adam D. Ruppe
Mar 14, 2017
Inquie
Mar 14, 2017
Ali Çehreli
Mar 14, 2017
Inquie
Mar 14, 2017
Ali Çehreli
Mar 18, 2017
Basile B.
March 13, 2017
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.

March 13, 2017
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

March 13, 2017
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.




March 13, 2017
On Monday, 13 March 2017 at 17:29:41 UTC, Inquie wrote:
>
> I have been using
>
> static if(true)
> {
>     ... junk
> }

Indeed #region is part of the C# specification, even if it has no effect on the code. (The specification does not say anything about folding/collapsing, just about "marking sections of code", although I guess most IDEs supporting it will follow the example of MS's reference implementation.)

Short answer, D does not have this, as far as I know.

I don't really think it's good substitute practice to insert meaningless static if(true)... Even if you're really used to that feature, and even if you're right that it does the job and doesn't change the generated code.

Unfortunately you can't get this folding easily (I'm sure some Vim wizard would come up with something). Instead if you want to mark regions of code, that's what comments are for. You can't get the folding you want unfortunately (outside of naturally existing bracket pairs) but you can use your editor to search forward and backward in the file for whatever text, e.g.

//region: foo//
March 13, 2017
On Monday, 13 March 2017 at 21:17:31 UTC, XavierAP wrote:
> On Monday, 13 March 2017 at 17:29:41 UTC, Inquie wrote:
>>
>> I have been using
>>
>> static if(true)
>> {
>>     ... junk
>> }
>
> Indeed #region is part of the C# specification, even if it has no effect on the code. (The specification does not say anything about folding/collapsing, just about "marking sections of code", although I guess most IDEs supporting it will follow the example of MS's reference implementation.)
>
> Short answer, D does not have this, as far as I know.
>
> I don't really think it's good substitute practice to insert meaningless static if(true)... Even if you're really used to that feature, and even if you're right that it does the job and doesn't change the generated code.
>
> Unfortunately you can't get this folding easily (I'm sure some Vim wizard would come up with something). Instead if you want to mark regions of code, that's what comments are for. You can't get the folding you want unfortunately (outside of naturally existing bracket pairs) but you can use your editor to search forward and backward in the file for whatever text, e.g.
>
> //region: foo//


That's not the point. The point is that the IDE I use(VS, which is the most common IDE on windows), requires an actual block to fold. Folding is useful so it is not an irrelevant issue. Even notepad++ can fold blocks if it can determine what a block, so this isn't an "IDE" specific thing nor an "IDE" specific feature.

When one had a shit load of types in a single file, it is nice to be able to fold them. It is also nice to be able to group them in some way(hence the question) and fold the group so that large chunks of the file can be visibly reduced.

One can say that it is a useless feature because D doesn't have it... or one could say that D is useless because it doesn't have it. A nice balance is simply to say "It is a useful feature that has proven it's worth and it is time that D implements something like it". As D becomes more mainstream, these features will be requested. D should learn from other language/compilers just as other languages/compilers have learned from it. (it's a two a way street)

If D supported such simple stuff hacks would not be required to do the simple things.

March 13, 2017
On Monday, 13 March 2017 at 19:51:59 UTC, Inquie wrote:

> 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).

From my understanding of the feature, it does the same as

// region

... code to be folded ...

// endregion

An IDE can then read those comments and allow code folding. It might meet some definition of a language feature, but it is nothing more than 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).

I don't understand how it would break your code.

March 13, 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

March 14, 2017
On Monday, 13 March 2017 at 21:33:56 UTC, Inquie wrote:
> One can say that it is a useless feature because D doesn't have it... or one could say that D is useless because it doesn't have it. A nice balance is simply to say "It is a useful feature that has proven it's worth and it is time that D implements something like it". As D becomes more mainstream, these features will be requested. D should learn from other language/compilers just as other languages/compilers have learned from it. (it's a two a way street)

FYI: The "you must implement my feature request or D will never succeed" attitude is rather common and never helpful. Not to mention that such an argument would be demonstrably false: every popular language without the feature you want has apparently succeeded despite not having said feature.

> When one had a shit load of types in a single file, it is nice to be able to fold them. It is also nice to be able to group them in some way(hence the question) and fold the group so that large chunks of the file can be visibly reduced.

If you have enough declarations in one file that they call for code folding, it may be better to move them to a separate module. Public imports and aliases allow doing this without breaking any code.

If you would like a way to achieve code folding without involving language constructs, I think the starting point would be your IDE/editor's D plugin vendor. Once implemented in one editor, the syntax could be implemented in others and be informally standardized.

I don't think that it would make sense to introduce it into the language syntax proper. The #region syntax in C# makes sense for C# because, as already mentioned, the language vendor is also the main IDE vendor; but also because C#, like Java, requires a lot more boilerplate - writing programs in C# is much more tedious without an IDE than with. This is not the case of D, which was designed to solve problems that would otherwise require boilerplate code in the language itself.

Generally speaking, I would recommend to simply avoid code folding altogether:

https://blog.codinghorror.com/the-problem-with-code-folding/
March 14, 2017
On Tuesday, 14 March 2017 at 00:38:12 UTC, Vladimir Panteleev wrote:
>
> If you have enough declarations in one file that they call for code folding, it may be better to move them to a separate module. Public imports and aliases allow doing this without breaking any code.
>
> [...]
>
> Generally speaking, I would recommend to simply avoid code folding altogether:
>
> https://blog.codinghorror.com/the-problem-with-code-folding/

Indeed good point:
http://stackoverflow.com/questions/475675/when-is-a-function-too-long
March 14, 2017
On Tuesday, 14 March 2017 at 00:38:12 UTC, Vladimir Panteleev wrote:
> On Monday, 13 March 2017 at 21:33:56 UTC, Inquie wrote:
>> One can say that it is a useless feature because D doesn't have it... or one could say that D is useless because it doesn't have it. A nice balance is simply to say "It is a useful feature that has proven it's worth and it is time that D implements something like it". As D becomes more mainstream, these features will be requested. D should learn from other language/compilers just as other languages/compilers have learned from it. (it's a two a way street)
>
> FYI: The "you must implement my feature request or D will never succeed" attitude is rather common and never helpful. Not to mention that such an argument would be demonstrably false: every popular language without the feature you want has apparently succeeded despite not having said feature.
>

I never said that. I said those were the extremes and you decided to pick the extreme that you disagreed with. I'd like you to take a moment and instead of arguing against the feature that you obviously do not like and try to argue for it. I know it will be hard and you won't be able to come up with anything, but try anyways...


>> When one had a shit load of types in a single file, it is nice to be able to fold them. It is also nice to be able to group them in some way(hence the question) and fold the group so that large chunks of the file can be visibly reduced.
>
> If you have enough declarations in one file that they call for code folding, it may be better to move them to a separate module. Public imports and aliases allow doing this without breaking any code.

Maybe, maybe not... proves nothing as it is just your preference.

> If you would like a way to achieve code folding without involving language constructs, I think the starting point would be your IDE/editor's D plugin vendor. Once implemented in one editor, the syntax could be implemented in others and be informally standardized.

That would be fine and dandy, but that is just kicking the can down the road to someone else. You should argue on the validity of the issue itself and not on

> I don't think that it would make sense to introduce it into the language syntax proper. The #region syntax in C# makes sense for C# because, as already mentioned, the language vendor is also the main IDE vendor; but also because C#, like Java, requires a lot more boilerplate - writing programs in C# is much more tedious without an IDE than with. This is not the case of D, which was designed to solve problems that would otherwise require boilerplate code in the language itself.

This is not logical. When the designers of C# were creating it, in no way did they say "Well, since C#'s IDE will be our IDE we will add this feature", and if they weren't they wouldn't have added it. They added it because they thought it was a useful thing in general. People don't create compilers based on what the IDE can or can not do.



> Generally speaking, I would recommend to simply avoid code folding altogether:
>
> https://blog.codinghorror.com/the-problem-with-code-folding/

Anecdotal. One guys view is not proof of anything. Sometimes it is not feasible to split things. The baby shouldn't be thrown out with the bath water. Obviously the designers of C# thought it was important and useful enough and anyone can hunt for a counter example of someone not liking something.


If you start with the conclusion that something is wrong or bad(or even right or good) and simply simply opinions as proof, you do not prove anything. You should argue on the merits of the feature itself and not your own person opinions, desires, and wishes.


« First   ‹ Prev
1 2 3