xxxInPlace or xxxCopy?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Jan 20 04:02:36 PST 2011
On Thursday 20 January 2011 03:51:48 Trass3r wrote:
> If such an annotation was introduced, it should be the other way around.
> But imo discarding a return value should always result in a warning,
> the function returns something for a reason.
Actually, there are plenty of cases where you throw away the return value. A
number of overloaded operators are prime examples - such as opAssign.
std.algorithm.sort both sorts in place _and_ returns a sorted range (so that
other algorithms can then know that the range is sorted). It's really quite easy
to get legitimate cases where throwing away the return value makes perfect
sense. Now, if you're dealing with a strongly pure function which throws away
its return value, then yes, that's definitely bug, since the only effect of the
function is its return value. Frequently however, that's not the case.
Yes, you can have bugs because you didn't actually use the return value of a
function, but it's that necessarily uncommon to have function calls which
legitimately throw away their return value.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list