Text file
talks/2014/hellogophers.slide
1 Hello, Gophers!
2 Gophercon Opening Keynote
3 24 Apr 2014
4
5 Rob Pike
6 Google, Inc.
7 https://go.dev
8
9 * Video
10
11 A video of this talk was recorded at GopherCon in Denver.
12
13 .link https://www.youtube.com/watch?v=VoS7DsT1rdM Watch the talk on YouTube
14
15
16 * Hello, gophers!
17
18 .image hellogophers/gophers.jpg 500 750
19
20 * Hello, gophers!
21
22 .play hellogophers/hellogophers.go
23
24 * History
25
26 This is a historic occasion.
27
28 Go has achieved a level of success worthy of a conference.
29
30 * Success
31
32 Many factors contribute to that success.
33
34 - features
35 - lack of features
36 - combination of features
37 - design
38 - people
39 - time
40
41 * Case study
42
43 A look back, focusing on code.
44
45 * Two programs
46
47 A close look at two programs.
48
49 First is the first Go program _you_ ever saw. Historic for you.
50 Second is the first Go program _we_ ever saw. Historic for all gophers.
51
52 First up: "hello, world".
53
54 * hello.b
55
56 .code hellogophers/hello.b
57
58 First appeared in a 1972 B tutorial by Brian W. Kernighan.
59 (Not, as sometimes claimed, a few years earlier in BCPL.)
60
61 * hello.c
62
63 .code hellogophers/hello.c
64
65 First appeared in
66 _Programming_in_C:_A_Tutorial_, by Brian W. Kernighan, 1974.
67 Came as a document with Unix v5.
68
69 * hello.c
70
71 .code hellogophers/helloKnR.c
72
73 First appeared in
74 _The_C_Programming_Language_, by Brian W. Kernighan and Dennis M. Ritchie, 1978.
75
76 * hello.c, Draft ANSI C
77
78 .code hellogophers/helloDraftAnsi.c
79
80 Appeared in
81 _The_C_Programming_Language_, _Second_Edition_, (Based on Draft-Proposed ANSI C)
82 by Brian W. Kernighan and Dennis M. Ritchie, 1988.
83
84 * hello.c, ANSI C89
85
86 .code hellogophers/helloAnsi.c
87
88 Appeared in
89 _The_C_Programming_Language_, _Second_Edition_, round two,
90 by Brian W. Kernighan and Dennis M. Ritchie, 1988.
91
92 "You've gotta put a void THERE?" -Ken Thompson
93
94 * A generation or two later...
95
96 (Skipping all the intermediate languages.)
97
98 Go discussions start in late 2007.
99
100 Specification first drafted in March 2008.
101 For experimentation and prototyping, compiler work already underway.
102 Initially generated C output.
103 Once the specification arose, compiler rewritten to generate native code.
104
105 * hello.go, June 6, 2008
106
107 .code hellogophers/hello_20080606.go
108
109 First checked-in test.
110 The `print` builtin is all we have, and `main` returns an `int`.
111 Note: no parentheses on `print`.
112
113 * hello.go, June 27, 2008
114
115 .code hellogophers/hello_20080627.go
116
117 When `main` returns, the program calls `exit(0)`.
118
119 * hello.go, August 11, 2008
120
121 .play hellogophers/hello_20080811.go
122
123 Parentheses now required: `print` now a function not a primitive.
124
125 * hello.go, October 24, 2008
126
127 .code hellogophers/hello_20081024.go
128
129 The "printf as we know and love it" goes in.
130 (The test still uses `print` not `printf`; we've switched examples here.)
131
132 * hello.go, January 15, 2009
133
134 .play hellogophers/hello_20090115.go
135
136 Upper case for export. "Casification."
137
138 * hello.go, Dec 11, 2009
139
140 .play hellogophers/hello_20091211.go
141
142 No more semicolons.
143 A major change that occurs _after_ the open source release (Nov 10, 2009).
144
145 The current version.
146
147 It took us a while to get here (32 years!).
148
149 A lot of history.
150
151 * Not just C
152
153 We "started with C" but Go is profoundly different.
154 Some of the languages that influenced and informed the design of Go:
155
156 C: statement and expression syntax
157 Pascal: declaration syntax
158 Modula 2, Oberon 2: packages
159 CSP, Occam, Newsqueak, Limbo, Alef: concurrency
160 BCPL: the semicolon rule
161 Smalltalk: methods
162 Newsqueak: `<-`, `:=`
163 APL: `iota`
164
165 And others. Also some was invented whole: `defer`, constants, for instance.
166
167 Plus lessons good and bad from all those plus:
168 C++, C#, Java, JavaScript, LISP, Python, Scala, ...
169
170 * hello.go, Go version 1
171
172 Which brings us to today.
173
174 .play hellogophers/hello.go
175
176 Let's dig deeper, break this down.
177
178 * Hello, world in 16 tokens
179
180 `package`
181 `main`
182 `import`
183 `"fmt"`
184 `func`
185 `main`
186 `(`
187 `)`
188 `{`
189 `fmt`
190 `.`
191 `Println`
192 `(`
193 `"Hello,`Gophers`(some`of`whom`know`日本語)!"`
194 `)`
195 `}`
196
197 * package
198
199 Major topic in early design discussions: Key to scalability.
200
201 What is a package? Ideas from Modula-2 etc.
202 Why are there packages?
203 Hold all the information you need to build.
204 No circular dependencies (imports).
205 No subpackages.
206 Separation of package name and package path.
207 Visibility is package-level, not type-level.
208 Within a package, you have the whole language, outside only what you permit.
209
210 * main
211
212 One place where C legacy shows through.
213 Was originally `Main` for some forgotten reason.
214 `Main` package, `main` function.
215 Special because the root of the initialization tree.
216
217 * import
218
219 Mechanism for loading a package.
220 Implemented by the compiler (as opposed to a text processor).
221 Worked hard to make it efficient and linear.
222 Imports a package, not a set of identifiers.
223
224 As for export: It used to be a keyword.
225
226 * "fmt"
227
228 Package path is just a string, not a list of identifiers.
229 Allows the language to avoid defining what it means—adaptability.
230 From the beginning wanted a URL as an option.
231 Allows for future growth.
232
233 * func
234 A keyword introduces functions (and types, variables, constants) for easy parsing.
235 Easy parsing is important with function literals (closures).
236
237 By the way, keyword was originally `function`.
238
239 * Aside: Mail thread from February 6, 2008
240
241 From: Ken Thompson <ken@google.com>
242 To: gri, r
243
244 larry and sergey came by tonight. we
245 talked about go for more than an hour.
246 they both said they liked it very much.
247
248 p.s. one of larrys comments was "why isnt function spelled func?"
249
250 ---
251
252 From: Rob Pike <r@google.com>
253 To: ken, gri
254
255 fine with me. seems compatible with 'var'.
256
257 anyway we can always say, "larry said to call it 'func'"
258
259 * main
260
261 Where program starts... except it isn't.
262 Separation of initialization from normal execution, long planned.
263 Where does initialization happen?
264 Feeds back to package design.
265
266 * ()
267
268 Look Ma, no `void`.
269 No return value for `main`: handled by runtime.
270 No function args (command line is in `os` package).
271 No return value.
272
273 Return values and syntax.
274
275 * {
276
277 Braces not spaces.
278 And not square brackets.
279 Why is the newline after the brace?
280
281 * fmt
282
283 All imported identifiers are _qualified_ by their import.
284 _Every_ identifier is either local to package or func, or qualified by type or import.
285 Profound effect on readability.
286
287 Why `fmt` not `format`?
288
289 * .
290
291 How many uses are there in Go for a period token? (Lots.)
292 The meaning of `a.B` requires using the type system.
293 But it is clear to humans and very easy to read.
294
295 Autopromotion of pointers (no `->` operator).
296
297 * Println
298
299 `Println` not `println`: capitals for export.
300 Always knew it would be reflection-driven. (Safety, formatless printing.)
301 Variadic functions.
302 Argument type was `(...)`; became `(...interface{})` on Feb 1, 2010.
303
304 * (
305
306 Traditional function syntax.
307
308 * "Hello, Gophers (some of whom know 日本語)!"
309
310 UTF-8 input source, so strings as literals are UTF-8 automatically.
311 But what is a string?
312 One of the first things written in the specification, hardly changed today.
313
314 .link /blog/strings go.dev/blog/strings
315
316 * )
317
318 No semicolon.
319 Semicolons went away shortly after release.
320 Much futzing around to try to cull them in early days.
321 Eventually accepted the BCPL approach.
322
323 * }
324
325 Done.
326
327 * Aside: Not discussed
328
329 - types
330 - constants
331 - methods
332 - interfaces
333 - libraries
334 - memory management
335 - concurrency (coming up)
336
337 Plus tools, ecosystem, community, ...:
338 Language is central but only part of the story.
339
340 * Success
341
342 Factors:
343
344 - building on history
345 - building on experience
346 - process of design
347 - early ideas refined into final approach
348 - concentrated effort by a small dedicated team
349
350 Finally: Commitment.
351
352 Go 1.0 locked down the language and libraries.
353
354 * Another round
355
356 Now watch similar evolution of a second program.
357
358 * Problem: Prime sieve
359
360 Problem specification from
361 _Communicating_Sequential_Processes_, by C. A. R. Hoare, 1978
362
363 "Problem: To print in ascending order all primes less than
364 10000. Use an array of processes, SIEVE, in which each
365 process inputs a prime from its predecessor and prints it.
366 The process then inputs an ascending stream of numbers
367 from its predecessor and passes them on to its successor,
368 suppressing any that are multiples of the original prime. "
369
370 * Solution
371
372 Defined in the 1978 CSP paper.
373 (Note: not the sieve of Eratosthenes.)
374
375 "This beautiful solution was contributed by David Gries."
376
377 * CSP
378
379 In Hoare's 1978 CSP paper
380
381 .code hellogophers/sieve.csp
382
383 No channels, just processes so number of primes is fixed by program.
384
385 * Newsqueak
386
387 _circa_ 1988.
388 Language by Rob Pike, program by Tom Cargill via Doug McIlroy.
389
390 Uses channels, so length of run is programmable.
391 (Where did the idea of channels come from?)
392
393 .code hellogophers/sieve.newsqueak 1,/BREAK/
394
395 * Newsqueak (cont'd)
396
397 .code hellogophers/sieve.newsqueak /BREAK/,$
398
399 * sieve.go, March 5, 2008
400
401 First version in a Go specification, probably the second non-trivial program written.
402 `>` to send, `<` to receive. Channels are pointers. `Main` is capitalized.
403
404 .code hellogophers/sieve_20080305.go 1,/BREAK/
405
406 * sieve.go, March 5, 2008 (cont'd)
407
408 .code hellogophers/sieve_20080305.go /BREAK/,$
409
410 * sieve.go, July 22, 2008
411
412 `-<` to send, `<-` to receive. Channels still pointers. Now `main` not capitalized.
413
414 .code hellogophers/sieve_20080722.go 1,/BREAK/
415
416 * sieve.go, July 22, 2008 (cont'd)
417
418 .code hellogophers/sieve_20080722.go /BREAK/,$
419
420 * sieve.go, September 17, 2008
421
422 Communication operators now prefix and postfix `<-`. Channels still pointers.
423
424 .code hellogophers/sieve_20080917.go 1,/BREAK/
425
426 * sieve.go, September 17, 2008 (cont'd)
427
428 .code hellogophers/sieve_20080917.go /BREAK/,$
429
430 * sieve.go, January 6, 2009
431
432 The `make` builtin arrives. No pointers. Code wrong! (One `*` left, bad argument types.)
433
434 .code hellogophers/sieve_20090106.go 1,/BREAK/
435
436 * sieve.go, January 6, 2009 (cont'd)
437
438 .code hellogophers/sieve_20090106.go /BREAK/,$
439
440 * sieve.go, September 25, 2009
441
442 First correct modern version. Also: capitalization gone. Uses `fmt`.
443
444 .play hellogophers/sieve_20090925.go 1,/BREAK/
445
446 * sieve.go, September 25, 2009 (cont'd)
447
448 .play hellogophers/sieve_20090925.go /BREAK/,$
449
450 * sieve.go, December 10, 2009
451
452 Semicolons gone. Program as it is today.
453
454 .play hellogophers/sieve.go 1,/BREAK/
455
456 * sieve.go, December 10, 2009 (cont'd)
457
458 .play hellogophers/sieve.go /BREAK/,$
459
460 "This beautiful solution was contributed by a decades-long process of design."
461
462 * Aside: Not discussed
463
464 - `select`
465
466 The core connector for real concurrent applications. (A fact not always appreciated).
467 Origins in Dijkstra's guarded commands.
468 Made truly concurrent in Hoare's CSP.
469 Refined through Newsqueak, Alef, Limbo, and other routes.
470
471 Go's version specified on March 26, 2008.
472 Simplifications, clarifications, syntactic considerations.
473
474 * Stability
475
476 Sieve program unchanged since late 2009—stability!
477
478 Open source systems are not always dependably compatible and stable.
479
480 Go is.
481
482 This is a very important reason for Go's success.
483
484 * Trends
485
486 Graphs in usage metrics show knee in curve at Go 1.0 release.
487
488 .image hellogophers/trends.png
489
490 * Success
491
492 The factors for Go's success?
493
494 Obvious: Features and tools.
495
496 - concurrency
497 - garbage collection
498 - efficient implementation
499 - static types but dynamic feel
500 - rich but limited standard library
501 - tooling (and the factors that make it possible)
502 - `gofmt`
503 - programming in the large
504
505 * Success
506
507 Less obvious: process.
508
509 - focus on the original goals
510 - concentrated development followed by freeze
511 - consensus of a small core team
512 - vital contributions from a community that "gets it"
513 - rich ecosystem generated as a consequence
514
515 In short, an open source community that shares our mission,
516 coupled to a language designed for today's world.
517
518 * Fitness to purpose
519
520 From _Go:_the_emerging_language_of_cloud_infrastructure_ by Donnie Berkholz, March 2014.
521 [[/s/emerging]]
522
523 .image hellogophers/emerging.png
524
525 * The future
526
527 This is where you come in!
528
529 .image hellogophers/gophers.jpg 500 750
530
View as plain text