Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2864)

Delta Between Two Patch Sets: 2014/go4java.slide

Issue 111050043: code review 111050043: go.talks: add "Go for Javaneros" (Closed)
Left Patch Set: diff -r c636a8a8316f https://code.google.com/p/go.talks Created 9 years, 8 months ago
Right Patch Set: diff -r f10c43fe60f9 https://code.google.com/p/go.talks Created 9 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | 2014/go4java/BadInheritance.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 Go for Javaneros (Javaïstes?) 1 Go for Javaneros (Javaïstes?)
2 #go4java 2 #go4java
3 3
4 Francesc Campoy 4 Francesc Campoy
5 Gopher and Developer Advocate 5 Gopher and Developer Advocate
6 Google 6 Google
7 @francesc 7 @francesc
8 campoy@golang.org 8 campoy@golang.org
9 9
10 * What is Go? 10 * What is Go?
11 11
12 Go is an open-source programming language 12 Go is an open-source programming language
13 13
14 - created at Google, 14 - created at Google,
15 - to solve Google-scale problems. 15 - to solve Google-scale problems.
16 16
17 .image go4java/img/gopher.jpg 450 800 17 .image go4java/img/gopher.jpg 450 _
18 18
19 * Who uses Go? 19 * Who uses Go?
20 20
21 Google: 21 Google:
22 22
23 - YouTube (no gophers, no kittens!) 23 - YouTube
24 - dl.google.com 24 - dl.google.com
25 25
26 Others: 26 Others:
27 27
28 - dotCloud (Docker) 28 - dotCloud (Docker)
29 - SoundCloud 29 - SoundCloud
30 - Canonical 30 - Canonical
31 - CloudFlare 31 - CloudFlare
32 - Mozilla 32 - Mozilla
33 - ... 33 - ...
34 34
35 [[http://golang.org/wiki/GoUsers][golang.org/wiki/GoUsers]] 35 [[http://golang.org/wiki/GoUsers][golang.org/wiki/GoUsers]]
36 36
37 * Who uses Go? 37 * Who uses Go?
38 38
39 .iframe http://www.google.com/trends/fetchComponent?hl=en-US&q=golang&content=1& cid=TIMESERIES_GRAPH_0&export=5&w=600&h=400 600 1200 39 .image go4java/img/trends.png _ 800
40
41 .caption Google Trends for [[http://www.google.com/trends/explore#q=golang][gola ng]]
40 42
41 * Why Go? 43 * Why Go?
42 44
43 * Simplicity 45 * Simplicity
44 46
45 Minimal design 47 Minimal design
46 48
47 .image go4java/img/perfection.jpg 49 .image go4java/img/perfection.jpg
48 50
49 * Consistency 51 * Consistency
50 52
51 Orthogonal features 53 Orthogonal features
52 54
53 .image go4java/img/lego.jpg 55 .image go4java/img/lego.jpg 400 _
56
57 .caption By Kenny Louie from Vancouver, Canada [[http://creativecommons.org/lice nses/by/2.0][CC-BY-2.0]], via Wikimedia Commons
54 58
55 * Readability 59 * Readability
56 60
57 “The ratio of time spent reading (code) versus writing is well over 10 to 1 ... (therefore) making it easy to read makes it easier to write.” 61 “The ratio of time spent reading (code) versus writing is well over 10 to 1 ... (therefore) making it easy to read makes it easier to write.”
58 ― Robert C. Martin 62 ― Robert C. Martin
59 63
60 .image go4java/img/piet.png 500 600· 64 .image go4java/img/piet.png 500 600·
61 65
62 * Safety 66 * Safety
63 67
64 Type safety, no buffer overflows, no pointer arithmetic. 68 Type safety, no buffer overflows, no pointer arithmetic.
65 69
66 .image go4java/img/baby.jpg 500 500 70 .image go4java/img/baby.jpg 500 500
67 71
68 * Built-in concurrency features 72 * Built-in concurrency features
69 73
70 “In a concurrent world, imperative is the wrong default!” - Tim Sweeney 74 “In a concurrent world, imperative is the wrong default!” - Tim Sweeney
71 75
72 Concurrent Sequential Processes - Hoare (1978) 76 Communicating Sequential Processes - Hoare (1978)
73 77
74 .image go4java/img/conc.jpg _ 1000 78 .image go4java/img/conc.jpg _ 1000
75 79
76 * Speed 80 * Speed
77 81
78 .image go4java/img/fast.jpg 500 _ 82 .image go4java/img/fast.jpg 500 _
79 83
80 * Let's dive in 84 * Let's dive in
81 85
82 * Go and Java common aspects 86 * Go and Java common aspects
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 183 }
180 184
181 Made clearer by naming the return values: 185 Made clearer by naming the return values:
182 186
183 func div(den, div int) (q, rem int) 187 func div(den, div int) (q, rem int)
184 return a / b, a % b 188 return a / b, a % b
185 } 189 }
186 190
187 * Method declarations 191 * Method declarations
188 192
189 » func ([receiver]) [name] ([param]*) ([return]*) 193 » func ([receiver]) [name] ([params]) ([return values])
190 194
191 A method on a struct: 195 A method on a struct:
192 196
193 func (p Person) Major() bool { 197 func (p Person) Major() bool {
194 return p.age >= 18 198 return p.age >= 18
195 } 199 }
196 200
197 But also a method on a `float64`: 201 But also a method on a `float64`:
198 202
199 func (c Celsius) Freezing() bool { 203 func (c Celsius) Freezing() bool {
200 return c <= 0 204 return c <= 0
201 } 205 }
202 206
203 _Constraint:_ Methods can be defined *only* on types declared in the same packag e. 207 _Constraint:_ Methods can be defined *only* on types declared in the same packag e.
204 208
205 // This won't compile 209 // This won't compile
206 func (s string) Length() int { return len(s) } 210 func (s string) Length() int { return len(s) }
207 211
208 * Wait, pointers? 212 * Wait, pointers?
209 213
210 Use `&` to obtain the address of a variable. 214 Use `&` to obtain the address of a variable.
211 215
212 a := "hello" 216 a := "hello"
213 p := &a 217 p := &a
214 218
215 Use `*` to redeference the pointer. 219 Use `*` to dereference the pointer.
216 220
217 fmt.Print(*p + ", world") 221 fmt.Print(*p + ", world")
218 222
219 No pointer arithmetic, no pointers to unsafe memory. 223 No pointer arithmetic, no pointers to unsafe memory.
220 224
221 a := "hello" 225 a := "hello"
222 p := &a 226 p := &a
223 227
224 p += 4 // no, you can't 228 p += 4 // no, you can't
225 229
226 * Why pointers? 230 * Why pointers?
227 231
228 Control what you pass to functions. 232 Control what you pass to functions.
229 233
230 - passing values, no side-effects: 234 - passing values, no side-effects:
231 235
232 func double(x int) { 236 func double(x int) {
233 x *= 2 237 x *= 2
234 } 238 }
235 239
236 - passing pointers: side-effects possible: 240 - passing pointers: side-effects possible:
237 241
238 » func double(x int) { 242 » func double(x *int) {
239 *x *= 2 243 *x *= 2
240 } 244 }
241 245
242 Control your memory layout. 246 Control your memory layout.
243 247
244 - compare []Person and []*Person 248 - compare []Person and []*Person
245 249
246 * Method declarations on pointers 250 * Method declarations on pointers
247 251
248 Receivers behave like any other argument. 252 Receivers behave like any other argument.
249 253
250 Pointers allow modifying the pointed receiver: 254 Pointers allow modifying the pointed receiver:
251 255
252 func (p *Person) IncAge() { 256 func (p *Person) IncAge() {
253 p.age++ 257 p.age++
254 } 258 }
255 259
256 The method receiver is a copy of a pointer (pointing to the same address). 260 The method receiver is a copy of a pointer (pointing to the same address).
257 261
258 Method calls on nil receivers are perfectly valid (and useulf!). 262 Method calls on nil receivers are perfectly valid (and useulf!).
u 2014/07/16 11:42:04 useulf should be useful.
campoy 2014/07/16 17:41:30 Done.
259 263
260 func (p *Person) Name() string { 264 func (p *Person) Name() string {
261 if p == nil { 265 if p == nil {
262 return "anonymous" 266 return "anonymous"
263 } 267 }
264 return p.name 268 return p.name
265 } 269 }
266 270
267 * Interfaces 271 * Interfaces
268 272
(...skipping 16 matching lines...) Expand all
285 } 289 }
286 290
287 * It's all about satisfaction 291 * It's all about satisfaction
288 292
289 Java interfaces are satisfied *explicitly*. 293 Java interfaces are satisfied *explicitly*.
290 294
291 Go interfaces are satisfied *implicitly*. 295 Go interfaces are satisfied *implicitly*.
292 296
293 .image //upload.wikimedia.org/wikipedia/commons/thumb/2/29/Rolling_Stones_09.jpg /512px-Rolling_Stones_09.jpg _ 512 297 .image //upload.wikimedia.org/wikipedia/commons/thumb/2/29/Rolling_Stones_09.jpg /512px-Rolling_Stones_09.jpg _ 512
294 298
295 Picture by Gorupdebesanez [[http://creativecommons.org/licenses/by-sa/3.0][CC-BY -SA-3.0]], via [[http://commons.wikimedia.org/wiki/File%3ARolling_Stones_09.jpg] [Wikimedia Commons]] 299 .caption Picture by Gorupdebesanez [[http://creativecommons.org/licenses/by-sa/3 .0][CC-BY-SA-3.0]], via [[http://commons.wikimedia.org/wiki/File%3ARolling_Stone s_09.jpg][Wikimedia Commons]]
296 300
297 * Go: implicit satisfaction 301 * Go: implicit satisfaction
298 302
299 _If_a_type_defines_all_the_methods_of_an_interface,_the_type_satisfies_that_inte rface._ 303 _If_a_type_defines_all_the_methods_of_an_interface,_the_type_satisfies_that_inte rface._
300 304
301 Benefits: 305 Benefits:
302 306
303 - fewer dependencies 307 - fewer dependencies
304 - no type hierarchy 308 - no type hierarchy
305 - organic composition 309 - organic composition
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 It is more general. 489 It is more general.
486 490
487 - Struct embedding of interfaces. 491 - Struct embedding of interfaces.
488 492
489 * Is struct embedding like inheritance? 493 * Is struct embedding like inheritance?
490 494
491 Struct embedding is selective. 495 Struct embedding is selective.
492 496
493 .code go4java/writecounter.go /WriteCounter/,/MAIN/ 497 .code go4java/writecounter.go /WriteCounter/,/MAIN/
494 498
495 WriteCounter can be used with any io.ReadWriteCloser. 499 WriteCounter can be used with any `io.ReadWriter`.
496 500
497 .play go4java/writecounter.go /func main/,/^}/ 501 .play go4java/writecounter.go /func main/,/^}/
498 502
499 * Easy mocking 503 * Easy mocking
500 504
501 What if we wanted to fake a part of a `net.Conn`? 505 What if we wanted to fake a part of a `net.Conn`?
502 506
503 type Conn interface { 507 type Conn interface {
504 Read(b []byte) (n int, err error) 508 Read(b []byte) (n int, err error)
505 Write(b []byte) (n int, err error) 509 Write(b []byte) (n int, err error)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 Concurrency is awesome, and you should check it out. 657 Concurrency is awesome, and you should check it out.
654 658
655 * What to do next? 659 * What to do next?
656 660
657 Learn Go on your browser with [[http://tour.golang.org][tour.golang.org]] 661 Learn Go on your browser with [[http://tour.golang.org][tour.golang.org]]
658 662
659 Find more about Go on [[http://golang.org][golang.org]] 663 Find more about Go on [[http://golang.org][golang.org]]
660 664
661 Join the community at [[https://groups.google.com/forum/#!forum/Golang-nuts][gol ang-nuts]] 665 Join the community at [[https://groups.google.com/forum/#!forum/Golang-nuts][gol ang-nuts]]
662 666
663 Link to the slides [[http://campoy.cat/go4java][campoy.cat/go4java]] 667 Link to the slides [[http://talks.golang.org/2014/go4java.slide]]
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b