Remix.run Logo
▲ troupo 4 hours ago

> in any, out any

Completely unrelated: can anyone tell me why language authors introduce in/out/inout function parameters (see also C#).

It feels like this is some rather bad workaround for something that breaks assumptions about parameters being passed into the function.

▲hxtk 3 hours ago | parent | next [-]

In Go, it’s a question of who owns the allocation. If you return a pointer type allocated within the function, the answer is “no one,” so the pointer escapes and has to be managed by the garbage collector.

If the allocation is owned by the calling function which uses it internally and then doesn’t return it, it can be a stack variable. Or the same allocation can be reused many times in a loop. Or an array of allocations can be made all at once with foreknowledge of the total number.

▲jayd16 2 hours ago | parent | prev | next [-]

`out` params in C# are params that must be set within the function. They are way to implement multiple return values and tell the caller "this is written to, not read from."

But you might be conflating that with in/out for Contra/Co-variance when specifying a generic.

▲ahmedtd 2 hours ago | parent | prev | next [-]

The parameters named "out" here are not "output parameters" in the way you seem to be thinking. They are "input parameters" named "out", because they are the buffer or pipe you want the data written to.

▲duskwuff 4 hours ago | parent | prev | next [-]

"in" and "out" are the names of the parameters, not qualifiers.

▲CharlieDigital 3 hours ago | parent | prev [-]

C# `out` is kinda nice because it can be `var`d and used directly.

▲troupo 2 hours ago | parent [-]

Erm... what do you mean?