1
0
mirror of https://github.com/golang/go synced 2024-11-21 14:44:40 -07:00
go/doc/talks/go_talk-20100121.html
2010-01-27 15:50:29 -08:00

454 lines
9.7 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Go, Networked (January 21, 2010)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="font-size-adjustment" content="-1" />
<link rel="stylesheet" href="slidy.css"
type="text/css" media="screen, projection, print" />
<script src="slidy.js" type="text/javascript">
</script>
</head>
<body>
<!-- this defines the slide background -->
<div class="background">
<div class="header">
<!-- sized and colored via CSS -->
</div>
<div class="footer"></div>
</div>
<div class="slide titlepage">
<div style="height: 135px; width: 480px; overflow: hidden; position: fixed; top: auto; bottom: 10px; left: auto; right: 0; ">
<img src="../gordon/bumper480x270.png" style="margin: -135px 0 0 0;"/>
</div>
<!-- <img src="../google.png" style="position: fixed; top: auto; bottom: 30px; left: 20px; right: auto;"/> -->
<br/>
<img src="../go-logo-white.png">
<br/>
<br/>
<h1 style="padding-right: 0pt; margin-right: 0pt; color: #0066cc; font-size: 250%; border-bottom: 0px;">The Go Programming Language</h1>
<div style="color: #ffcc00;">
<h2>Russ Cox</h2>
<!-- <h3><i>rsc@google.com</i></h3> -->
<br/>
<h3>CNS Winter Research Review<br/><br/>January 21, 2010</h3>
<br/>
<br/>
<!--
<h4><i>click to start; then left/right arrow to change slides</i></h4> -->
</div>
</div>
<div class="slide">
<h1>Go</h1>
<h2>New</h2>
<h2>Experimental</h2>
<h2>Concurrent</h2>
<h2>Garbage-collected</h2>
<h2>Systems</h2>
<h2>Language</h2>
</div>
<div class="slide">
<h1>Hello, world</h1>
<pre>
package main
import "fmt"
func main() {
fmt.Printf("Hello, 世界\n")
}
</pre>
</div>
<div class="slide">
<h1>History</h1>
<h2>Design started in late 2007.</h2>
<h2>Implementation starting to work mid-2008.</h2>
<h2>Released as an open source project in November 2009.</h2>
<h2>Work continues.<h2>
<h2>Robert&nbsp;Griesemer, Ken&nbsp;Thompson, Rob&nbsp;Pike, Ian&nbsp;Lance&nbsp;Taylor, Russ&nbsp;Cox, many others</h2>
</div>
<div class="slide">
<h1>Goals and Motivation</h1>
<h2>Go fast!</h2>
<h2>Make programming fun again.</h2>
<h2>Targeted at systems software, broadly.</h2>
</div>
<div class="slide">
<h1>Why isn't programming fun?</h1>
<div class="incremental">
<h2>Compiled, statically-typed languages (C, C++, Java) require too much typing and too much typing:</h2>
<ul>
<li>verbose, lots of repetition</li>
<li>too much focus on type hierarchy</li>
<li>types get in the way as much as they help</li>
<li>compiles take far too long</li>
</ul>
</div>
<div class="incremental">
<h2>Dynamic languages (Python, JavaScript) fix these problems (no more types, no more compiler) but introduce others:</h2>
<ul>
<li>errors at run time that should be caught statically</li>
<li>no compilation means slow code</li>
</ul>
</div>
<h2 class="incremental">Can we combine the best of both?</h2>
</div>
<div class="slide">
<h1>Why a new language?</h1>
<div class="incremental">
<h2>No new systems language in 10+ years.</h2>
<h2>Current languages designed before ...</h2>
<h3>... rise of large-scale, networked and multicore computing</h3>
<h3>... rise of Internet-scale distributed development (many libraries)</h3>
</div>
</div>
<div class="slide">
<h1>Go</h1>
<h2>Make the language fast.</h2>
<h2>Make the tools fast.</h2>
</div>
<div class="slide">
<h1>Compilation Demo</h1>
<h2>Build all standard Go packages: ~120,000 lines of code.</h2>
</div>
<div class="slide">
<h1>Go in one slide</h1>
<h2 class="incremental">Lightweight syntax.</h2>
<h2 class="incremental">Static types: enough to compile well, but inferred much of the time.</h2>
<h2 class="incremental">Methods: on any type, orthogonal to type system.</h2>
<h2 class="incremental">Abstract types: interface values, relations inferred statically.</h2>
<h2 class="incremental">Visibility: inferred from case of name.</h2>
<h2 class="incremental">First-class functions.</h2>
<h2 class="incremental">Garbage collection.</h2>
<br/>
<h2 class="incremental">Lightweight feel of a scripting language but compiled.</h2>
</div>
<div class="slide">
<h1>Go, concurrently</h1>
<h2>Cheap to create a new flow of control (goroutine):</h2>
<pre>
func main() {
go expensiveComputation(x, y, z)
anotherExpensiveComputation(a, b, c)
}
</pre>
<h2>Two expensive computations in parallel.</h2>
</div>
<div class="slide">
<h1>Go, concurrently</h1>
<h2>Cheap to create a new flow of control (goroutine):</h2>
<pre>
for {
rw := l.Accept()
conn := newConn(rw, handler)
go conn.serve()
}
</pre>
<h2>Concurrent web server.</h2>
<h2>Network connections multiplexed onto epoll.</h2>
<ul>
<li>many blocked Read calls != many blocked OS threads</li>
</ul>
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>Use explicit messages to communicate and synchronize.</h2>
<pre>
func computeAndSend(ch chan int, x, y, z int) {
ch <- expensiveComputation(x, y, z)
}
func main() {
ch := make(chan int)
go computeAndSend(ch, x, y, z)
v2 := anotherExpensiveComputation(a, b, c)
v1 := <-ch
fmt.Println(v1, v2)
}
</pre>
<h2>Notice communication of result in addition to synchronization.</h2>
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client</h2>
<pre>
func (client *Client) Call(method string, args, reply interface{}) os.Error {
// Send RPC message.
call := client.Go(method, args, reply, nil)
// Read reply from Done channel.
<-call.Done
return call.Error
}
</pre>
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client demux</h2>
<pre>
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
</pre>
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client demux</h2>
<pre>
func (client *Client) input() {
for {
<font style="color: black;">resp := client.readResponse()</font>
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
</pre>
<h2>Read response from network.</h2
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client demux</h2>
<pre>
func (client *Client) input() {
for {
resp := client.readResponse()
<font style="color: black;">client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()</font>
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
</pre>
<h2>Look up request by sequence number.</h2
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client demux</h2>
<pre>
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
<font style="color: black;">if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)</font>
c.Done <- c
}
}
</pre>
<h2>Decode response fields from payload.</h2
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client demux</h2>
<pre>
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
<font style="color: black;">c.Done <- c</font>
}
}
</pre>
<h2>Tell client that it finished.</h2
</div>
<div class="slide">
<h1>Go, synchronized</h1>
<h2>RPC client demux</h2>
<pre>
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
</pre>
<h2>Can create multiple Calls with same Done channel
and distinguish which finished by inspecting value sent on channel.
</h2>
</div>
<div class="slide">
<h1>Goroutine demo</h1>
<h2>Chain together 100,000 goroutines connected by 100,001 channels.</h2>
<h2>Send a value to one end of the chain.</h2>
<h2>Each passes it along, increments.</h2>
<h2>Receive value out the other end of the chain.</h2>
</div>
<div class="slide">
<h1>Go Status</h1>
</div>
<div class="slide">
<h1>Go Status</h1>
<h2>Open source:</h2>
<ul>
<li>released on November 10, 2009
<li>regular releases (~ weekly)
<li>all development done in public Mercurial repository
<li>outside contributions welcome
<li>two independent compiler implementations
<li>XML, JSON, HTTP, TLS/SSL, native RPC, (network channels,) ...
</ul>
</div>
<div class="slide">
<h1>Go Status</h1>
<h2>Open source</h2>
<h2>Portable:</h2>
<ul>
<li>FreeBSD, Linux, OS X (x86, x86-64)
<li>(in progress) Linux arm, Native Client x86, Windows x86.
</ul>
</div>
<div class="slide">
<h1>Go Status</h1>
<h2>Open source</h2>
<h2>Portable</h2>
<h2>Still in progress, experimental. Yet to come:</h2>
<ul>
<li>production garbage collector
<li>generics?
<li>exceptions?
<li>unions or sum types?
</ul>
</div>
<div class="slide titlepage">
<h1>Questions?</h1>
<br><br>
<center>
<img src="../gordon/bumper640x360.png">
</center>
<br><br>
<div style="color: #ffcc00;">
<!-- <h3><i>rsc@google.com</i></h3> -->
</div>
</div>
</body></html>