Re: code folding

2017-03-18 Thread Basile B. via Digitalmars-d-learn

On Monday, 13 March 2017 at 17:29:41 UTC, Inquie 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.


In Coedit I added regions to the highlighter.

//---+
//

http://imgur.com/a/hIUTV.

A comment that ends with ---+ start a region. Comment that ends 
with  ends a region, if any.


Re: code folding

2017-03-17 Thread Entity325` via Digitalmars-d-learn

On Saturday, 18 March 2017 at 05:00:48 UTC, Entity325` wrote:
and both create a scope outside of which no declarations inside 
them are visible(potentially undesirable side-effects).


Oh. Static ifs don't do that. Disregard, I'm wrong.


code folding

2017-03-17 Thread Entity325` via Digitalmars-d-learn

FYI,
static if(true)//comments are great for adding some context to 
your code.

{
   //stuff
}

and

{//let's toss a comment on the scope declaration!
   //stuff
}
are functionally equivalent in my IDE. Both will fold down to 
only the top {(good), and both create a scope outside of which no 
declarations inside them are visible(potentially undesirable 
side-effects).


If you need to sequester your code, you really should just toss 
it into a library and import it from there(no side-effects).


Re: code folding

2017-03-14 Thread Ali Çehreli via Digitalmars-d-learn

On 03/14/2017 02:48 PM, Inquie wrote:

>> version (all) {
>> // ...
>> }
>>
>> You can define your own version identifiers as well:
>>
>> version = some_descriptive_name;
>>
>> version (some_descriptive_name) {
>> // ...
>> }
>>
>> Ali
>
> Oh, that might be better. I thought of versions but I didn't want to
> have to define anything... didn't know about all.

I remembered reading about it here: ;)

  http://ddili.org/ders/d.en/cond_comp.html#ix_cond_comp.all,%20version

which includes a link to the very long list of pre-defined version 
identifiers here:


  http://dlang.org/spec/version.html#predefined-versions

Ali



Re: code folding

2017-03-14 Thread Inquie via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 20:56:02 UTC, Ali Çehreli wrote:

On 03/13/2017 10:29 AM, Inquie 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.



There is version:

version (all) {
// ...
}

You can define your own version identifiers as well:

version = some_descriptive_name;

version (some_descriptive_name) {
// ...
}

Ali


Oh, that might be better. I thought of versions but I didn't want 
to have to define anything... didn't know about all.





Re: code folding

2017-03-14 Thread Ali Çehreli via Digitalmars-d-learn

On 03/13/2017 10:29 AM, Inquie 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.



There is version:

version (all) {
// ...
}

You can define your own version identifiers as well:

version = some_descriptive_name;

version (some_descriptive_name) {
// ...
}

Ali



Re: code folding

2017-03-14 Thread Inquie via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 17:07:57 UTC, Adam D. Ruppe wrote:

On Monday, 13 March 2017 at 17:29:41 UTC, Inquie wrote:

Does D have any nice way to specify a block for cold folding?


I personally sometimes use

// some description {

// }

since my editor does a really good job matching {}, even in 
comments so it is convenient to jump anywhere, and i can search 
the description text to get back to it from anywhere.


I can fold it too but i personally prefer just jumping it than 
actually folding it.


Yeah, that would be better, unfortunately VS/VD doesn't do this.


Re: code folding

2017-03-14 Thread flamencofantasy via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 16:58:21 UTC, Inquie wrote:

On Tuesday, 14 March 2017 at 16:29:15 UTC, Mike Parker wrote:

[...]


It's not that I feel strongly about, I simply would like the 
best useable solution. Like usually what happens, my original 
post was taken completely out of context:


[...]


static if(true) // region blah
{
   junk...
}

when folded;

static if (true) // #region blah{...}

does that solve your problem?


Re: code folding

2017-03-14 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 13 March 2017 at 17:29:41 UTC, Inquie wrote:

Does D have any nice way to specify a block for cold folding?


I personally sometimes use

// some description {

// }

since my editor does a really good job matching {}, even in 
comments so it is convenient to jump anywhere, and i can search 
the description text to get back to it from anywhere.


I can fold it too but i personally prefer just jumping it than 
actually folding it.


Re: code folding

2017-03-14 Thread Inquie via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 16:29:15 UTC, Mike Parker wrote:

On Tuesday, 14 March 2017 at 15:44:27 UTC, Inquie wrote:



So, with all the bloviating, all I have arrived at is that my 
original hack is still the only way to get the cold folding I 
wanted(the original use case I had in mind, even though I'd 
rather have proper code structuring support in general). 
Generally when even a hint of a suggestion of a language 
addition is created, the worms come out to party...


If it's something you feel strongly about, then the way to go 
about it is to put together a DIP. There was a time when you 
could open a forum post about a new feature and eventually see 
it added, but those days are long gone (for good reason). If 
any new feature is going to have any hope of getting in these 
days, then it needs someone to champion it through the DIP 
process.


It's not that I feel strongly about, I simply would like the best 
useable solution. Like usually what happens, my original post was 
taken completely out of context:


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

No where do I mention anything about a language change. I asked 
if D had something useful and better than my hack. What it seems 
to stir up is a bunch of people that have a fear based reaction, 
which I can only hypothesize why. Usually it involves someone 
trying to state absolutely why what I am doing is wrong or bad 
and all they offer is anecdotal evidence and their opinions. None 
of which are helpful or useful.


I would wager that more than 50% of D users have this mentality, 
and given that, it is highly unlikely that I could push for such 
changes. I'd get more done and have more use by forking D and 
adding my own features for my own personal use.


What perplexes me is why so many have such a disdain for any 
change that ultimately doesn't effect them much. If, say the 
"#regions" feature was implement, or some variant, and they are 
right and it is useless then chances of them ever encountering 
such code is slim... and code they do encounter would generally 
not a a problem(light use). Yet, those that do use it(in house), 
which, if it is so bad, according to them, should be rare, would 
benefit from it, at least in their own mind.


You know, there is something called "Survival of the fittest" and 
if an idea is truly bad then it will die out. Many people don't 
even want to give any idea a chance to go through that process... 
fear of it being successful? Fear they might have to learn 
something new? Fear it might require them to adapt their 
understanding of how things work? Fear of it being a waste of 
time? Fear of it causing a nuclear meltdown? When it will affect 
them almost nil, and they rail against it, it is some deep seeded 
fear from something... Unless they can give nearly absolute 
mathematical proof why it is invalid/wrong.


Anyways, my hack is good enough for me. If they ever see any of 
my code, they might rather have allowed something a bit more 
syntactically pleasing and so they can blame themselves(which 
they won't). Of course, we could always depreciate "static if 
(true)" to prevent that possibility! Maybe that is the real 
solution?













Re: code folding

2017-03-14 Thread bachmeier via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 16:29:15 UTC, Mike Parker wrote:

If it's something you feel strongly about, then the way to go 
about it is to put together a DIP. There was a time when you 
could open a forum post about a new feature and eventually see 
it added, but those days are long gone (for good reason). If 
any new feature is going to have any hope of getting in these 
days, then it needs someone to champion it through the DIP 
process.


In addition, not that it won't get very far without a 
demonstration of how this (a) can't be done using comments, and 
(b) can't be handled at the IDE level. I have to admit that I do 
not understand at this point why a change to the language is 
needed.


On the other hand, if this does provide value, I'd expect it to 
be one of the easiest possible additions to push through, because 
it won't break anyone's code.


Re: code folding

2017-03-14 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 15:44:27 UTC, Inquie wrote:



So, with all the bloviating, all I have arrived at is that my 
original hack is still the only way to get the cold folding I 
wanted(the original use case I had in mind, even though I'd 
rather have proper code structuring support in general). 
Generally when even a hint of a suggestion of a language 
addition is created, the worms come out to party...


If it's something you feel strongly about, then the way to go 
about it is to put together a DIP. There was a time when you 
could open a forum post about a new feature and eventually see it 
added, but those days are long gone (for good reason). If any new 
feature is going to have any hope of getting in these days, then 
it needs someone to champion it through the DIP process.


Re: code folding

2017-03-14 Thread Inquie via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 15:18:00 UTC, bachmeier wrote:
On Tuesday, 14 March 2017 at 00:38:12 UTC, Vladimir Panteleev 
wrote:


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.


This is a little different, however, in the sense that there is 
no reason to add a feature to the language to do what is 
requested. If you use Emacs, you can get the same thing in any 
language using comments:


https://www.emacswiki.org/emacs/FoldingMode


and I agree that having an such a feature(for #region) would 
better be handled by comments(assuming it, itself, can be 
commented out easily). But either way, we do not have the 
capabilities with D in the first place. I do not use Emacs but 
the Visual D, which I assume is the sponsored IDE for D.



This is an issue for the IDE, not for the language, and 
changing the language would not have any effect on IDE support 
for code folding.


Remember, it is not just about code folding(which seems to be the 
common misconception). The cold folding is a sort of byproduct of 
struct defining language features... of which, D has very little 
of. Version, is a good one for certain things, but useless here 
for code structure itself.


My original statement was if D had the ability to do proper code 
folding rather than resorting to hacks and it has been derailed 
in to an language vs ide battle.


So, with all the bloviating, all I have arrived at is that my 
original hack is still the only way to get the cold folding I 
wanted(the original use case I had in mind, even though I'd 
rather have proper code structuring support in general). 
Generally when even a hint of a suggestion of a language addition 
is created, the worms come out to party...










Re: code folding

2017-03-14 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 00:38:12 UTC, Vladimir Panteleev 
wrote:


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.


This is a little different, however, in the sense that there is 
no reason to add a feature to the language to do what is 
requested. If you use Emacs, you can get the same thing in any 
language using comments:


https://www.emacswiki.org/emacs/FoldingMode

This is an issue for the IDE, not for the language, and changing 
the language would not have any effect on IDE support for code 
folding.


Re: code folding

2017-03-14 Thread Inquie via Digitalmars-d-learn

Just for fun:

1. Folding directives are glorified comments. #region has zero 
meaning to the compiler; it's a hint to the editor to allow code 
folding. It doesn't do any namespacing or scoping. Why, exactly, 
are we writing code to accommodate the editor? It boggles my mind 
that we'd add significant lines of code to our project that do 
nothing but offer organizational hints to the editor. Even 
traditional comments are a better value for your keystroke, 
because they can be more expressive. And folding is certainly no 
substitute at all for bona-fide refactoring.


BS. I use regions in C# to separate disparate code. I like to 
know how my code functions and the structure of code relative to 
itself. It helps conceptually understand the code better.


2. Folding is used to sweep code under the rug. Got a bunch of 
boring boilerplate code that makes your eyes water? A slew of 
ugly, gnarly code that nobody in their right mind wants to look 
at? Hide it in a region and fold that sucker into oblivion! 
Problem solved, right? Hardly. Your project is now full of crappy 
code that you can't see. That's worse. Much worse! Code that 
hides from you is code that will rot in the most putrescent and 
painful way possible. Your code should be front and center at all 
times -- exposed to as many programmers' eyes, and as much 
healing light, as possible.


No matter what color language you use to object to something 
doesn't mean it is more true. I guess this guy doesn't realize 
that you can unfold the code.


3. Folding is used to mask excessive length. The presence of 
folded code can lull developers into a false sense of what clean 
code looks like. Under the cover of folding, you can end up 
writing long, horrible spaghetti code blocks. If the code needs 
the crutch of folding to look organized, it's bad code.


Well duh, that is one of the benefits of it.

I'll state it again. I use regions in C# to separate disparate 
code. I like to know how my code functions and the structure of 
code relative to itself. It helps conceptually understand the 
code better.




4. Folding can hide deficiencies in your editor. The presence of 
so-called "standard" boilerplate regions like "Public 
Constructors" and "Public Properties" and "Events" is not a 
feature. It's a bug. The editor should automatically offer to 
fold up these common structural blocks for you! I'm continually 
amazed that programmers spend time doing this scutwork when they 
could be writing useful code. Or at least demanding a smarter 
code editor.


This guy obviously doesn't know what a bug is so how could we 
trust his "expertise"? But which is it? the language or the 
stupid IDE? I'm confused?



This guy probably never used #regions to learn how to use them 
properly and has such a pathetic uptight life that all he can do 
is bitch about other peoples poor code practices. That is no 
proof of anything. Instead of bitching, like most people, why 
didn't he write a constructive article about how to use #regions 
properly?


Anyone can write a blog these days kinda sad actually. ;/



I guess you will then state that he is an amazing programmer 
because of SO and that we should all bow down to his wisdom? 
yeah, right





Re: code folding

2017-03-14 Thread Inquie via Digitalmars-d-learn
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.





Re: code folding

2017-03-13 Thread XavierAP via Digitalmars-d-learn
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


Re: code folding

2017-03-13 Thread Vladimir Panteleev via Digitalmars-d-learn

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/


Re: code folding

2017-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
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



Re: code folding

2017-03-13 Thread bachmeier via Digitalmars-d-learn

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.



Re: code folding

2017-03-13 Thread Inquie via Digitalmars-d-learn

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.




Re: code folding

2017-03-13 Thread XavierAP via Digitalmars-d-learn

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//


Re: code folding

2017-03-13 Thread Inquie via Digitalmars-d-learn

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.







Re: code folding

2017-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
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



code folding

2017-03-13 Thread Inquie via Digitalmars-d-learn
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.