July 30, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3008





--- Comment #20 from Chad Joan <chadjoan@gmail.com>  2009-07-30 14:16:00 PDT ---
(In reply to comment #18)
> (In reply to comment #15)
> > Incorrect.
> > 
> > s is an lvalue (it isn't being returned)
> > s.getValue is an lvalue (pointer to some C's data, AKA a reference type)
> 
> *struct* MyNiftyPointerTo(T)
> 
> ...
> 
> MyNiftyPointerTo!(C) getValue()
> 
> Read that carefully about 5 times
> 
> getValue returns a struct.  getValue returns an rvalue.  Please recognize this before commenting again.
> 
> > It's not going away because MyNiftyPointerTo!(C).getValue is an lvalue.
> 
> MyNiftyPointerTo!(C) does not have a function called getValue, it is the return
> type from getValue
> 
> > But I'm going to answer the question anyways ...
> 
> Incidentally, I can type quite fast and I have never EVER wanted to save keystrokes when it sacrifices clarity.  My protests have nothing to do with saving keystrokes, they have to do with generic code -- writing code that works whether something is a builtin or a custom wrapper type.

(In reply to comment #18)
> (In reply to comment #15)
> > Incorrect.
> > 
> > s is an lvalue (it isn't being returned)
> > s.getValue is an lvalue (pointer to some C's data, AKA a reference type)
> 
> *struct* MyNiftyPointerTo(T)
> 
> ...
> 
> MyNiftyPointerTo!(C) getValue()
> 
> Read that carefully about 5 times
> 
> getValue returns a struct.  getValue returns an rvalue.  Please recognize this before commenting again.
> 
> > It's not going away because MyNiftyPointerTo!(C).getValue is an lvalue.
> 
> MyNiftyPointerTo!(C) does not have a function called getValue, it is the return
> type from getValue
> 

Ah, sorry.  I was confused because the meaning of getValue changed and foo was never defined in MyNiftyPointerTo!(T).

> > But I'm going to answer the question anyways ...
> 
> Incidentally, I can type quite fast and I have never EVER wanted to save keystrokes when it sacrifices clarity.  My protests have nothing to do with saving keystrokes, they have to do with generic code -- writing code that works whether something is a builtin or a custom wrapper type.

So MyNiftyPointerTo!(T) may grab all of the compile-time reflection info from T and forward all of its functions and such.  Then it becomes a reference to some T, but not a reference in a sense the compiler knows about.

I think I can see now where you're going with this.

I suppose to really make everyone happy, there would need to be some way to annotate struct definitions and say, "Hey, this thing can be mutated as an rvalue, it's all under control."  That probably doesn't make Walter happy though :(

Still, without any major change to the language, we can at least forbid the assignment to members of rvalues as BCS suggested in comment #11, correct?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 30, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3008





--- Comment #21 from BCS <shro8822@vandals.uidaho.edu>  2009-07-30 14:35:05 PDT ---
(In reply to comment #19)
> (In reply to comment #17)
> > 
> > You assume that the above is a bug and what I really wanted was to return a reference. Take another look while assuming that I actual do want return by value and the return by reference would be a bug.
> 
> I suppose what caught me is that it's easily possibly to write GetProcessOutput() such that a ref return isn't a bug.  Just make sure the reference doesn't point to an OutputHandle that's already in use.  I feel like having a value return there is unnecessary.
> 

In most cases you are probably correct but, while I can't enumerate a specific example, I can imagine a cases where the value return us wanted for it's semantics rather than for memory usage reasons. For instance something in the direction of  smart pointers or keeping track of distinct handles to a common resource.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 31, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3008





--- Comment #22 from Steven Schveighoffer <schveiguy@yahoo.com>  2009-07-31 06:11:34 PDT ---
(In reply to comment #20)
> (In reply to comment #18)
> > > It's not going away because MyNiftyPointerTo!(C).getValue is an lvalue.
> > 
> > MyNiftyPointerTo!(C) does not have a function called getValue, it is the return
> > type from getValue
> > 
> 
> Ah, sorry.  I was confused because the meaning of getValue changed and foo was never defined in MyNiftyPointerTo!(T).

Yes, I probably could have made that clearer, but the type was supposed to be a functional replacement for C in that it hooks all calls to the underlying type.

> 
> > > But I'm going to answer the question anyways ...
> > 
> > Incidentally, I can type quite fast and I have never EVER wanted to save keystrokes when it sacrifices clarity.  My protests have nothing to do with saving keystrokes, they have to do with generic code -- writing code that works whether something is a builtin or a custom wrapper type.
> 
> So MyNiftyPointerTo!(T) may grab all of the compile-time reflection info from T and forward all of its functions and such.  Then it becomes a reference to some T, but not a reference in a sense the compiler knows about.

Yes.  That is a good way of explaining it.

> I think I can see now where you're going with this.
> 
> I suppose to really make everyone happy, there would need to be some way to annotate struct definitions and say, "Hey, this thing can be mutated as an rvalue, it's all under control."  That probably doesn't make Walter happy though :(

Due to the nature of the problem, I don't think there's any way to solve it, as it reduces to the halting problem as BCS says.  And limiting it makes the language less powerful than languages that don't forbid it (such as C# and C++).  Without this ability, it will be a sticking point for people who don't want to convert :)  I think we can pick better battles.

However, annotating such structs might be OK.  I am unsure how often this annoyance would surface, so I'm unsure how much annotation is required.  If you have to annotate more than 25% of structs just to get them to work correctly, then I don't think it's worth it.

> 
> Still, without any major change to the language, we can at least forbid the assignment to members of rvalues as BCS suggested in comment #11, correct?

Yes, I think that should solve quite a few mistakes that people often make, such as the Widget/Rectangle error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2 3
Next ›   Last »