News for hackers. Stuff that matters.
Re:Learn Go in five minutes by 37ef_ced3 on Tuesday January 05, 2021 @12:01PM (#25647610)
Take Go's slices, for example

Realize a Go []int ("slice of int") is just a C struct like this, passed by value:

  struct intSlice {
      int* addr;
      int len;
      int cap;
  };
The memory at addr is not owned by the slice. All the slice operations are simply notation for manipulating the struct. Go's garbage collection makes the whole thing work well

This can be confusing if you're used to C++'s std::vector (which owns the memory) or Python's slices. Go's slices are a shallow pointer/length system exactly like is used in C all the time. For example:

  void sort(int* addr, int len);
becomes

  func sort(a []int)
A Go slice is just a formalization of C's pointer/length idiom, with terse notation for manipulation
Re:Learn Go in five minutes by traes on Tuesday January 05, 2021 @12:19PM (#25647861)
I'm not really sure saying that features in Go can be modeled in C really suggests that they are similar as languages. Syntax is very important.
Re:Learn Go in five minutes by nyanpasu64 on Tuesday January 05, 2021 @12:28PM (#25648028)
Go's slices don't act like what I thought were called "non-owning references"(Rust's &/&mut [T] or C++'s std::span<T/T const>), which reference memory whose lifetime is bounded by something else (like a vector or array or shared pointer). Instead it's "shared ownership" where memory is referenced by one or more slices (and no single owner) which can reference and mutate the slice simultaneously, and it's freed by the GC sometime after all the slices are gone.

This reminds me of Numpy's ndarrays, which act more like "owning containers" (which may sometimes share ownership and alias) than "non-owning references".

Re:Learn Go in five minutes by erik_seaberg on Tuesday January 05, 2021 @03:51PM (#25650842)
Slices are kind of a mess. They should either be uniqueness types or passed by reference (the way maps and channels are, and NIO buffers from Java). Instead they’re passed by value so multiple copies exist whose sizes and sometimes contents aren’t in sync.
Re:Learn Go in five minutes by mhh__ on Tuesday January 05, 2021 @12:39PM (#25648235)
Slices should be the absolute bare minimum for a modern systems language, it's not really a reason to switch in my case

If I want to write flat/simple code I'll just C, Go doesn't really offer anything to me because I want to be relatively low-level and able to make the compiler save my time.