-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
326 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# go-dotznt-talk | ||
Slides for the talk I gave at 20.10.2015 at the .net Zentral meetup in Lucerne | ||
Slides for the talk I gave at 20.10.2015 at the .net Zentral meetup in Lucerne. | ||
|
||
Use the [Go Present Tool](https://godoc.org/golang.org/x/tools/cmd/present) to compile and view. | ||
|
||
This work is licensed to you under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func sum(a []int, c chan int) { | ||
sum := 0 | ||
for _, v := range a { | ||
sum += v | ||
} | ||
c <- sum // send sum to c | ||
} | ||
|
||
func main() { | ||
a := []int{7, 2, 8, -9, 4, 0} | ||
|
||
c := make(chan int) | ||
go sum(a[:len(a)/2], c) | ||
go sum(a[len(a)/2:], c) | ||
x, y := <-c, <-c // receive from c | ||
|
||
fmt.Println(x, y, x+y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
ch := make(chan int) | ||
ch <- 1 | ||
ch <- 2 | ||
fmt.Println(<-ch) | ||
fmt.Println(<-ch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
ch := make(chan int, 2) | ||
ch <- 1 | ||
ch <- 2 | ||
fmt.Println(<-ch) | ||
fmt.Println(<-ch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
ch := make(chan string, 2) | ||
go ReadMessages(ch) | ||
go PrintMessages(ch) | ||
close(ch) | ||
} | ||
|
||
func ReadMessages(source chan<- string) { | ||
// writes messages into the channel | ||
source <- "New Message" | ||
} | ||
|
||
func PrintMessages(source <-chan string) { | ||
// prints messages | ||
fmt.Println(<-source) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func fibonacci(c, quit chan int) { | ||
x, y := 0, 1 | ||
for { | ||
select { | ||
case c <- x: | ||
x, y = y, x+y | ||
case <-quit: | ||
fmt.Println("quit") | ||
return | ||
default: | ||
fmt.Println(" .") | ||
time.Sleep(50 * time.Millisecond) | ||
} | ||
} | ||
} | ||
|
||
func main() { | ||
c := make(chan int) | ||
quit := make(chan int) | ||
go func() { | ||
for i := 0; i < 10; i++ { | ||
fmt.Println(<-c) | ||
} | ||
quit <- 0 | ||
}() | ||
fibonacci(c, quit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func say(s string) { | ||
for i := 0; i < 5; i++ { | ||
time.Sleep(100 * time.Millisecond) | ||
fmt.Println(s) | ||
} | ||
} | ||
|
||
func main() { | ||
go say("world") | ||
say("hello") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Variable | ||
var x interface{} // x is nil and has static type interface{} | ||
// Duck types variable | ||
var x = interface{} // static type of x is inferred from the RHS | ||
|
||
// Function | ||
func F(name Type, …)(Type, …){ … } | ||
func Printf(format string, params ...interface{}) // variadic function | ||
|
||
// Type | ||
type Sample struct { } | ||
|
||
// Interface | ||
type Sample interface { … } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type Vertex struct { | ||
X int // public member | ||
xi int // private member | ||
Y int | ||
} | ||
|
||
func (vertex *Vertex) Scale(int factor) { … } | ||
|
||
// Function Type definition | ||
type HandlerFunc func(request HttpRequest, response HttpResponse)( status int, err error ) | ||
|
||
type Reader interface { | ||
Read(b []byte) (n int, err error) | ||
} | ||
|
||
type FileReader struct { … } | ||
func (reader *FileReader) Read(b []byte) (n int, err error){ … } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
Go | ||
|
||
Michael Ingold | ||
Developer and Gopher | ||
github: enzian | ||
@michaelingold | ||
[email protected] | ||
|
||
* How Go came to life | ||
|
||
"Quote: When the three of us [Ken Thompson, Rob Pike, and Robert Griesemer] got started, it was pure research. The three of us got together and decided that we hated C++." | ||
|
||
Issues with C++ | ||
- Huge language (tons of features) | ||
- Concurrency is a pain (so developers try to avoid it) | ||
- Large code bases – long build times | ||
- Old and laborious tools (make and co.) | ||
|
||
* Adoption | ||
.image images/go_search.png | ||
.image images/geo.png | ||
|
||
* Adoption | ||
.image images/github.png | ||
|
||
* GOs trademarks | ||
|
||
- Compiled and stat. linked | ||
- Typesafe | ||
- Garbage collected | ||
- Plattform independent | ||
- Source Code only dependencies | ||
- Solid Tooling | ||
|
||
* Simplicity | ||
- Keywords: | ||
break default func interface select | ||
case defer go map struct | ||
chan else goto package switch | ||
const fallthrough if range type | ||
continue for import return var | ||
|
||
- Operators | ||
+ & += &= && == != ( ) | ||
- | -= |= || < <= [ ] | ||
* ^ *= ^= <- > >= { } | ||
/ << /= <<= ++ = := , ; | ||
% >> %= >>= -- ! ... . : | ||
&^ &^= | ||
|
||
* Simplicity (2) | ||
- Variable declaration | ||
.code code/declarations.go 2,2 | ||
- Duck typed variable | ||
.code code/declarations.go 4,4 | ||
- Function | ||
.code code/declarations.go 7,8 | ||
- Type | ||
.code code/declarations.go 11,11 | ||
- Interface | ||
.code code/declarations.go 14,14 | ||
|
||
* Typesystem | ||
- No polymophism | ||
- No generics | ||
- (almost) No Reflection | ||
- Interfaces! | ||
|
||
* Typedefinitions | ||
- Struct type definition | ||
.code code/typedefinitions.go 1,7 | ||
|
||
- Function Type definition | ||
.code code/typedefinitions.go 10,10 | ||
|
||
- Interface type defintion | ||
.code code/typedefinitions.go 12,14 | ||
|
||
* Interfaces | ||
Interfaces are satisfied implicitly - FileReader satifies the Reader interface | ||
|
||
.code code/typedefinitions.go 12,17 | ||
|
||
* FAQ: Types: | ||
Q : Does Go support generics? | ||
A : No! | ||
|
||
Q : How about polymophism? | ||
A : Nope! | ||
|
||
Q : … Reflection? | ||
A : Not really… | ||
|
||
* Concurrency | ||
|
||
- Goroutines | ||
- Channels | ||
- Classic synchronization structures | ||
|
||
* Go Routines | ||
.play code/concurrency1.go | ||
|
||
* Channels | ||
.play code/channels1.go | ||
|
||
* Buffered channels | ||
- Buffered | ||
.play code/channels2.go | ||
|
||
* Unbuffered channels | ||
.play code/channels3.go | ||
|
||
* Channel direction | ||
- Read-only channels | ||
.code code/channels4.go 17,20 | ||
- Write-only channels | ||
.code code/channels4.go 12,15 | ||
- TwoWay channels | ||
.code code/channels4.go 6,6 | ||
|
||
* Channel direction (2) | ||
.play code/channels4.go | ||
|
||
* Channels as control structures | ||
.play code/channels_quit.go 8,22 | ||
|
||
* Tooling | ||
"GO was designed with tooling in mind" | ||
Rob Pike | ||
|
||
* The GO command | ||
- Main command – prints some help. | ||
$ go | ||
- Compile and executes the given go file. | ||
$ go run main.go | ||
- Pulls in a new dependency from the given GIT or Hg repo into your GOPATH/src directory | ||
$ go get github.com/ahmetalpbalkan/go-linq | ||
- Compiles the given file (the the files in the current directory) and write the results to the GOPATH/pkg or /bin directory | ||
$ go build | ||
|
||
* The GO command (2) | ||
- Compiles and executes all tests in all the files in the current directory, their dependencies and subdirectories. | ||
$ go test ./.. | ||
- Generates code from existing source files (can be used to create ‘generics’) | ||
$ go generate | ||
|
||
* Editor Integration | ||
- Atom (go-plus) | ||
- Eclipse (GoClipse) | ||
- IntelliJ IDEA | ||
- Sublime | ||
- Notepad++ | ||
- Many others | ||
- coming soon: VS Code!! | ||
|
||
* Usefull Tools | ||
.link https://github.com/nsf/gocode GoCode | ||
Helps integrating with IDEs to enable context sensitive autocompletition. | ||
.link https://godoc.org/ GoDoc | ||
Godoc extracts and generates documentation for Go programs. | ||
.link https://github.com/FiloSottile/gvt Gvt | ||
simple Go vendoring tool which helps you manage your dependencies. | ||
|
||
.link https://golang.org/cmd/gofmt/ Gofmt | ||
Formats you code to match the go codeguidelines | ||
.link https://golang.org/cmd/vet/ GoVet | ||
Vet examines Go source code and reports suspicious constructs | ||
|
||
Many others at [[https://golang.org/cmd/]] | ||
|
||
* References | ||
- [[https://golang.org/]] | ||
- [[https://play.golang.org]] | ||
- [[https://gobyexample.com/]] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.