Suppose you have to write a program in C, but you prefer to think in Go (or CSP). What libraries, tools, and techniques would you use to make your C development experience more Go-like?
If you want to limit the discussion to CSP, you should check out libtask. It’s a pretty simple drop-in library for coroutines by Russ Cox and released around 2005. There’s a lot of similarities between the prime sieve example (coros communicate over buffered channels!) and how you might write it in Go.
You can take a look at Plan 9/Inferno coding guidelines and internals. That’s something looking very close to Go. There is some good things in C11 as well.
One thing I really like about Go coming from C was the “defer” statement, which is very useful for making sure resources get cleaned up at exit. Sadly, there doesn’t seem to be any complete analogue to this in C, but there is the atexit standard library function which can register function pointers to be run when the whole process exits. Useful for cleaning up global state.
The RAII pattern is common in C++ if that’s an acceptable jump.
Seems relevant: design doc for implementation of Go channels in C:
It’s a step towards a “libchannel”…