Rob Pike | 6898f95 | 2009-11-09 23:54:35 -0800 | [diff] [blame] | 1 | <!-- FAQ --> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 2 | |
| 3 | <h2 id="Origins">Origins</h2> |
| 4 | |
| 5 | <h3 id="What_is_the_purpose_of_the_project"> |
| 6 | What is the purpose of the project?</h3> |
| 7 | |
| 8 | <p> |
| 9 | No major systems language has emerged in over a decade, but over that time |
| 10 | the computing landscape has changed tremendously. There are several trends: |
| 11 | |
| 12 | <ul> |
| 13 | <li> |
| 14 | Computers are enormously quicker but software development is not faster. |
| 15 | <li> |
| 16 | Dependency management is a big part of software development today but the |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 17 | “header files” of languages in the C tradition are antithetical to clean |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 18 | dependency analysis—and fast compilation. |
| 19 | <li> |
| 20 | There is a growing rebellion against cumbersome type systems like those of |
| 21 | Java and C++, pushing people towards dynamically typed languages such as |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 22 | Python and JavaScript. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 23 | <li> |
| 24 | Some fundamental concepts such as garbage collection and parallel computation |
| 25 | are not well supported by popular systems languages. |
| 26 | <li> |
| 27 | The emergence of multicore computers has generated worry and confusion. |
| 28 | </ul> |
| 29 | |
| 30 | <p> |
| 31 | We believe it's worth trying again with a new language, a concurrent, |
| 32 | garbage-collected language with fast compilation. Regarding the points above: |
| 33 | |
| 34 | <ul> |
| 35 | <li> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 36 | It is possible to compile a large Go program in a few seconds on a single computer. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 37 | <li> |
| 38 | Go provides a model for software construction that makes dependency |
| 39 | analysis easy and avoids much of the overhead of C-style include files and |
| 40 | libraries. |
| 41 | <li> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 42 | Go's type system has no hierarchy, so no time is spent defining the |
| 43 | relationships between types. Also, although Go has static types the language |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 44 | attempts to make types feel lighter weight than in typical OO languages. |
| 45 | <li> |
| 46 | Go is fully garbage-collected and provides fundamental support for |
| 47 | concurrent execution and communication. |
| 48 | <li> |
| 49 | By its design, Go proposes an approach for the construction of system |
| 50 | software on multicore machines. |
| 51 | </ul> |
| 52 | |
| 53 | <h3 id="What_is_the_origin_of_the_name"> |
| 54 | What is the origin of the name?</h3> |
| 55 | |
| 56 | <p> |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 57 | “Ogle” would be a good name for a Go debugger. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 58 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 59 | <h3 id="What_kind_of_a_name_is_6g"> |
| 60 | What kind of a name is 6g?</h3> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 61 | |
| 62 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 63 | The <code>6g</code> (and <code>8g</code> and <code>5g</code>) compiler is named in the |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 64 | tradition of the Plan 9 C compilers, described in |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 65 | <a href="http://plan9.bell-labs.com/sys/doc/compiler.html"> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 66 | http://plan9.bell-labs.com/sys/doc/compiler.html</a> |
| 67 | (see the table in section 2). |
| 68 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 69 | <code>6</code> is the architecture letter for amd64 (or x86-64, if you prefer), while |
| 70 | <code>g</code> stands for Go. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 71 | |
| 72 | <h3 id="Why_not_just_write_some_libraries_for_Cpp_to_do_communication"> |
| 73 | Why not just write some libraries for C++ to do communication?</h3> |
| 74 | |
| 75 | <p>We considered doing that, but too many of the problems—lack of |
| 76 | garbage collection, long dependency chains, nested include files, |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 77 | lack of concurrency awareness—are rooted in the design of |
| 78 | the C and C++ languages themselves. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 79 | We felt a viable solution required a more complete approach. |
| 80 | |
Rob Pike | d8134e7 | 2009-11-11 11:44:27 -0800 | [diff] [blame] | 81 | <h3 id="Why_doesnt_Go_run_on_Windows"> |
| 82 | Why doesn't Go run on Windows?</h3> |
| 83 | |
| 84 | <p> |
| 85 | We understand that a significant fraction of computers in the world |
| 86 | run Windows and it would be great if those computers could run Go |
| 87 | programs. However, the Go team is small and we don't have the |
| 88 | resources to do a Windows port at the moment. We would be |
| 89 | more than willing to answer questions and offer advice to anyone |
| 90 | willing to develop a Windows version. |
| 91 | </p> |
| 92 | |
Rob Pike | bdecae9 | 2009-11-23 17:34:23 -0800 | [diff] [blame] | 93 | <h3 id="Whats_the_origin_of_the_mascot"> |
| 94 | What's the origin of the mascot?</h3> |
| 95 | |
| 96 | <p> |
| 97 | The mascot and logo were designed by |
| 98 | <a href="http://reneefrench.blogspot.com">Renée French</a>, who also designed |
| 99 | <a href="http://plan9.bell-labs.com/plan9/glenda.html">Glenda</a>, |
| 100 | the Plan 9 bunny. |
| 101 | The gopher is derived from one she used for an <a href="http://wfmu.org/">WFMU</a> |
| 102 | T-shirt design some years ago. |
| 103 | The logo and mascot are covered by the |
| 104 | <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> |
| 105 | license. |
| 106 | </p> |
| 107 | |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 108 | <h2 id="Usage">Usage</h2> |
| 109 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 110 | <h3 id="Who_should_use_the_language"> |
| 111 | Who should use the language?</h3> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 112 | |
| 113 | <p> |
| 114 | Go is an experiment. We hope adventurous users will give it a try and see |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 115 | if they enjoy it. Not every programmer |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 116 | will, but we hope enough will find satisfaction in the approach it |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 117 | offers to justify further development. |
| 118 | |
Rob Pike | 7685a67 | 2009-11-09 20:25:45 -0800 | [diff] [blame] | 119 | <h3 id="Is_Google_using_go_internally"> Is Google using Go |
| 120 | internally?</h3> |
| 121 | |
| 122 | <p> The Go project was conceived to make it easier to write the kind |
| 123 | of servers and other software Google uses internally, but the |
| 124 | implementation isn't quite mature enough yet for large-scale |
| 125 | production use. While we continue development we are also doing |
| 126 | experiments with the language as a candidate server environment. It's |
| 127 | getting there. For instance, the server behind <a |
| 128 | href="http://golang.org">http://golang.org</a> is a Go program; in |
| 129 | fact it's just the <a href="/cmd/godoc"><code>godoc</code></a> document server running in a |
| 130 | production configuration. |
| 131 | |
| 132 | |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 133 | <h3 id="Do_Go_programs_link_with_Cpp_programs"> |
| 134 | Do Go programs link with C/C++ programs?</h3> |
| 135 | |
| 136 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 137 | There are two Go compiler implementations, <code>6g</code> and friends, generically called |
| 138 | <code>gc</code>, and <code>gccgo</code>. |
| 139 | <code>Gc</code> uses a different calling convention and linker and can |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 140 | therefore only be linked with C programs using the same convention. |
| 141 | There is such a C compiler but no C++ compiler. <code>Gccgo</code> is a |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 142 | GCC front-end that can, with care, be linked with GCC-compiled |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 143 | C or C++ programs. However, because Go is garbage-collected it will be |
| 144 | unwise to do so, at least naively. |
| 145 | |
| 146 | <p> |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 147 | There is a “foreign function interface” to allow safe calling of C-written |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 148 | libraries from Go code. We expect to use SWIG to extend this capability |
| 149 | to C++ libraries. There is no safe way to call Go code from C or C++ yet. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 150 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 151 | <h3 id="Does_Go_support_Google_protocol_buffers"> |
| 152 | Does Go support Google's protocol buffers?</h3> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 153 | |
| 154 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 155 | Protocol buffers are supported. We plan to have the next release of the |
| 156 | protocol buffer source code include Go code generators |
| 157 | and a Go library for them. The implementation uses data reflection |
| 158 | at run time so it is slow, but a new implementation is planned. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 159 | |
Russ Cox | 6301fb4 | 2009-12-03 17:23:33 -0800 | [diff] [blame^] | 160 | <h3 id="Can_I_translate_the_Go_home_page"> |
| 161 | Can I translate the Go home page into another language?</h3> |
| 162 | |
| 163 | <p> |
| 164 | Absolutely. We encourage developers to make Go Language sites in their own languages. |
| 165 | However, if choose to add the Google logo or branding to your site |
| 166 | (it does not appear on <a href="http://golang.org/">golang.org</a>), |
| 167 | you will need to abide by the guidelines at |
| 168 | <a href="http://www.google.com/permissions/guidelines.html">http://www.google.com/permissions/guidelines.html</a> |
| 169 | </p> |
| 170 | |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 171 | <h2 id="Design">Design</h2> |
| 172 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 173 | <h3 id="Why_doesnt_Go_have_feature_X">Why doesn't Go have feature X?</h3> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 174 | |
| 175 | <p> |
| 176 | Every language contains novel features and omits someone's favorite |
| 177 | feature. Go was designed with an eye on felicity of programming, speed of |
| 178 | compilation, orthogonality of concepts, and the need to support features |
| 179 | such as concurrency and garbage collection. Your favorite feature may be |
| 180 | missing because it doesn't fit, because it affects compilation speed or |
| 181 | clarity of design, or because it would make the fundamental system model |
| 182 | too difficult. |
| 183 | |
| 184 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 185 | If it bothers you that Go is missing feature <var>X</var>, |
| 186 | please forgive us and investigate the features that Go does have. You might find that |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 187 | they compensate in interesting ways for the lack of <var>X</var>. |
| 188 | |
| 189 | <h3 id="Why_is_the_syntax_so_different_from_Cpp"> |
| 190 | Why is the syntax so different from C++?</h3> |
| 191 | |
| 192 | <p> |
| 193 | This and other language design questions are answered in |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 194 | the separate <a href="go_lang_faq.html">language design FAQ</a>. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 195 | |
| 196 | <h2 id="Object_Oriented_Programming"> |
| 197 | Object-Oriented Programming</h2> |
| 198 | |
| 199 | <h3 id="Is_Go_an_object-oriented_language"> |
| 200 | Is Go an object-oriented language?</h3> |
| 201 | |
| 202 | <p> |
| 203 | Yes and no. Although Go has types and methods and allows an |
| 204 | object-oriented style of programming, there is no type hierarchy. |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 205 | The concept of “interface” in Go provides a different approach that |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 206 | we believe is easy to use and in some ways more general. There are |
| 207 | also ways to embed types in other types to provide something |
| 208 | analogous—but not identical—to subclassing. |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 209 | Moreover, methods in Go are more general than in C++ or Java: |
| 210 | they can be defined for any sort of data, not just structs. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 211 | |
| 212 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 213 | Also, the lack of type hierarchy makes “objects” in Go feel much more |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 214 | lightweight than in languages such as C++ or Java. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 215 | |
| 216 | <h3 id="How_do_I_get_dynamic_dispatch_of_methods"> |
| 217 | How do I get dynamic dispatch of methods?</h3> |
| 218 | |
| 219 | <p> |
| 220 | The only way to have dynamically dispatched methods is through an |
| 221 | interface. Methods on structs or other types are always resolved statically. |
| 222 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 223 | <h2 id="Concurrent_programming">Concurrent programming</h2> |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 224 | |
| 225 | <h3 id="What_operations_are_atomic_What_about_mutexes"> |
| 226 | What operations are atomic? What about mutexes?</h3> |
| 227 | |
| 228 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 229 | We haven't fully defined it all yet, but some details about atomicity are available in the |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 230 | <a href="go_mem.html">Go Memory Model specification</a>. |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 231 | Also, some concurrency questions are answered in more detail in the |
| 232 | <a href="go_lang_faq.html">language design FAQ</a>. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 233 | |
| 234 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 235 | Regarding mutexes, the <a href="/pkg/sync">sync</a> |
| 236 | package implements them, but we hope Go programming style will |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 237 | encourage people to try higher-level techniques. In particular, consider |
| 238 | structuring your program so that only one goroutine at a time is ever |
| 239 | responsible for a particular piece of data. |
| 240 | |
| 241 | <p> |
| 242 | Do not communicate by sharing memory. Instead, share memory by communicating. |
| 243 | |
| 244 | <h2 id="Writing_Code">Writing Code</h2> |
| 245 | |
| 246 | <h3 id="How_are_libraries_documented"> |
| 247 | How are libraries documented?</h3> |
| 248 | |
| 249 | <p> |
| 250 | There is a program, <code>godoc</code>, written in Go, that extracts |
| 251 | package documentation from the source code. It can be used on the |
| 252 | command line or on the web. An instance is running at |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 253 | <a href="http://golang.org/pkg/">http://golang.org/pkg/</a>. |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 254 | In fact, <code>godoc</code> implements the full site at |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 255 | <a href="http://golang.org/">http://golang.org/</a>. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 256 | |
| 257 | <h3 id="Is_there_a_Go_programming_style_guide"> |
| 258 | Is there a Go programming style guide?</h3> |
| 259 | |
| 260 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 261 | Eventually, there may be a small number of rules to guide things |
| 262 | like naming, layout, and file organization. |
| 263 | The document <a href="effective_go.html">Effective Go</a> |
| 264 | contains some style advice. |
| 265 | More directly, the program <code>gofmt</code> is a pretty-printer |
| 266 | whose purpose is to enforce layout rules; it replaces the usual |
| 267 | compendium of do's and don'ts that allows interpretation. |
| 268 | All the Go code in the repository has been run through <code>gofmt</code>. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 269 | |
| 270 | <h3 id="How_do_I_submit_patches_to_the_Go_libraries"> |
| 271 | How do I submit patches to the Go libraries?</h3> |
| 272 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 273 | <p> |
| 274 | The library sources are in <code>go/src/pkg</code>. |
| 275 | If you want to make a significant change, please discuss on the mailing list before embarking. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 276 | |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 277 | <p> |
| 278 | See the document |
| 279 | <a href="contribute.html">Contributing to the Go project</a> |
| 280 | for more information about how to proceed. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 281 | |
| 282 | <h3 id="How_do_I_create_a_multifile_package"> |
| 283 | How do I create a multifile package?</h3> |
| 284 | |
| 285 | <p> |
| 286 | Put all the source files for the package in a directory by themselves. |
| 287 | Source files can refer to items from different files at will; there is |
| 288 | no header file or need for forward declarations. |
| 289 | |
| 290 | <p> |
| 291 | Other than being split into multiple files, the package will compile and test |
| 292 | just like a single-file package. |
| 293 | |
| 294 | <h3 id="How_do_I_write_a_unit_test"> |
| 295 | How do I write a unit test?</h3> |
| 296 | |
| 297 | <p> |
| 298 | Create a new file ending in <code>_test.go</code> in the same directory |
| 299 | as your package sources. Inside that file, <code>import "testing"</code> |
| 300 | and write functions of the form |
| 301 | |
| 302 | <pre> |
| 303 | func TestFoo(t *testing.T) { |
| 304 | ... |
| 305 | } |
| 306 | </pre> |
| 307 | |
| 308 | <p> |
| 309 | Run <code>gotest</code> in that directory. |
| 310 | That script finds the <code>Test</code> functions, |
| 311 | builds a test binary, and runs it. |
| 312 | |
| 313 | <h3 id="Where_is_assert"> |
| 314 | Where is assert?</h3> |
| 315 | |
| 316 | <p> |
| 317 | Go doesn't provide assertions. They are undeniably convenient, but our |
| 318 | experience has been that programmers use them as a crutch to avoid thinking |
| 319 | about proper error handling and reporting. Proper error handling means that |
| 320 | servers continue operation after non-fatal errors instead of crashing. |
| 321 | Proper error reporting means that errors are direct and to the point, |
| 322 | saving the programmer from interpreting a large crash trace. Precise |
| 323 | errors are particularly important when the programmer seeing the errors is |
| 324 | not familiar with the code. |
| 325 | |
| 326 | <p> |
| 327 | The same arguments apply to the use of <code>assert()</code> in test programs. Proper |
| 328 | error handling means letting other tests run after one has failed, so |
| 329 | that the person debugging the failure gets a complete picture of what is |
| 330 | wrong. It is more useful for a test to report that |
| 331 | <code>isPrime</code> gives the wrong answer for 2, 3, 5, and 7 (or for |
| 332 | 2, 4, 8, and 16) than to report that <code>isPrime</code> gives the wrong |
| 333 | answer for 2 and therefore no more tests were run. The programmer who |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 334 | triggers the test failure may not be familiar with the code that fails. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 335 | Time invested writing a good error message now pays off later when the |
| 336 | test breaks. |
| 337 | |
| 338 | <p> |
| 339 | In testing, if the amount of extra code required to write |
| 340 | good errors seems repetitive and overwhelming, it might work better as a |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 341 | table-driven test instead. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 342 | Go has excellent support for data structure literals. |
| 343 | |
| 344 | <p> |
| 345 | We understand that this is a point of contention. There are many things in |
| 346 | the Go language and libraries that differ from modern practices, simply |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 347 | because we feel it's sometimes worth trying a different approach. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 348 | |
| 349 | <h2 id="Implementation">Implementation</h2> |
| 350 | |
| 351 | <h3 id="What_compiler_technology_is_used_to_build_the_compilers"> |
| 352 | What compiler technology is used to build the compilers?</h3> |
| 353 | |
| 354 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 355 | <code>Gccgo</code> has a C++ front-end with a recursive descent parser coupled to the |
| 356 | standard GCC back end. <code>Gc</code> is written in C using |
| 357 | <code>yacc</code>/<code>bison</code> for the parser. |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 358 | Although it's a new program, it fits in the Plan 9 C compiler suite |
| 359 | (<a href="http://plan9.bell-labs.com/sys/doc/compiler.html">http://plan9.bell-labs.com/sys/doc/compiler.html</a>) |
| 360 | and uses a variant of the Plan 9 loader to generate ELF binaries. |
| 361 | |
| 362 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 363 | We considered writing <code>6g</code>, the original Go compiler, in Go itself but |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 364 | elected not to do so because of the difficulties of bootstrapping and |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 365 | especially of open source distribution—you'd need a Go compiler to |
| 366 | set up a Go environment. <code>Gccgo</code>, which came later, makes it possible to |
| 367 | consider writing a compiler in Go, which might well happen. (Go would be a |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 368 | fine language in which to implement a compiler; a native lexer and |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 369 | parser are already available in <a href="/pkg/go/"><code>/pkg/go</code></a>.) |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 370 | |
| 371 | <p> |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 372 | We also considered using LLVM for <code>6g</code> but we felt it was too large and |
Russ Cox | 3227445 | 2009-10-22 00:13:51 -0700 | [diff] [blame] | 373 | slow to meet our performance goals. |
| 374 | |
| 375 | <h3 id="How_is_the_runtime_implemented"> |
| 376 | How is the runtime implemented?</h3> |
| 377 | |
| 378 | <p> |
| 379 | Again due to bootstrapping issues, the runtime is mostly in C (with a |
| 380 | tiny bit of assembler) although Go is capable of implementing most of |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 381 | it now. <code>Gccgo</code>'s runtime uses <code>glibc</code>. |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 382 | <code>Gc</code> uses a custom library, to keep the footprint under |
| 383 | control; it is |
| 384 | compiled with a version of the Plan 9 C compiler that supports |
| 385 | segmented stacks for goroutines. |
Russ Cox | e434f1a | 2009-11-07 17:31:22 -0800 | [diff] [blame] | 386 | Work is underway to provide the same stack management in |
Rob Pike | 0c2a479 | 2009-11-01 20:50:42 -0800 | [diff] [blame] | 387 | <code>gccgo</code>. |