From 64d85769dadfbe5f3f456bf079f912ee9d7e54e3 Mon Sep 17 00:00:00 2001
From: Evan Shaw
We believe it's worth trying again with a new language, a concurrent, @@ -49,12 +50,14 @@ concurrent execution and communication. By its design, Go proposes an approach for the construction of system software on multicore machines. +
“Ogle” would be a good name for a Go debugger. +
6
is the architecture letter for amd64 (or x86-64, if you prefer), while
g
stands for Go.
+
@@ -117,6 +120,7 @@ language. Programmers who could were choosing ease over safety and efficiency by moving to dynamically typed languages such as Python and JavaScript rather than C++ or, to a lesser extent, Java.
+Go is an attempt to combine the ease of programming of an interpreted, dynamically typed @@ -131,7 +135,6 @@ and so on. These cannot be addressed well by libraries or tools; a new language was called for.
-@@ -147,7 +150,6 @@ about what programmers do and how to make programming, at least the kind of programming we do, more effective, which means more fun.
-@@ -179,7 +181,6 @@ interfaces represent abstraction; and so on. Orthogonality makes it easier to understand what happens when things combine.
-Yes. There are now several Go programs deployed in +
+Yes. There are now several Go programs deployed in
production inside Google. For instance, the server behind
http://golang.org is a Go program;
in fact it's just the godoc
document server running in a production configuration.
-
+
Gccgo
is a GCC front-end that can, with care, be linked with
GCC-compiled C or C++ programs.
+
The cgo program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries. +
+If it bothers you that Go is missing feature X, please forgive us and investigate the features that Go does have. You might find that they compensate in interesting ways for the lack of X. +
Generics are convenient but they come at a cost in complexity in the type system and run-time. We haven't yet found a @@ -298,6 +308,7 @@ plus the ability to use the empty interface to construct containers (with explicit unboxing) mean in many cases it is possible to write code that does what generics would enable, if less smoothly.
+This remains an open issue.
@@ -311,6 +322,7 @@ convoluted code. It also tends to encourage programmers to label too many ordinary errors, such as failing to open a file, as exceptional. +Go takes a different approach. Instead of exceptions, it has a couple of built-in functions to signal and recover from truly exceptional @@ -319,11 +331,11 @@ function's state being torn down after an error, which is sufficient to handle catastrophe but requires no extra control structures and, when used well, can result in clean error-handling code.
+See the Defer, Panic, and Recover article for details.
-
The same arguments apply to the use of assert()
in test programs. Proper
@@ -348,17 +361,20 @@ answer for 2 and therefore no more tests were run. The programmer who
triggers the test failure may not be familiar with the code that fails.
Time invested writing a good error message now pays off later when the
test breaks.
+
In testing, if the amount of extra code required to write good errors seems repetitive and overwhelming, it might work better as a table-driven test instead. Go has excellent support for data structure literals. +
We understand that this is a point of contention. There are many things in the Go language and libraries that differ from modern practices, simply because we feel it's sometimes worth trying a different approach. +
One of the most successful models for providing high-level linguistic support for concurrency comes from Hoare's Communicating Sequential Processes, or CSP. @@ -392,6 +409,7 @@ The result, which we call goroutines, can be very cheap: unless they spend a lot in long-running system calls, they cost little more than the memory for the stack.
+To make the stacks small, Go's run-time uses segmented stacks. A newly minted goroutine is given a few kilobytes, which is almost always enough. @@ -420,7 +438,6 @@ as when hosting an untrusted program, the implementation could interlock map access.
-Also, the lack of type hierarchy makes “objects” in Go feel much more lightweight than in languages such as C++ or Java. +
The only way to have dynamically dispatched methods is through an interface. Methods on structs or other types are always resolved statically. +
Rather than requiring the programmer to declare ahead of time that two types are related, in Go a type automatically satisfies any interface @@ -469,6 +490,7 @@ or for testing—without annotating the original types. Because there are no explicit relationships between types and interfaces, there is no type hierarchy to manage or discuss.
+
It's possible to use these ideas to construct something analogous to
type-safe Unix pipes. For instance, see how fmt.Fprintf
@@ -479,6 +501,7 @@ stream ciphers. All these ideas stem from a single interface
(io.Writer
) representing a single method
(Write
). And that's only scratching the surface.
It takes some getting used to but this implicit style of type dependency is one of the most exciting things about Go. @@ -503,6 +526,7 @@ but that it could also be confusing and fragile in practice. Matching only by n and requiring consistency in the types was a major simplifying decision in Go's type system.
+Regarding operator overloading, it seems more a convenience than an absolute requirement. Again, things are simpler without it. @@ -574,7 +598,6 @@ the interface idea. Sometimes, though, they're necessary to resolve ambiguities among similar interfaces.
-
A related detail is that, unlike in C, int
and int64
are distinct types even if int
is a 64-bit type. The int
@@ -610,7 +634,6 @@ If a specific application can benefit from a custom implementation, it's possibl
to write one but it will not be as convenient syntactically; this seems a reasonable tradeoff.
@@ -637,7 +660,6 @@ language but they have a large effect on usability: Go became a more productive, comfortable language when they were introduced.
-godoc
implements the full site at
http://golang.org/.
+
gofmt
is a pretty-printer
whose purpose is to enforce layout rules; it replaces the usual
compendium of do's and don'ts that allows interpretation.
All the Go code in the repository has been run through gofmt
.
+
The library sources are in go/src/pkg
.
If you want to make a significant change, please discuss on the mailing list before embarking.
+
See the document Contributing to the Go project for more information about how to proceed. - +
The storage location does have an effect on writing efficient programs. @@ -759,11 +785,13 @@ local to a function in that function's stack frame. However, if the compiler cannot prove that the variable is not referenced after the function returns, then the compiler must allocate the variable on the garbage-collected heap to avoid dangling pointer errors. +
In the current compilers, the analysis is crude: if a variable has its address taken, that variable is allocated on the heap. We are working to improve this analysis so that more data is kept on the stack. +
GOMAXPROCS
should be set on a per-application basis.
-
Gc
is written in C using
Although it's a new program, it fits in the Plan 9 C compiler suite
(http://plan9.bell-labs.com/sys/doc/compiler.html)
and uses a variant of the Plan 9 loader to generate ELF binaries.
+
We considered writing 6g
, the original Go compiler, in Go itself but
@@ -1003,10 +1031,12 @@ set up a Go environment. Gccgo
, which came later, makes it possible
consider writing a compiler in Go, which might well happen. (Go would be a
fine language in which to implement a compiler; a native lexer and
parser are already available in /pkg/go
.)
+
We also considered using LLVM for 6g
but we felt it was too large and
slow to meet our performance goals.
+
gccgo
.
+
5l
, 6l
, and 8l
) only
generate statically linked binaries. All Go binaries therefore include the Go
run-time, along with the run-time type information necessary to support dynamic
type checks, reflection, and even panic-time stack traces.
+
A trivial C "hello, world" program compiled and linked statically using gcc on Linux is around 750 kB. An equivalent Go program is around 1.1 MB, but that includes more powerful run-time support. We believe that with some effort the size of Go binaries can be reduced. +
Some have argued that the lexer should do lookahead to permit the brace to live on the next line. We disagree. Since Go code is meant @@ -1195,6 +1228,7 @@ implement it with low enough overhead and no significant latency. (The current implementation is a plain mark-and-sweep collector but a replacement is in the works.)
+Another point is that a large part of the difficulty of concurrent and multi-threaded programming is memory management; @@ -1205,8 +1239,8 @@ Of course, implementing garbage collection in a concurrent environment is itself a challenge, but meeting it once rather than in every program helps everyone.
+Finally, concurrency aside, garbage collection makes interfaces simpler because they don't need to specify how memory is managed across them.
-