mirror of
https://github.com/vbatts/talks.git
synced 2025-04-18 20:54:35 +00:00
2015-devnation: final changes
This commit is contained in:
parent
1b8e5c7a36
commit
8e251effd9
5 changed files with 152 additions and 8 deletions
39
2015/06-devnation-golang-good-bad-ugly/marshal.go
Normal file
39
2015/06-devnation-golang-good-bad-ugly/marshal.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// +build OMIT
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// START1 OMIT
|
||||||
|
type MyStruct struct {
|
||||||
|
Name string `json:"myname"`
|
||||||
|
DateTime time.Time `json:"mytime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// STOP1 OMIT
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var (
|
||||||
|
buf []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
// START2 OMIT
|
||||||
|
m := MyStruct{"vbatts", time.Now()}
|
||||||
|
fmt.Printf("%#v\n", m)
|
||||||
|
if buf, err = json.Marshal(m); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%s\n", string(buf))
|
||||||
|
|
||||||
|
var m1 MyStruct
|
||||||
|
if err = json.Unmarshal(buf, &m1); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%#v\n", m1)
|
||||||
|
|
||||||
|
// STOP2 OMIT
|
||||||
|
}
|
12
2015/06-devnation-golang-good-bad-ugly/marshal_ugly.go
Normal file
12
2015/06-devnation-golang-good-bad-ugly/marshal_ugly.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// +build OMIT
|
||||||
|
package main
|
||||||
|
|
||||||
|
// START1 OMIT
|
||||||
|
type Namer interface {
|
||||||
|
Name() string
|
||||||
|
}
|
||||||
|
|
||||||
|
// STOP1 OMIT
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
}
|
39
2015/06-devnation-golang-good-bad-ugly/marshal_xml.go
Normal file
39
2015/06-devnation-golang-good-bad-ugly/marshal_xml.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// +build OMIT
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// START1 OMIT
|
||||||
|
type MyStruct struct {
|
||||||
|
Name string `json:"myname"`
|
||||||
|
DateTime time.Time `json:"mytime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// STOP1 OMIT
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var (
|
||||||
|
buf []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
// START2 OMIT
|
||||||
|
m := MyStruct{"vbatts", time.Now()}
|
||||||
|
fmt.Printf("%#v\n", m)
|
||||||
|
if buf, err = xml.Marshal(m); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%s\n", string(buf))
|
||||||
|
|
||||||
|
var m1 MyStruct
|
||||||
|
if err = xml.Unmarshal(buf, &m1); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%#v\n", m1)
|
||||||
|
|
||||||
|
// STOP2 OMIT
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ Golang - the good, the bad, the ugly
|
||||||
25 June 2015 - devnation.org
|
25 June 2015 - devnation.org
|
||||||
|
|
||||||
Vincent Batts
|
Vincent Batts
|
||||||
Developer
|
Engineer
|
||||||
@vbatts
|
@vbatts
|
||||||
vbatts@redhat.com
|
vbatts@redhat.com
|
||||||
https://github.com/vbatts/talks
|
https://github.com/vbatts/talks
|
||||||
|
@ -13,7 +13,7 @@ https://github.com/vbatts/talks
|
||||||
Login: vbatts Name: Vincent Batts
|
Login: vbatts Name: Vincent Batts
|
||||||
Such mail.
|
Such mail.
|
||||||
Plan:
|
Plan:
|
||||||
Contribute with right, joyful effort
|
OHMAN
|
||||||
$> id -Gn
|
$> id -Gn
|
||||||
vbatts devel openshift docker
|
vbatts devel openshift docker
|
||||||
|
|
||||||
|
@ -82,14 +82,24 @@ https://github.com/vbatts/talks
|
||||||
.play ./pingpong.go /STARTMAIN1/,/STOPMAIN1/
|
.play ./pingpong.go /STARTMAIN1/,/STOPMAIN1/
|
||||||
.link http://talks.golang.org/2013/advconc.slide Sameer Ajmani - Advanced Concurrency
|
.link http://talks.golang.org/2013/advconc.slide Sameer Ajmani - Advanced Concurrency
|
||||||
|
|
||||||
|
* Marshalling
|
||||||
|
|
||||||
|
.code ./marshal.go /START1/,/STOP1/
|
||||||
|
.play ./marshal.go /START2/,/STOP2/
|
||||||
|
|
||||||
|
* Marshalling
|
||||||
|
|
||||||
|
.code ./marshal_xml.go /START1/,/STOP1/
|
||||||
|
.play ./marshal_xml.go /START2/,/STOP2/
|
||||||
|
|
||||||
*
|
*
|
||||||
.image ./kanye_imma_bookmarklet.png 320 _
|
.image ./kanye_imma_bookmarklet.png 320 _
|
||||||
|
|
||||||
- easy learning curve
|
- easy learning curve
|
||||||
|
- fast compiles
|
||||||
- `go get`
|
- `go get`
|
||||||
- cross-compiles
|
- cross-compiles
|
||||||
|
|
||||||
|
|
||||||
* Bad
|
* Bad
|
||||||
|
|
||||||
*
|
*
|
||||||
|
@ -103,7 +113,7 @@ Addresses different concern than distributions
|
||||||
|
|
||||||
* lack of generics?
|
* lack of generics?
|
||||||
# i don't feel strongly about this, though many do
|
# i don't feel strongly about this, though many do
|
||||||
- interfaces - are enough for most
|
- interfaces - good enough for most
|
||||||
- go1.4 introduced go:generate
|
- go1.4 introduced go:generate
|
||||||
# produce code for Set, Graph etc, for the types needed, but at compile time. No need to reflect.
|
# produce code for Set, Graph etc, for the types needed, but at compile time. No need to reflect.
|
||||||
|
|
||||||
|
@ -112,18 +122,22 @@ Addresses different concern than distributions
|
||||||
- gdb is there, sort of
|
- gdb is there, sort of
|
||||||
- some known debugging tools for ELF are not useful
|
- some known debugging tools for ELF are not useful
|
||||||
- fmt.Printf("%#v\n", ...)
|
- fmt.Printf("%#v\n", ...)
|
||||||
|
- go1.5 has much focus on DWARF symbols
|
||||||
|
|
||||||
* Concurrency and GC
|
* Concurrency and GC
|
||||||
|
|
||||||
Calls like setns(2) are rough
|
- Calls like setns(2) are rough
|
||||||
|
|
||||||
|
|
||||||
(yes, even with runtime.LockOSThread())
|
(yes, even with runtime.LockOSThread())
|
||||||
|
|
||||||
|
- go1.5 will greatly improve garbage collections
|
||||||
|
(performance and pauses)
|
||||||
|
|
||||||
|
|
||||||
* Fork/Exec
|
* Fork/Exec
|
||||||
|
|
||||||
Not Separate, but together
|
Not Separate, but together
|
||||||
|
|
||||||
|
|
||||||
* Ugly? (maybe just new)
|
* Ugly? (maybe just new)
|
||||||
|
|
||||||
*
|
*
|
||||||
|
@ -139,6 +153,9 @@ or files with *_linux.go like suffix.
|
||||||
|
|
||||||
More like extern.
|
More like extern.
|
||||||
|
|
||||||
|
* pointer reciever
|
||||||
|
|
||||||
|
.play ./ugly2.go /START1/,/STOP1/
|
||||||
|
|
||||||
* _
|
* _
|
||||||
|
|
||||||
|
@ -176,11 +193,21 @@ channel
|
||||||
|
|
||||||
.code ./primitive3.go /START2/,/STOP2/
|
.code ./primitive3.go /START2/,/STOP2/
|
||||||
|
|
||||||
|
* interfaces and marshalling
|
||||||
|
|
||||||
|
.code ./marshal_ugly.go /START1/,/STOP1/
|
||||||
|
|
||||||
|
|
||||||
* Conclusions?
|
* Conclusions?
|
||||||
|
|
||||||
|
* Conclusions?
|
||||||
|
|
||||||
|
- easy to adopt
|
||||||
|
- enjoyable to learn
|
||||||
|
|
||||||
* use-case
|
* use-case
|
||||||
|
|
||||||
- like all languages, align with you use-case
|
|
||||||
- get familiar enough to like and dislike it
|
- get familiar enough to like and dislike it
|
||||||
|
- like all languages, choose the one that aligns with your use-case
|
||||||
- don't be afraid to try it out
|
- don't be afraid to try it out
|
||||||
|
|
||||||
|
|
27
2015/06-devnation-golang-good-bad-ugly/ugly2.go
Normal file
27
2015/06-devnation-golang-good-bad-ugly/ugly2.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// +build OMIT
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// START1 OMIT
|
||||||
|
type Message string
|
||||||
|
|
||||||
|
func (m Message) WriteTo(w io.Writer) (int, error) {
|
||||||
|
return w.Write([]byte(m))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Message) Reset() {
|
||||||
|
m = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
m := Message("Hello World\n")
|
||||||
|
m.WriteTo(os.Stdout)
|
||||||
|
m.Reset()
|
||||||
|
m.WriteTo(os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// STOP1 OMIT
|
Loading…
Add table
Reference in a new issue