News for hackers. Stuff that matters.
Re:Hooking Go from Rust by aviramha on Friday August 26, 2022 @11:08AM (#32608511)
Hey, One of the writers of the article here. This is a very controversial topic in Go ecosystem, and following all the discussions that led to this decision is very hard. In short, I think main reasons are:

1. libc is considered hazard - security, comfort, runtime. It needs to maintain support for so many flows and setups so it's hard to make things better. For example, having `errno` as a global is quite weird (instead of just returning it, which is a whole discussion of it's own)

2. Golang devs like to re-invent the wheel, in a kind of Apple-ish way - all other are doing it wrong, we're going to do it better. ofc it's debatable whether they're correct with their approach.

3. Given they use Plan 9 system design, doing FFI from Go is very expensive (need to switch stack, save context, etc on each call)

Re:Hooking Go from Rust by tialaramex on Friday August 26, 2022 @11:50AM (#32609008)
> For example, having `errno` as a global is quite weird

It was quite weird before we wrote concurrent software. Once you're writing concurrent software it's very weird because as originally documented this single error location is shared by all threads, so it necessarily gets concurrently modified while being read, a Data Race.

Your 2022 C library typically defines it as Thread Local instead, so when you call some_c_function() and then check errno, you aren't confused by the fact meanwhile another thread tried to open("nonexistent.file") and so their thread set errno to report that the file doesn't exist.

Given that none of this fuss is how the actual system calls work, it's understandable that people might want to sidestep it.

Re:Hooking Go from Rust by aviramha on Friday August 26, 2022 @11:56AM (#32609082)
Thanks for elaborating! I totally agree there's valid reasons to drop libc, though not sure if that's the right way. In most modern languages today you can just return a tuple, not needing to mess with TLS.. whereas old times didn't really like passing results in out parameters (by ref) (which makes sense, it's less ergonomic).
Re:Hooking Go from Rust by throwaway894345 on Friday August 26, 2022 @02:08PM (#32610828)
I much prefer the ergonomics of passing out-parameters than TLS. Honestly, TLS has always struck me as a code smell in any language.
Re:Hooking Go from Rust by throwaway894345 on Friday August 26, 2022 @02:07PM (#32610805)
> Golang devs like to re-invent the wheel, in a kind of Apple-ish way - all other are doing it wrong, we're going to do it better. ofc it's debatable whether they're correct with their approach.

I'm very happy with these tradeoffs. Not only is it a pleasure not to have to deal with libc (truly static binaries on Linux, 2mb docker images, etc), but because interop is tedious/expensive, the ecosystem is largely pure-Go. This means that we rarely (if ever) have to deal with C's abysmal build tooling and (lack of) package managers and stuff like cross compilation is trivial. Everything builds consistently on every system, every time, and irrespective of target platform (provided there are no C dependencies).

Re:Hooking Go from Rust by aviramha on Friday August 26, 2022 @02:14PM (#32610888)
My concern here is that many people are now writing software in Go which can only be used from Go. Yes, you can cgo but as you wrote the interop is tedious/expensive. It’s good we’re rewriting old software but this time in a semi closed garden…
Re:Hooking Go from Rust by throwaway894345 on Friday August 26, 2022 @03:28PM (#32611712)
I mean, the garden has always been semi-closed, we've never had a truly open garden, and nothing Go did was going to change that. In other words, what language has ever solved the problem of cross-language-reuse in a way that was so simple that we didn't end up rewriting a huge swath of the ecosystem in every new language? It's not like Java or Rust came along and now we can stop rewriting HTTP libraries in subsequent languages.

Easy interop has only ever been an illusion (we forget about the difficulties of integrating distinct build systems and memory management systems or the runtime costs of marshaling data between memory layouts). Rather than paying significant costs to preserve that illusion, Go doubled down in order to realize some pretty considerable gains: easy compilation even on niche distros, even when cross compiling, truly static binaries, etc.

Re:Hooking Go from Rust by aviramha on Friday August 26, 2022 @03:37PM (#32611822)
We’re sliding into opinions but using C, Python, Rust in each interop had some cost but I did it and got a lot of benefits of using existing good software. Yes C lacks dev ergonomics, but meson + ninja gave a very neat experience..
Re:Hooking Go from Rust by throwaway894345 on Friday August 26, 2022 @03:57PM (#32612041)
> using C, Python, Rust in each interop had some cost but I did it and got a lot of benefits of using existing good software

I don't dispute this, but that is still a niche case. The general case is that library software gets rewritten in each language (and if it's not worth the trouble to rewrite it, it's usually not worth the trouble to use and maintain bindings). So yes, there is a tradeoff, I'm just expressing my opinion that Go made the better tradeoff, at least for a garbage collected language (since you mentioned it, Python trades off a boatload of performance and package management simplicity in its pursuit of easy C interop).

> Yes C lacks dev ergonomics, but meson + ninja gave a very neat experience..

My point about abysmal C build/package tooling wasn't about the experience of a C developer, but the experience of someone who is downstream of C packages. As a Python developer, I don't get to choose how my C dependencies are packaged for Python (which build system and package manager they use)--I'm just at the mercy of whatever they offer, and if I'm targeting some non-mainstream Linux distro, then there's a good chance some build or runtime dependency of some upstream C project is going to fail, and now I need to grok that C project's build/linking system to sort it out. This just doesn't happen in (pure) Go because Go's build system and package manager are reproducible (no implicit dependencies).

Re:Hooking Go from Rust by aviramha on Friday August 26, 2022 @04:14PM (#32612229)
Fair point.
Re:Hooking Go from Rust by infiniteregrets on Friday August 26, 2022 @11:10AM (#32608538)
Re:Hooking Go from Rust by metadat on Friday August 26, 2022 @11:18AM (#32608636)
^ (Go 1.16 will make system calls through Libc on OpenBSD)