{"id":326,"date":"2010-09-10T04:31:49","date_gmt":"2010-09-09T17:31:49","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=326"},"modified":"2010-09-10T04:32:57","modified_gmt":"2010-09-09T17:32:57","slug":"another-go-at-language-design","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2010\/09\/10\/another-go-at-language-design\/","title":{"rendered":"Another Go at language design"},"content":{"rendered":"<p>The other day I attended a very interesting talk at the University of Melbourne given by Rob Pike.\u00a0 The title was &#8220;Another Go at language design&#8221; and it was all about Google&#8217;s new programming language, <a href=\"http:\/\/golang.org\/\">Go<\/a>.\u00a0 It was a high level overview of the language with an emphasis on why certain design decisions were made.<\/p>\n<p>Here is a random selection of the things that struck me as most interesting.<\/p>\n<ul>\n<li>Pike lamented the state of modern industrial languages, by which he meant C++ and Java.\u00a0 He started with a quote from Dick Gabriel \u201cOld programs read like quiet conversations between a well-spoken research worker and a well-studied mechanical colleague, not as a debate with a compiler.\u201d\u00a0 In particular, one of the aims of Go is to show programmers whose only exposure to static typing is through C++ and Java that statically typed languages can have the simpler, more concise feel (fewer declarations!) of dynamically typed languages like JavaScript and Python.<\/li>\n<li>Compile times of Go programs are small.\u00a0 This is because the compiler doesn&#8217;t need to know about transitive dependencies between packages (their name for modules).\u00a0 For example, if you have a file A.go which depends on B.go which depends on C.go, at first you have to compile C.go, then B.go, then A.go.\u00a0 But all the information exported from A.go is stored in the compiled B.o file, which means that if you recompile A.go you don&#8217;t have to recompile anything else.\u00a0 Hmm, now I&#8217;m unsure if that&#8217;s exactly right.\u00a0 But the broader point is that the language avoids C++&#8217;s problem where bazillions of header files have to be read for every module.\u00a0 He said with a completely straight face that their goal was to have a 1,000,000x speed-up over C++ for the compilation time of large programs, though they&#8217;d probably be satisfied with 100,000x.\u00a0 Impressive!\u00a0 Imagine if Firefox compiled in less than a second.<\/li>\n<li>Identifiers that start with an upper-case letter are public, and identifiers that start with a lower-case letter are private.\u00a0 The other language I&#8217;m familiar with that has a similar distinction is Haskell, where identifiers that start with an upper-case letter are used for types, and identifiers that start with a lower-case letter are used for values.\u00a0 The nice thing about Go&#8217;s approach is that it gives you strictly more information:\u00a0 you can determine from an identifier&#8217;s use point whether it&#8217;s public or private, which saves you from having to find it&#8217;s declaration.<\/li>\n<li>There is no automatic conversion between numeric types.\u00a0 This is for simplicity;\u00a0 Pike said (probably exaggerating) that 1\/3 of the C standard deals with this topic.\u00a0 But the handling of numeric constants avoids many cases where explicit conversions are needed, because numeric constants are platonic in the sense that they don&#8217;t have a particular type until they are assigned to a variable.<\/li>\n<li>They have a reformatting program, gofmt, that rewrites Go code into an &#8220;approved&#8221; layout.\u00a0 This ensures that all Go code looks consistent, and avoids fights over style.\u00a0 (<a href=\"http:\/\/weblogs.mozillazine.org\/roc\/\">Robert O&#8217;Callahan<\/a> would approve!)\u00a0 Interestingly, gofmt is separate from the compiler, and the idea is that you run it once you have finished a change.\u00a0 At Google when code is committed into a repository, gofmt is run and if the layout doesn&#8217;t match the code is rejected.\u00a0 I asked why they made it a separate program, rather than having stronger syntax\/layout checking in of the compiler.\u00a0 He said that (a) they hadn&#8217;t thought of putting it in the compiler, (b) it seemed like it would be less painful to just run it occasionally rather than having to worry about it every time you compile, and (c) it would slow down the compiler.<\/li>\n<\/ul>\n<p>It was a good talk, Pike is an engaging speaker.\u00a0 I&#8217;m glad he made the trip to Melbourne.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I attended a very interesting talk at the University of Melbourne given by Rob Pike.\u00a0 The title was &#8220;Another Go at language design&#8221; and it was all about Google&#8217;s new programming language, Go.\u00a0 It was a high level overview of the language with an emphasis on why certain design decisions were made. [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[916,617],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/326"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/comments?post=326"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/326\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}