4 ms·
> Go is closer in spirit to C than to any other language This is certainly not the case for the way that I personally think about C. Perhaps there are two "sp
by haberman 14y ago
> Go is closer in spirit to C than to any other language
This is certainly not the case for the way that I personally think about C. Perhaps there are two "spirits" of C; two ways that people think about it:
1. C is small, C is simple, C lets you write useful programs with good performance while keeping the language itself simple. For this view of C, I can see Go being a compelling alternative.
2. C is a bare-metal environment for implementing low-level systems code like VMs, garbage collectors, JITs, and other runtimes. It imposes nothing and never gets in your way. For this view of C (which is how I think of it), Go is not an alternative. If you are inclined to disagree, answer for me: why is the Go runtime and GC not itself written in Go?
I think that perhaps the difference between these two views of C leads to some of the disagreement about whether Go is an alternative for C.
- jbarham 14y ago> why is the Go runtime and GC not itself written in Go? In a word: bootstrapping. It's a FAQ: http://golang.org/doc/faq#What_compiler_technology_is_used_to_build_the_compilers http://golang.org/doc/faq#What_compiler_technology_is_used_t...
- pcwalton 14y agoI don't see how to easily implement a garbage collector in a language that doesn't let you precisely control garbage collected allocations (i.e. making all GC allocations immediately apparent and visible, instead of using escape analysis), for the same heap you're allocating into. You'd have to reason very carefully about the colors of your objects in order to ensure correctness in the presence of allocating into the same heap you're in the process of marking or sweeping or copying. (This is not the same problem as incremental collection—with incremental collection you can count on barriers to handle it for you.) I wouldn't be surprised if it's doable with some really clever tricks, but it doesn't seem worth it in terms of maintainability. Just use C or C++.
- tikhonj 14y agoOr, one day, Rust :P. Or does Rust's optional GC get in the way? I'm not really familiar with that part of the language.
- steveklabnik 14y agoRust is written in Rust. (The compiler currently makes heavy use of `unsafe`, in my understanding. At least for now.)
- yoklov 14y agoNot an expert, but my understanding was that most of those were either from bindings to unsafe functions (e.g. C++ functions from LLVM) or false positives from the compiler dealing with the 'unsafe' keyword in the code its compiling.
- kibwen 14y agoIt's increasingly possible to write Rust code without needing the runtime at all; this is what's enabling the current effort to rewrite the runtime from C++ to Rust itself. However, there are some restrictions imposed if you choose to shed the runtime: no use of garbage-collected pointers, and concurrency will be either unavailable or somewhat restricted (i.e. mapping tasks to OS threads rather than green threads). https://github.com/mozilla/rust/issues/3608 https://github.com/mozilla/rust/issues/3608 Writing the Go runtime in Go would require the similar ability to do without all the services that are currently provided by the runtime. That is, unless you want your runtime to recursively require itself to infinite depth. :) I'm sure it's theoretically possible, but considering that two of the language's largest selling points are concurrency and memory safety via GC, a theoretical runtime-less dialect of Go would be so near to C that it might not really be worth the effort.
- pjmlp 14y agoOberon's GC is written in Oberon in some implementations and Assembly in others, but the SYSTEM package is more powerful in low level primitives than what Go offers in its unsafe package. Edit: Forgot to mention that it does not do escape analysis.
- qznc 14y agoThe C philosophy is captured in http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10... "Some of the facets of the spirit of C can be summarized in phrases like: • Trust the programmer. • Don’t prevent the programmer from doing what needs to be done. • Keep the language small and simple. • Provide only one way to do an operation. • Make it fast, even if it is not guaranteed to be portable. "
- pjmlp 14y ago- Make it easy to write buffer exploits