From 5b79202ca21a0de8336283bdaee58a312e539ce4 Mon Sep 17 00:00:00 2001
From: Rob Pike
-Go is an attempt to combine the ease of programming of the dynamic -languages with the efficiency and type safety of a compiled language. +Go is an attempt to combine the ease of programming of a dynamic +language with the efficiency and type safety of a compiled language. It also aims to be modern, with support for networked and multicore computing. Finally, it is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. @@ -124,6 +124,31 @@ Cox joined later and helped move the language and libraries from prototype to reality.
++Programming today involves too much bookkeeping, repetition, and +clerical work. As Dick Gabriel says, “Old programs read +like quiet conversations between a well-spoken research worker and a +well-studied mechanical colleague, not as a debate with a compiler. +Who'd have guessed sophistication bought such noise?” +The sophistication is worthwhile—no one wants to go back to +the old languages—but can it be more quietly achieved? +
+
+Go attempts to reduce the amount of typing in both senses of the word.
+Throughout its design, we have tried to reduce the clutter and
+complexity. There are no forward declarations and no header files;
+everything is declared exactly once. Initialization is expressive,
+automatic, and easy to use. Syntax is clean and light on keywords.
+Stuttering (foo.Foo* myFoo = new(foo.Foo)
) is reduced by
+simple type derivation using the :=
+declare-and-initialize construct. And perhaps most radically, there
+is no type hierarchy: types just are, they don't have to
+announce their relationships. These simplifications allow Go to be
+expressive yet comprehensible without sacrificing, well, sophistication.
+
+Object-oriented programming, at least in the languages we've used, +involves too much discussion of the relationships between types, +relationships that often could be derived automatically. Go takes a +different approach that we're still learning about but that feels +useful and powerful. +
++Rather than requiring the programmer to declare ahead of time that two +types are related, in Go a type automatically satisfies any interface +that specifies a subset of its methods. Besides reducing the +bookkeeping, this approach has real advantages. Types can satisfy +many interfaces at once, without the complexities of traditional +multiple inheritance. +Interfaces can be very lightweight—one or even zero methods +in an interface can express useful concepts. +Interfaces can be added after the fact if a new idea comes along +or for testing—without annotating the original type. +Because there are no explicit relationships between types +and interfaces, there is no type hierarchy to manage. +
+
+It's possible to use these ideas to construct something analogous to
+type-safe Unix pipes. For instance, see how fmt.Fprintf
+enables formatted printing to any output, not just a file, or how the
+bufio
package can be completely separate from file I/O,
+or how the crypto
packages stitch together block and
+stream ciphers. All these ideas stem from a single interface
+(io.Writer
) representing a single method
+(Write
). We've only scratched the surface.
+
+It takes some getting used to but this implicit style of type +dependency is one of the most exciting things about Go. +
+ +len
a function and not a method?
+To be blunt, Go isn't that kind of language. We debated this issue but decided
+implementing len
and friends as functions was fine in practice and
+didn't complicate questions about the interface (in the Go type sense)
+of basic types. The issue didn't seem important enough to resolve that way.
+
+Method dispatch is simplified if it doesn't need to do type matching as well. +Experience with other languages told us that having a variety of +methods with the same name but different signatures was occasionally useful +but that it could also be confusing and fragile in practice. Matching only by name +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. +
+ ++The same reason strings are: they are such a powerful and important data +structure that providing one excellent implementation with syntactic support +makes programming more pleasant. We believe that Go's implementation of maps +is strong enough that it will serve for the vast majority of uses. +If a specific application can benefit from a custom implementation, it's possible +to write one but it will not be as convenient to use; this seems a reasonable tradeoff. +
+ + ++Map lookup requires an equality operator, which structs and arrays do not implement. +They don't implement equality because equality is not well defined on such types; +there are multiple considerations involving shallow vs. deep comparison, pointer vs. +value comparison, how to deal with recursive structures, and so on. +We may revisit this issue—and implementing equality for structs and arrays +will not invalidate any existing programs—but without a clear idea of what +equality of structs and arrays should mean, it was simpler to leave it out for now. +
+TODO:
-Why does Go not have: -- macros? -- conditional compilation? - -What do you have planned? -- variant types? - explain: package design slices @@ -290,24 +402,19 @@ why garbage collection? -no data in interfaces - -concurrency questions: - goroutine design - why csp inheritance? embedding? dependency declarations in the language oo questions + no data in interfaces dynamic dispatch clean separation of interface and implementation why no automatic numeric conversions? make vs new -Why do maps only work on builtin types?-- 2.48.1