May 27, 2007
What's the deal with making iterators be classes in D, rather than simple value types like they are in C++?  I see that tango uses classes, and DTL used them too.  Chris commented over on the Tango forum that "there are problems with using structs".  So what are they?

The way people describe iterators in C++ is as a generalization of a pointer.  Including the fact that they are value types and can be copied.  DTL and tango iterators can't even be copied at all.  Just seems like a struct makes more sense for an iterator in D.

--bb
May 28, 2007
Bill Baxter wrote:
> What's the deal with making iterators be classes in D, rather than simple value types like they are in C++?  I see that tango uses classes, and DTL used them too.  Chris commented over on the Tango forum that "there are problems with using structs".  So what are they?
> 
> The way people describe iterators in C++ is as a generalization of a pointer.  Including the fact that they are value types and can be copied.  DTL and tango iterators can't even be copied at all.  Just seems like a struct makes more sense for an iterator in D.

Iterators should almost certainly be value types (structs).  The problems are that structs currently don't have c'tors/d'tors nor do they have a fully useful copy c'tor.  However, both are planned for inclusion.

Dave
May 28, 2007
David B. Held wrote:
> Bill Baxter wrote:
>> What's the deal with making iterators be classes in D, rather than simple value types like they are in C++?  I see that tango uses classes, and DTL used them too.  Chris commented over on the Tango forum that "there are problems with using structs".  So what are they?
>>
>> The way people describe iterators in C++ is as a generalization of a pointer.  Including the fact that they are value types and can be copied.  DTL and tango iterators can't even be copied at all.  Just seems like a struct makes more sense for an iterator in D.
> 
> Iterators should almost certainly be value types (structs).  The problems are that structs currently don't have c'tors/d'tors nor do they have a fully useful copy c'tor.  However, both are planned for inclusion.

Hmm, I can't think of a case where any of that would matter.
Looking at a few DTL iterators, none of them seem to contain anything that couldn't be done with static opCall.  I do see a somewhat dubious constructor in stack.d, however:

        this(value_type[] elements, index_type position)
        {
            m_position  =   position;
            m_elements  =   elements[position .. elements.length];
        }

This sets the size_t m_position to 10, say, but that becomes position zero in the slice m_elements.  Looks like a bug to me.

And classes don't have fully useful copy c'tors either, so you can't really hold that against structs.

The only think I've thought of (and this is probably Tango's main justification for classes) is that structs can't inherit.

--bb
May 28, 2007
Bill Baxter wrote:
> [...]
> And classes don't have fully useful copy c'tors either, so you can't really hold that against structs.

Classes have reference semantics, so you need to implement a clone() method if you want deep copies.  Value types need to support copy/assign/swap as first-class operations.

> [...]
> The only think I've thought of (and this is probably Tango's main justification for classes) is that structs can't inherit.

There is some talk about allowing structs to implement interfaces, but that is a technically non-trivial change.

Dave
May 28, 2007
David B. Held wrote:
> Bill Baxter wrote:
>> [...]
>> And classes don't have fully useful copy c'tors either, so you can't really hold that against structs.
> 
> Classes have reference semantics, so you need to implement a clone() method if you want deep copies.  Value types need to support copy/assign/swap as first-class operations.

Ok, the way you said it before made it sound like you were arguing structs were no good for iterators because they can't do anything more than a bitwise copy.  But you were actually saying classes are no good for iterators because they can't be given value semantics.  Gotcha.

>> [...]
>> The only think I've thought of (and this is probably Tango's main justification for classes) is that structs can't inherit.
> 
> There is some talk about allowing structs to implement interfaces, but that is a technically non-trivial change.

I'm struggling here.  I'm feeling the void when it comes to iterators in D, but none of the solutions I've seen implemented really resonate with me.  I'm not sure whether it's me, or the libraries, or D that need to change.  But I like my iterators to be value types, darnit.  :-)

--bb
May 28, 2007
Bill Baxter wrote:
> [...]
> I'm struggling here.  I'm feeling the void when it comes to iterators in D, but none of the solutions I've seen implemented really resonate with me.  I'm not sure whether it's me, or the libraries, or D that need to change.  But I like my iterators to be value types, darnit.  :-)

The language definitely needs to change, and fixing structs to be on par with C++ is actually a priority for Walter.  However, finishing const/final/invariant comes first.

Dave
May 28, 2007
"David B. Held" <dheld@codelogicconsulting.com> wrote in message news:f3e2ji$2h7$2@digitalmars.com...
>
> The language definitely needs to change, and fixing structs to be on par with C++ is actually a priority for Walter.

Through what mystical channels of communication do you obtain such information?  I've always found it rather disconcerting that no one knows what's on Walter's mind until one of a select few people talk about it on the NG as if everyone knew about it.  I never seem to hear Walter's opinions and plans from Walter.


May 28, 2007
Jarrett Billingsley wrote:
> "David B. Held" <dheld@codelogicconsulting.com> wrote in message news:f3e2ji$2h7$2@digitalmars.com...
>> The language definitely needs to change, and fixing structs to be on par with C++ is actually a priority for Walter.
> 
> Through what mystical channels of communication do you obtain such information?  I've always found it rather disconcerting that no one knows what's on Walter's mind until one of a select few people talk about it on the NG as if everyone knew about it.  I never seem to hear Walter's opinions and plans from Walter. 

IIRC David talks to Alexei (and Walter?) IRL...
May 28, 2007
"Frits van Bommel" <fvbommel@REMwOVExCAPSs.nl> wrote in message news:f3eond$146l$1@digitalmars.com...

>
> IIRC David talks to Alexei (and Walter?) IRL...

That's good to know, but it would be _fantastic_ if the results of their little brainstorming sessions were made public, or if the sessions themselves were.  It's very frustrating that this tiny core group of people is driving the development of D with little to no interaction with the rest of the users.  Don't get me wrong -- I really like that structs are being improved, I just don't like being in the dark, and I would imagine few people do.


May 28, 2007
Jarrett Billingsley wrote:
> "Frits van Bommel" <fvbommel@REMwOVExCAPSs.nl> wrote in message news:f3eond$146l$1@digitalmars.com...
> 
>> IIRC David talks to Alexei (and Walter?) IRL...
> 
> That's good to know, but it would be _fantastic_ if the results of their little brainstorming sessions were made public, or if the sessions themselves were.  It's very frustrating that this tiny core group of people is driving the development of D with little to no interaction with the rest of the users.  Don't get me wrong -- I really like that structs are being improved, I just don't like being in the dark, and I would imagine few people do. 

If you want D to develop as quickly as C++, then Design by Committee is a great idea.  When does C++0x come out?  2009?  If you want to hear the status straight from the horse's mouth, so to speak, move to Seattle, where you can stalk him in person. ;)

If you notice, Walter does solicit public feedback directly from time to time, but you may also notice that it takes a long time for a feature to go from idea to implementation.  If he announced every thought he or someone else had about a feature while it was being designed, you'd find that most of it is noise or confusing.  If you multiply that by the number of people on the NG, I guarantee that absolutely nothing would get done.  It's simply a matter of pragmatism to meet with people face-to-face to help flesh out ideas, because the bandwidth is much higher and it's easier to filter out the noise.

But I will say this: Walter is influenced more by libraries that he thinks are cool or important than by many other considerations, and insists that features those libraries need to survive and thrive be given extra priority.  So people who want to lobby for a pet feature can do so most effectively by producing a significant library that demonstrates the need for the feature.  It seems only natural that if there isn't a significant use case, the value of a feature is unproven.

Dave
« First   ‹ Prev
1 2 3 4
Top | Discussion index | About this forum | D home