One document about Go

Jonathan M Davis jmdavisProg at gmail.com
Tue Jun 1 15:28:38 PDT 2010


bearophile wrote:

> Walter Bright:
>> > Out parameters are initialized at function entry, so in theory all is
>> > good and there are no bugs, but this is a *workaround*, a language
>> > kludge, a hack, something dirty that is done because of language
>> > limitation, or to keep the language compatible with an ancient C
>> > design, or because the design is old.
>> 
>> I don't agree. For one thing, C and C++ do not even have out parameters.
> 
> In C and C++ you use pointers and & arguments to perform the same thing,
> in an even less safe way (they don't get initialized). But if you think
> that "out arguments" aren't something logically backwards, something that
> looks like a hack that is present just to work around some kind of
> language/compiler/design/brain limit, then there is something profoundly
> different in how our brains are designed :-) For me function arguments are
> something that goes in a function, and the results are something that
> comes out. In a real language there can be exceptions to this (like ref
> return values of D2), but I have always assumed out arguments are just a
> kind of hack done because of some compiler limit, I have never thought of
> them as something "nice" or safe, or logically good.
> 
> Bye,
> bearophile

There are definitely times that I'd like multiple return values. It would be 
a great feature to have - though doing it with a tuple type or something 
similar works well enough for the most part.

However, there are cases where you really want the function to be returning 
a single value - particularly when you're feeding the result into an 
expression - and it's nice to be able to still get other values out of the 
function with out or ref parameters.

Which is better depends in part on how your mind works and in part on what 
you're actually trying to do.

- Jonathan M Davis


More information about the Digitalmars-d mailing list