On Sunday, 29 April 2012 at 19:30:24 UTC, Nick Sabalausky wrote:
"deadalnix" <deadal...@gmail.com> wrote in message
news:jnhopd$gi3$1...@digitalmars.com...
- out arguments. We can return tuples, out argument is going
backward in history.
You can overload on out parameters. You can't overload on
return type. So
without "out" making an optional output param would be harder
to make and
uglier to use. That could be even more of a problem if the out
param in
question is expensive to compute.
Also, out is nice when interfacing with C. Returning tuples
wouldn't help
here.
I do agree that maybe we should *prefer* returning tuples over
out params
(at least once we kill off the useless comma operator and have
a concise
built-in syntax for tuples), but I don't think tuples are
enough to replace
out entirely.
Well the functional way would be to use Option types as in:
Tuple!(int, Option!ExpensiveType) foobar(bool cond) {
if (cond) return tuple(0, newExpensiveType());
else return tuple(-1, Option.None);
}
I prefer the above as it's more readable IMO (we REALLY should
get a much better tuple syntax though ....)
I do agree that this won't work when interfacing with C but IMO
we shouldn't design D around limitations of C.