github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2010/go_talk-20100112.html (about) 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 4 <head> 5 <title>Go (January 12, 2010)</title> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 <meta name="font-size-adjustment" content="-1" /> 8 <link rel="stylesheet" href="support/slidy.css" 9 type="text/css" media="screen, projection, print" /> 10 <script src="support/slidy.js" type="text/javascript"> 11 </script> 12 </head> 13 <body> 14 <!-- this defines the slide background --> 15 16 <div class="background"> 17 18 <div class="header"> 19 <!-- sized and colored via CSS --> 20 </div> 21 22 <div class="footer"></div> 23 </div> 24 25 <div class="slide titlepage"> 26 <div style="height: 135px; width: 480px; overflow: hidden; position: fixed; top: auto; bottom: 10px; left: auto; right: 0; "> 27 <img src="support/bumper480x270.png" style="margin: -135px 0 0 0;"/> 28 </div> 29 <br/> 30 <img src="support/go-logo-white.png"> 31 <br/> 32 <br/> 33 <h1 style="padding-right: 0pt; margin-right: 0pt; color: #0066cc; font-size: 250%; border-bottom: 0px;">The Go Programming Language</h1> 34 <div style="color: #ffcc00;"> 35 <h2>Russ Cox</h2> 36 <!-- <h3><i>rsc@google.com</i></h3> --> 37 <br/> 38 <h3>Stanford University<br/><br/>January 12, 2010</h3> 39 </div> 40 </div> 41 42 <div class="slide"> 43 <h1>Go</h1> 44 45 <h2>New</h2> 46 <h2>Experimental</h2> 47 <h2>Concurrent</h2> 48 <h2>Garbage-collected</h2> 49 <h2>Systems</h2> 50 <h2>Language</h2> 51 </div> 52 53 <div class="slide"> 54 <h1>Hello, world</h1> 55 <pre> 56 package main 57 58 import "fmt" 59 60 func main() { 61 fmt.Printf("Hello, 世界\n") 62 } 63 </pre> 64 </div> 65 66 <div class="slide"> 67 <h1>History</h1> 68 69 <h2>Design started in late 2007.</h2> 70 <h2>Implementation starting to work mid-2008.</h2> 71 <h2>Released as an open source project in November 2009.</h2> 72 <h2>Work continues.<h2> 73 <h2>Robert Griesemer, Ken Thompson, Rob Pike, Ian Lance Taylor, Russ Cox, many others</h2> 74 </div> 75 76 <div class="slide"> 77 <h1>Why?</h1> 78 79 <h2>Go fast!</h2> 80 <h2>Make programming fun again.</h2> 81 </div> 82 83 <div class="slide"> 84 <h1>Why isn't programming fun?</h1> 85 86 <div class="incremental"> 87 <h2>Compiled, statically-typed languages (C, C++, Java) require too much typing and too much typing:</h2> 88 89 <ul> 90 <li>verbose, lots of repetition</li> 91 <li>too much focus on type hierarchy</li> 92 <li>types get in the way as much as they help</li> 93 <li>compiles take far too long</li> 94 </ul> 95 </div> 96 97 <div class="incremental"> 98 <h2>Dynamic languages (Python, JavaScript) fix these problems (no more types, no more compiler) but introduce others:</h2> 99 100 <ul> 101 <li>errors at run time that should be caught statically</li> 102 <li>no compilation means slow code</li> 103 </ul> 104 </div> 105 106 <h2 class="incremental">Can we combine the best of both?</h2> 107 </div> 108 109 <div class="slide"> 110 <h1>Go</h1> 111 112 <h2>Make the language fast.</h2> 113 <h2>Make the tools fast.</h2> 114 </div> 115 116 <div class="slide"> 117 <h1>Go Approach: Static Types</h1> 118 119 <h2>Static types, but declarations can infer type from expression:</h2> 120 121 <pre> 122 var one, hi = 1, "hello" 123 124 var double = func(x int) int { return x*2 } 125 </pre> 126 127 <h2>Not full Hindley-Milner type inference.</h2> 128 </div> 129 130 131 <div class="slide"> 132 <h1>Go Approach: Methods</h1> 133 134 <h2>Methods can be defined on any type.</h2> 135 136 <pre> 137 type Point struct { 138 X, Y float64 139 } 140 141 func (p Point) Abs() float64 { 142 return math.Sqrt(p.X*p.X + p.Y*p.Y) 143 } 144 </pre> 145 </div> 146 147 <div class="slide"> 148 <h1>Go Approach: Methods</h1> 149 150 <h2>Methods can be defined on any type.</h2> 151 152 <pre> 153 type MyFloat float64 154 155 func (f MyFloat) Abs() float64 { 156 v := float64(f) 157 if v < 0 { 158 v = -v 159 } 160 return v 161 } 162 </pre> 163 </div> 164 165 <div class="slide"> 166 <h1>Go Approach: Abstract Types</h1> 167 168 <h2>An interface type lists a set of methods. Any value with those methods satisfies the interface.</h2> 169 170 <pre> 171 type Abser interface { 172 Abs() float64 173 } 174 175 func AbsPrinter(a Abser) 176 </pre> 177 178 <h2>Can use Point or MyFloat (or ...):</h2> 179 180 <pre> 181 p := Point{3, 4} 182 AbsPrinter(p) 183 184 f := MyFloat(-10) 185 AbsPrinter(f) 186 </pre> 187 188 <h2>Notice that Point never declared that it implements Abser. It just does. Same with MyFloat.</h2> 189 </div> 190 191 <div class="slide"> 192 <h1>Go Approach: Packages</h1> 193 194 <h2>A Go program comprises one or more packages.</h2> 195 <h2>Each package is one or more source files compiled and imported as a unit.</h2> 196 <pre> 197 package draw 198 199 type Point struct { 200 X, Y int 201 } 202 </pre> 203 204 <pre> 205 package main 206 207 import "draw" 208 209 var p draw.Point 210 </pre> 211 </div> 212 213 <div class="slide"> 214 <h1>Go Approach: Visibility</h1> 215 216 <h2>Inside a package, all locally defined names are visible in all source files.</h2> 217 218 <h2>When imported, only the upper case names are visible.</h2> 219 220 <pre> 221 package draw 222 223 type <span style="color: black;">Point</span> struct { 224 <span style="color: black;">X</span>, <span style="color: black;">Y</span> int 225 dist float64 226 } 227 228 type cache map[Point] float64 229 </pre> 230 231 <h2>Clients that <code>import "draw"</code> can use the black names only.</h2> 232 233 <h2>“Shift is the new <code>public</code>.”</h2> 234 </div> 235 236 <div class="slide"> 237 <h1>Go Approach: Concurrency</h1> 238 239 <h2>Cheap to create a new flow of control (goroutine):</h2> 240 241 <pre> 242 func main() { 243 go expensiveComputation(x, y, z) 244 anotherExpensiveComputation(a, b, c) 245 } 246 </pre> 247 248 <h2>Two expensive computations in parallel.</h2> 249 </div> 250 251 <div class="slide"> 252 <h1>Go Approach: Synchronization</h1> 253 254 <h2>Use explicit messages to communicate and synchronize.</h2> 255 256 <pre> 257 func computeAndSend(ch chan int, x, y, z int) { 258 ch <- expensiveComputation(x, y, z) 259 } 260 261 func main() { 262 ch := make(chan int) 263 go computeAndSend(ch, x, y, z) 264 v2 := anotherExpensiveComputation(a, b, c) 265 v1 := <-ch 266 fmt.Println(v1, v2) 267 } 268 </pre> 269 <h2>Notice communication of result in addition to synchronization.</h2> 270 </div> 271 272 <div class="slide"> 273 <h1>Go Fast: Language</h1> 274 275 <h2 class="incremental">Static types: enough to compile well, but inferred much of the time.</h2> 276 277 <h2 class="incremental">Methods: on any type, orthogonal to type system.</h2> 278 279 <h2 class="incremental">Abstract types: interface values, relations inferred statically.</h2> 280 281 <h2 class="incremental">Visibility: inferred from case of name.</h2> 282 283 <h2 class="incremental">Concurrency: lightweight way to start new thread of control.</h2> 284 285 <h2 class="incremental">Synchronization: explicit, easy message passing.</h2> 286 287 <br/> 288 289 <h2 class="incremental">Lightweight feel of a scripting language but compiled.</h2> 290 </div> 291 292 <div class="slide"> 293 <h1>Compile fast</h1> 294 295 <div class="incremental"> 296 <h2>Observation: much of the compile time for a source file is spent processing 297 other, often unrelated files.</h2> 298 299 <h2>In C: <code>a.c</code> includes <code>b.h</code>, which includes <code>c.h</code>, which includes <code>d.h</code>. 300 </h2> 301 302 <h2>Except that it's more often a tree instead of a chain.</h2> 303 304 <h2>On my Mac (OS X 10.5.8, gcc 4.0.1):</h2> 305 <ul> 306 <li>C: <code>#include <stdio.h></code> reads 360 lines from 9 files. 307 <li>C++: <code>#include <iostream></code> reads 25,326 lines from 131 files. 308 <li>Objective C: <code>#include <Carbon/Carbon.h></code> reads 124,730 lines from 689 files. 309 </ul> 310 311 <h2>And we haven't done any real work yet!</h2> 312 313 <h2>Same story in Java, Python, but reading binaries instead of source files.</h2> 314 </div> 315 </div> 316 317 <div class="slide"> 318 <h1>Implementation: Summarize Dependencies</h1> 319 320 <pre> 321 package gui 322 323 import "draw" 324 325 type Mouse struct { 326 Loc draw.Point 327 Buttons uint 328 } 329 </pre> 330 <h2>Compiled form of <code>gui</code> summarizes the necessary part of <code>draw</code> (just <code>Point</code>).</h2> 331 332 </div> 333 334 <div class="slide"> 335 <h1>Implementation: Summarize Dependencies</h1> 336 337 <h2>Compiled form of <code>gui</code> summarizes the necessary part of <code>draw</code> (just <code>Point</code>). Pseudo-object:</h2> 338 339 <pre> 340 package gui 341 type draw.Point struct { 342 X, Y int 343 } 344 type gui.Mouse struct { 345 Loc draw.Point 346 Buttons uint 347 } 348 </pre> 349 350 <h2>A file that imports <code>gui</code> compiles without consulting <code>draw</code> or its dependencies.</h2> 351 352 <h2>In Go: <code>import "fmt"</code> reads <i>one</i> file: 184 lines summarizing types from 7 packages.</h2> 353 354 <h2>Tiny effect in this program but can be exponential in large programs.</h2> 355 </div> 356 357 <div class="slide"> 358 <h1>Compilation Demo</h1> 359 360 <h2>Build all standard Go packages: ~120,000 lines of code.</h2> 361 </div> 362 363 <div class="slide"> 364 <h1>Go Status</h1> 365 366 <div class="incremental"> 367 <div> 368 <h2>Open source:</h2> 369 <ul> 370 <li>released on November 10, 2009 371 <li>regular releases (~ weekly) 372 <li>all development done in public Mercurial repository 373 <li>outside contributions welcome 374 </ul> 375 </div> 376 377 <div> 378 <h2>Portable:</h2> 379 <ul> 380 <li>FreeBSD, Linux, OS X (x86, x86-64) 381 <li>(in progress) Linux arm, Native Client x86, Windows x86. 382 </ul> 383 </div> 384 385 <div> 386 <h2>Still in progress, experimental. Yet to come:</h2> 387 <ul> 388 <li>mature garbage collector 389 <li>generics? 390 <li>exceptions? 391 <li>unions or sum types? 392 </ul> 393 </div> 394 </div> 395 396 </div> 397 398 <div class="slide titlepage"> 399 <h1>Questions?</h1> 400 <br><br> 401 <center> 402 <img src="support/bumper640x360.png"> 403 </center> 404 <br><br> 405 <div style="color: #ffcc00;"> 406 <!-- <h3><i>rsc@google.com</i></h3> --> 407 </div> 408 </div> 409 410 </body></html>