github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/blog/content/first-go-program.article (about) 1 The first Go program 2 18 Jul 2013 3 Tags: history 4 5 Andrew Gerrand 6 7 * Introduction 8 9 Brad Fitzpatrick and I (Andrew Gerrand) recently started restructuring 10 [[http://golang.org/cmd/godoc/][godoc]], and it occurred to me that it is one 11 of the oldest Go programs. 12 Robert Griesemer started writing it back in early 2009, 13 and we're still using it today. 14 15 When I [[https://twitter.com/enneff/status/357403054632484865][tweeted]] about 16 this, Dave Cheney replied with an [[https://twitter.com/davecheney/status/357406479415914497][interesting question]]: 17 what is the oldest Go program? Rob Pike dug into his mail and found it 18 in an old message to Robert and Ken Thompson. 19 20 What follows is the first Go program. It was written by Rob in February 2008, 21 when the team was just Rob, Robert, and Ken. They had a solid feature list 22 (mentioned in [[http://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-more.html][this blog post]]) 23 and a rough language specfication. Ken had just finished the first working version of 24 a Go compiler (it didn't produce native code, but rather transliterated Go code 25 to C for fast prototyping) and it was time to try writing a program with it. 26 27 Rob sent mail to the "Go team": 28 29 From: Rob 'Commander' Pike 30 Date: Wed, Feb 6, 2008 at 3:42 PM 31 To: Ken Thompson, Robert Griesemer 32 Subject: slist 33 34 it works now. 35 36 roro=% a.out 37 (defn foo (add 12 34)) 38 return: icounter = 4440 39 roro=% 40 41 here's the code. 42 some ugly hackery to get around the lack of strings. 43 44 45 (The `icounter` line in the program output is the number of executed 46 statements, printed for debugging.) 47 48 .code first-go-program/slist.go 49 50 The program parses and prints an 51 [[https://en.wikipedia.org/wiki/S-expression][S-expression]]. 52 It takes no user input and has no imports, relying only on the built-in 53 `print` facility for output. 54 It was written literally the first day there was a 55 [[http://golang.org/change/8b8615138da3][working but rudimentary compiler]]. 56 Much of the language wasn't implemented and some of it wasn't even specified. 57 58 Still, the basic flavor of the language today is recognizable in this program. 59 Type and variable declarations, control flow, and package statements haven't 60 changed much. 61 62 But there are many differences and absences. 63 Most significant are the lack of concurrency and interfaces—both 64 considered essential since day 1 but not yet designed. 65 66 A `func` was a `function`, and its signature specified return values 67 _before_ arguments, separating them with `<-`, which we now use as the channel 68 send/receive operator. For example, the `WhiteSpace` function takes the integer 69 `c` and returns a boolean. 70 71 function WhiteSpace(bool <- c int) 72 73 This arrow was a stop-gap measure until a better syntax arose for declaring 74 multiple return values. 75 76 Methods were distinct from functions and had their own keyword. 77 78 method (this *Slist) Car(*Slist <-) { 79 return this.list.car; 80 } 81 82 And methods were pre-declared in the struct definition, although that changed soon. 83 84 type Slist struct { 85 ... 86 Car method(*Slist <-); 87 } 88 89 There were no strings, although they were in the spec. 90 To work around this, Rob had to build the input string as an `uint8` array with 91 a clumsy construction. (Arrays were rudimentary and slices hadn't been designed 92 yet, let alone implemented, although there was the unimplemented concept of an 93 "open array".) 94 95 input[i] = '('; i = i + 1; 96 input[i] = 'd'; i = i + 1; 97 input[i] = 'e'; i = i + 1; 98 input[i] = 'f'; i = i + 1; 99 input[i] = 'n'; i = i + 1; 100 input[i] = ' '; i = i + 1; 101 ... 102 103 Both `panic` and `print` were built-in keywords, not pre-declared functions. 104 105 print "parse error: expected ", c, "\n"; 106 panic "parse"; 107 108 And there are many other little differences; see if you can identify some others. 109 110 Less than two years after this program was written, Go was released as an 111 open source project. Looking back, it is striking how much the language has 112 grown and matured. (The last thing to change between this proto-Go and the Go 113 we know today was the elimination of semicolons.) 114 115 But even more striking is how much we have learned about _writing_ Go code. 116 For instance, Rob called his method receivers `this`, but now we use shorter 117 context-specific names. There are hundreds of more significant examples 118 and to this day we're still discovering better ways to write Go code. 119 (Check out the [[https://github.com/golang/glog][glog package]]'s clever trick for 120 [[https://github.com/golang/glog/blob/c6f9652c7179652e2fd8ed7002330db089f4c9db/glog.go#L893][handling verbosity levels]].) 121 122 I wonder what we'll learn tomorrow. 123