by luriel · 14y ago · 0 comments
The amount of complexity in a modern libc, glibc in particular, is mind-boggling.
One thing I love about Go is that it completely bypasses even libc, the Go runtime and stdlib use syscalls directly(well, except on Windows, for obvious reasons), in a way a Go program is "closer to the metal" than a C program.
It's amusing how often people try to one-up C with their favorite language, and how these attempts are almost never successful.
You can write C that doesn't use libc, that has no access to any system services, or indeed that runs under no operating system at all. For example, an operating system kernel itself. In no way is a Go program "closer to the metal" than a C program.
Also note that Go can do all the things you mention, including writing a kernel.
Just to be clear, the real issue with C is not the language so much as the horrible libraries that have been built over decades of clumsily piling up complexity.
And the people who suggest glib is the answer to C's library needs are scary and depressing, glib just adds another layer of (very unportable!) crud on top of libc for no real gain other than keeping people from learning how to properly write C (data structures in particular).
Though you probably didn't mean "standard" literally, writing C programs that have no access to the standard library is explicitly mentioned in the standard, which calls this a "freestanding implementation."
> Also note that Go can do all the things you mention, including writing a kernel.
You can't write memory management code in a language that provides automatic memory management. You just can't. And while I can believe that people who like Go are experimenting with using Go for most of an OS kernel (with a C kernel underneath it to handle things like memory management and probably interrupts), it's not the same as C where the whole kernel can be in C with the exception of highly hardware-specific code (booting, context switching code, syscall gates, etc). Aside from that, I don't think the performance of GC will ever be acceptable for a high-performance kernel.
> Just to be clear, the real issue with C is not the language so much as the horrible libraries that have been built over decades of clumsily piling up complexity.
Wait, now C is bad because some people wrote some bad libraries for it? Then don't use those libraries? No one's forcing you to use glib.
Google Go uses syscalls directly because its threads ("goroutines") were designed for a 32-bit architecture so their solution to not running out of virtual address space was to use small stacks that can grow. But that means it can't just call normal C function directly because there may not be enough stack, so they have to reinvent libc on every platform they port to. Meanwhile virtually every desktop is 64-bit and even ARMs will soon be 64-bit.
Why design a new language around 32-bit computers? Good question.
Thread count vs stack space is a well-known tradeoff in 32-bit. It doesn't take a rocket scientist to know this is the reason for segmented stacks in Google Go even if there's no smoking gun (wayback didn't archive the golang site for a long time due to a misconfigured robots.txt).
Note that another cool thing we can do is to statically link clang-compiled C code with Rust code and LLVM can inline your small C functions directly into your Rust functions and save you the stack switch -- this is one of the coolest things we can do with LLVM, IMHO.
If you inline a compiled C function, don't you have to do the stack switching for whatever that inlined function might call? Or do you only inline code that doesn't have any function calls?
That might be ok for Rust where many 'tasks' might be computational only and never call a C function. But with Google Go, I think they said "we want to have a million threads each reading a socket" or some other arbitrary limit which isn't possible in 32-bit using system threads (even with segmented stack).
Does Rust do it's own threading, and if so what are the advantages you perceive to doing so?
http://golang.org/doc/go_faq.html#goroutines
When they say "system resources" they mean stack space. It's limited in 32-bit because a stack large enough to be useful takes up too many virtual address space. For instance an 8 MiB stack takes up 1/512 of the 32-bit address space so you can only have max 512 threads, but in 64-bit you can have 33 million (current CPUs limited to 2^48 address space)
So they segment the stack in Google Go to get more than some small number of threads. Even though Linux (edit: the kernel) only uses 4k or 8k per thread some OSes have severe limits, so they compound the segmented stack problem (making C interop slow and cumbersome) with userspace threading (M:N). A collection of links why that's a bad idea:
http://www.kegel.com/c10k.html#1:1
Eventually they'll concede that this wasn't a good idea, but I wouldn't bet on when.
EDIT: My memory was almost correct, he said that (in sharp contrast to C++) he can imagine letting Go into the kernel but not for a long time. http://www.realworldtech.com/beta/forums/index.cfm?action=de...
EDIT2: s/Linux/Linus/
In answer to that last paragraph, someone asked about Go, which is where you got Linus's overall noncommittal answer.
[1] http://www.realworldtech.com/beta/forums/index.cfm?action=de...
Go is a perfectly fine language for kernel mode development, I am aware of at least three efforts of writing an operating system in Go (one such effort being mine).
I do agree though that Go is not the right language to use in conjunction with the rest of the Linux kernel. While Go used for a kernel is perfectly fine, it forces you towards some design decisions and constraints that do not exist in the Linux kernel as it stands today.
However I don't think anybody is really marketing Go for that niche.
Today, "systems programming" is more taken to mean "kernel programming", and I don't get the sense that is what was meant by the senior authors of go.
http://en.wikipedia.org/wiki/System_programming
Last time I looked, inside of the Go libraries which had to do some tricky things there was some C code, meaning that even Go authors weren't able to write everything in Go. So Go can't be a substitute for C, and as long as most of the system programming is done in C, no go for Go.
Choose the greatest impediment and cite it as a primary goal.
It is already well equipped to write distributed network servers, web servers, message queue servers and such.
Anyway, "systems" in this case includes daemons and server processes. I'll update with a reference if I can find it in the Go context.
For that sense of "systems", Go excels and Java enjoys a great deal of popularity.
Based on that, I don't think I'd rule out the feasibility of doing a missile guidance system in a GC language.
Not obvious to me. Please elucidate.