On 2009-12-14 07:01:47 -0800, dsimcha <dsim...@yahoo.com> said:
== Quote from lws (inva...@email.com)'s article
I don't know if I believe this is necesarrily bad. It's revealing some
bad coding on your part.
You shouldn't be doing opEquals with an rvalue of a class. Make
getFoo return a reference.
ref Foo getFoo() {} fixes the problem and avoids value-copying for no
reason to an rvalue that's going to get garbage collected.
1. This was in DFL's code, not stuff I wrote.
2. It was a small struct that was cheap to copy, not a class.
3. At any rate, the inconsistency with builtins is inexcusable.
1. Well, stuff like this is good warning to whomever about the code.
Since D is a imperative language, it should at least give you a warning
when you're doing something really inefficient that has a boilerplate
way of accomplishing it that is much faster.
2. That's odd. structs DO have stack scope in D. Right? It
shouldn't even warn in that case. IMHO.
3. For classes, it is consistent with the whole point of the new const
stuff and the GC, and the fact that they are heap objects by
definition. Classes have always been treated "differently." And I
think it's good. Walter has enabled a lot of expressiveness with the
syntax in D when compared to C++, and it allows nice warnings when
you're doing things you probably shouldn't.
Unfortunately, this isn't an error.... Maybe for some reason you
REALLY want to be copying around structs and classes.