go
play

Go Berkeley CS 294-101 Mar 18, 2015 Rob Pike Google - PDF document

Go 3/19/15, 7:18 AM Go Berkeley CS 294-101 Mar 18, 2015 Rob Pike Google http://127.0.0.1:3999/2015/res.slide#47 Page 1 of 49 Go 3/19/15, 7:18 AM What is Go? Go is: designed by Google open source concurrent garbage-collected compiled


  1. Go 3/19/15, 7:18 AM Go Berkeley CS 294-101 Mar 18, 2015 Rob Pike Google http://127.0.0.1:3999/2015/res.slide#47 Page 1 of 49

  2. Go 3/19/15, 7:18 AM What is Go? Go is: designed by Google open source concurrent garbage-collected compiled scalable simple fun boring (to some) golang.org (http://golang.org) http://127.0.0.1:3999/2015/res.slide#47 Page 2 of 49

  3. Go 3/19/15, 7:18 AM Adoption http://127.0.0.1:3999/2015/res.slide#47 Page 3 of 49

  4. Go 3/19/15, 7:18 AM Why? Go is an answer to problems of scale at Google. http://127.0.0.1:3999/2015/res.slide#47 Page 4 of 49

  5. Go 3/19/15, 7:18 AM How? By designing a language for software engineering. http://127.0.0.1:3999/2015/res.slide#47 Page 5 of 49

  6. Go 3/19/15, 7:18 AM What is important? http://127.0.0.1:3999/2015/res.slide#47 Page 6 of 49

  7. Go 3/19/15, 7:18 AM Properties The "abilities": Readability Scalability Suitability Toolability http://127.0.0.1:3999/2015/res.slide#47 Page 7 of 49

  8. Go 3/19/15, 7:18 AM Readability http://127.0.0.1:3999/2015/res.slide#47 Page 8 of 49

  9. Go 3/19/15, 7:18 AM Overview The readability of programs is immeasurably more important than their writeability. Hints on Programming Language Design C. A. R. Hoare 1973 http://127.0.0.1:3999/2015/res.slide#47 Page 9 of 49

  10. Go 3/19/15, 7:18 AM Readability The purpose of notation: clearly express what we care about http://127.0.0.1:3999/2015/res.slide#47 Page 10 of 49

  11. Go 3/19/15, 7:18 AM Clarity: Plan for the future program for someone else, years from now one-liners not the gold standard a balance between clarity and redundancy http://127.0.0.1:3999/2015/res.slide#47 Page 11 of 49

  12. Go 3/19/15, 7:18 AM Too cold scoped_ptr<goscript::GoScript> goscript(goscript::GoScript::NewGoScript(FLAGS_goscript, goscript::GoScript::kFIFO)); http://127.0.0.1:3999/2015/res.slide#47 Page 12 of 49

  13. Go 3/19/15, 7:18 AM Too hot (n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps)) http://127.0.0.1:3999/2015/res.slide#47 Page 13 of 49

  14. Go 3/19/15, 7:18 AM Just right t := time.Now() switch { case t.Hour() < 12: return "morning" case t.Hour() < 18: return "afternoon" default: return "evening" } http://127.0.0.1:3999/2015/res.slide#47 Page 14 of 49

  15. Go 3/19/15, 7:18 AM Naming How names work in a programming language is critical to readability. http://127.0.0.1:3999/2015/res.slide#47 Page 15 of 49

  16. Go 3/19/15, 7:18 AM Scope Go has very simple scope hierarchy: universe package fi le (for imports only) function block http://127.0.0.1:3999/2015/res.slide#47 Page 16 of 49

  17. Go 3/19/15, 7:18 AM Locality of names Nuances: upper case names for visibility: name vs. Name no implicit this in methods (receiver is explicit); always see rcvr.Field package quali fi er always present for imported names ( fi rst component of) every name is always declared in current package http://127.0.0.1:3999/2015/res.slide#47 Page 17 of 49

  18. Go 3/19/15, 7:18 AM Locality scales No surprises when importing: adding an exported name to my package cannot break your package! Names do not leak across boundaries. In C, C++, Java the name y could refer to anything. In Go, y (or even Y ) is always de fi ned within the package. In Go, x.Y is clear: fi nd x locally, Y belongs to it. http://127.0.0.1:3999/2015/res.slide#47 Page 18 of 49

  19. Go 3/19/15, 7:18 AM Function and method lookup Method lookup by name only, not type. A type cannot have two methods with the same name, ever. Easy to identify which function/method is referred to. Simple implementation, simpler program, fewer surprises. Given a method x.M , there's only ever one M associated with x . http://127.0.0.1:3999/2015/res.slide#47 Page 19 of 49

  20. Go 3/19/15, 7:18 AM Scalability http://127.0.0.1:3999/2015/res.slide#47 Page 20 of 49

  21. Go 3/19/15, 7:18 AM http://127.0.0.1:3999/2015/res.slide#47 Page 21 of 49

  22. Go 3/19/15, 7:18 AM http://127.0.0.1:3999/2015/res.slide#47 Page 22 of 49

  23. Go 3/19/15, 7:18 AM http://127.0.0.1:3999/2015/res.slide#47 Page 23 of 49

  24. Go 3/19/15, 7:18 AM http://127.0.0.1:3999/2015/res.slide#47 Page 24 of 49

  25. Go 3/19/15, 7:18 AM http://127.0.0.1:3999/2015/res.slide#47 Page 25 of 49

  26. Go 3/19/15, 7:18 AM Scalability Google means scale in multiple dimensions computers cores data code engineers Plus scaling has a big e ff ect on: speed of compilation speed of testing http://127.0.0.1:3999/2015/res.slide#47 Page 26 of 49

  27. Go 3/19/15, 7:18 AM System scale http://127.0.0.1:3999/2015/res.slide#47 Page 27 of 49

  28. Go 3/19/15, 7:18 AM System scale 10 ⁶⁺ machines (design point) routine to be running on 1000 machines coordinating, interacting with other servers lots going on at once Solution: great support for concurrency http://127.0.0.1:3999/2015/res.slide#47 Page 28 of 49

  29. Go 3/19/15, 7:18 AM Engineering scale http://127.0.0.1:3999/2015/res.slide#47 Page 29 of 49

  30. Go 3/19/15, 7:18 AM Engineering scale In 2011 at Google: single code tree 5000+ developers across 40+ o ffi ces 20+ changes per minute 50% of source fi les change every month 50 million test cases executed per day Solution: engineer language for large code bases http://127.0.0.1:3999/2015/res.slide#47 Page 30 of 49

  31. Go 3/19/15, 7:18 AM Software scale http://127.0.0.1:3999/2015/res.slide#47 Page 31 of 49

  32. Go 3/19/15, 7:18 AM Dependencies in C++ Explosive, exponential, almost non-computable. In 2007, instrumented building a large Google web-serving binary: 2000 fi les 4.2 megabytes 8 gigabytes delivered to compiler 2000 bytes sent to compiler for every C++ source byte it's real work too: <string> for example hours to build http://127.0.0.1:3999/2015/res.slide#47 Page 32 of 49

  33. Go 3/19/15, 7:18 AM Dependencies in Go Linguistically de fi ned. E ffi cient. Computable. http://127.0.0.1:3999/2015/res.slide#47 Page 33 of 49

  34. Go 3/19/15, 7:18 AM Hoisting dependencies Consider: A imports B imports C but A does not directly import C . The object code for B includes all the information about C needed to import B . Therefore in A the line import "B" does not require the compiler to read C when compiling A . Also, the object fi les are designed so the "export" information comes fi rst; compiler doing import does not need to read whole fi le. Exponentially less data read than with #include fi les. With Go in Google, about 40X fanout (recall C++ was 2000x) Plus in C++ it's general code that must be parsed; in Go it's just export data. http://127.0.0.1:3999/2015/res.slide#47 Page 34 of 49

  35. Go 3/19/15, 7:18 AM Scalability requires readability For code to grow safely as time passes and sta ff changes: it must be readable it must be clear it must be adaptable it must be local The themes resonate. http://127.0.0.1:3999/2015/res.slide#47 Page 35 of 49

  36. Go 3/19/15, 7:18 AM Suitability http://127.0.0.1:3999/2015/res.slide#47 Page 36 of 49

  37. Go 3/19/15, 7:18 AM Suitability Can the language do the job? Language is notation for a problem; not all languages are good for all problems. Go was designed for Google to help solve Google's problems. http://127.0.0.1:3999/2015/res.slide#47 Page 37 of 49

  38. Go 3/19/15, 7:18 AM Concurrency is vital Linguistic support for concurrent execution makes programming in the Google environment easier, safer, and more productive. A key reason for Go's existence. http://127.0.0.1:3999/2015/res.slide#47 Page 38 of 49

  39. Go 3/19/15, 7:18 AM Go in production Several big services are written in Go: golang.org dl.google.com vitess , part of youtube.com ... Adoption fi nds issues; they are resolved; adoption easier next time. http://127.0.0.1:3999/2015/res.slide#47 Page 39 of 49

  40. Go 3/19/15, 7:18 AM SPDY SPDY proxy for Chrome on mobile devices http://127.0.0.1:3999/2015/res.slide#47 Page 40 of 49

  41. Go 3/19/15, 7:18 AM Toolability http://127.0.0.1:3999/2015/res.slide#47 Page 41 of 49

  42. Go 3/19/15, 7:18 AM Toolability Software engineering requires tools. Go's syntax, package design, naming, etc. make tools easy to write. Library includes lexer, parser and type checker. http://127.0.0.1:3999/2015/res.slide#47 Page 42 of 49

  43. Go 3/19/15, 7:18 AM Gofmt Always intended to do automatic code formatting. Eliminates an entire class of argument. Runs as a "presubmit" to the code repositories. Training: The community has always seen gofmt output. Sharing: Uniformity of presentation simpli fi es sharing. Scaling: Less time spent on formatting, more on content. Often cited as one of Go's best features. http://127.0.0.1:3999/2015/res.slide#47 Page 43 of 49

  44. Go 3/19/15, 7:18 AM Gofmt and other tools Surprise: The existence of gofmt enabled semantic tools: Can rewrite the tree; gofmt will clean up output. Examples: gofmt -r 'a[b:len(a)] -> a[b:]' gofix And good front-end libraries enable ancillary tools: godoc go get , go build , go vet , etc. api http://127.0.0.1:3999/2015/res.slide#47 Page 44 of 49

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend