News for hackers. Stuff that matters.
Re:A New Go API for JSON by troupo on Wednesday November 04, 2026 @03:01PM (#50370735)
> 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.

Re:A New Go API for JSON by duskwuff on Wednesday November 04, 2026 @03:51PM (#50371323)
"in" and "out" are the names of the parameters, not qualifiers.
Re:A New Go API for JSON by CharlieDigital on Wednesday November 04, 2026 @04:09PM (#50371560)
C# `out` is kinda nice because it can be `var`d and used directly.
Re:A New Go API for JSON by troupo on Wednesday November 04, 2026 @05:16PM (#50372279)
Erm... what do you mean?
Re:A New Go API for JSON by metaltyphoon on Wednesday November 04, 2026 @07:56PM (#50373617)

  if (int.TryParse(str, out var value) && value == 5)
  {
      // value is available 
  }

   // value also available
Re:A New Go API for JSON by hxtk on Wednesday November 04, 2026 @04:36PM (#50371898)
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.

Re:A New Go API for JSON by throwaway894345 on Wednesday November 04, 2026 @11:20PM (#50375136)
If you pass a pointer into a function, the Go compiler can (and sometimes does) allocate it on the heap. Go has no allocation/ownership semantics, tragically, so the best we can do is depend on undefined behavior regarding the escape analyzer and hope the Go team doesn’t break it (which is a relatively safe assumption, considering that it’s unlikely that the Go team would start allocating things on the heap that were previously allocated on the stack—Go rarely regresses performance like this).
Re:A New Go API for JSON by ahmedtd on Wednesday November 04, 2026 @05:34PM (#50372436)
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.
Re:A New Go API for JSON by jayd16 on Wednesday November 04, 2026 @05:40PM (#50372493)
`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.

Re:A New Go API for JSON by metaltyphoon on Wednesday November 04, 2026 @07:54PM (#50373600)
> They are way to implement multiple return values

They are one way to implement multiple return values. For multiple returns, tuples can be used.