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