SlideShare uma empresa Scribd logo
1 de 72
Baixar para ler offline
Go. Why it
goes?
1
About me
Serhii Pichkurov
●6+ years of experience
●Mostly backend
●~ 1 year with Go
2
Agenda
● Go is not C, not Java, not anything
● Gopher
● Rob Pike argument
● Main ideas
● Concurrency model
● Tools
● Issues and gotchas 3
Characteristics
Go (often referred to as golang) is:
4
●Clean procedural language designed
for scalable cloud software
●open source
●statically typed with duck typing
Characteristics
●CSP(communicating sequential processes) as
concurrent model
●with garbage collection
●created at Google in 2007 by Robert
Griesemer(V8), Rob Pike(UNIX, UTF-8), and Ken
Thompson(UNIX, regexp)
5
Characteristics
●compiled
●two compilers: "gc"(many platforms including
smartphones) and “gccgo”(more optimizations,
more processors)
●Linux, OS X, FreeBSD, Windows and more
6
Motivated by Google’s needs:
Why new lang?
7
● No surprises
● Efficiency
● Safety
● Concurrency
● Scalability
● Fast development cycle
● A cute mascot
Who uses Go at Google?
Lots of projects. Thousands of Go programmers. Millions
of lines of Go code.
Public examples:
● Kubernetes
● SPDY proxy for Chrome on mobile devices
● dl.google.com is written in Go
● YouTube Vitess MySQL balancer
8
Who uses Go besides Google?
9
Products written in Go
10
Go use-cases
● Cloud/Networking - routers, proxies, etc
● Distributed services and storages
● Internal infrastructures
● Microservices (with frameworks, like
GoKit)
● Containers and orchestration
● Command-line tools
11
Mascot: the gopher
12
Rob Pike
13
Rob Pike argument
● Go is different
● Go does not try to be like the other
languages
● Go does not compete on features
● As of Go 1, the language is fixed
14
Active Development
15
GC in Go 1.6
16https://talks.golang.org/2016/state-of-go.slide
Everything is passed by
value
17
Go elements
● concrete data types
● functions and methods
● interfaces
● structs
● packages
● concurrency
● good tools, fast builds
All the pieces feel simple in practice
18
Types
●bool
●string
●int int8 int16 int32 int64
uint uint8 uint16 uint32 uint64
●byte //alias for uint8
●rune //alias for int32, Unicode char
●float32 float64
●complex32 complex64
19
var c, python, java bool
20
k := 3
c, python, java := true, false, "no!"
21
func do_something() (string, int) {
return "result", 0
}
first, second := do_something()
Unused variables
or imports —
compilation error
22
Arrays
An array's length is part of its type, so arrays
cannot be resized.
var arr [5]int
arr[4] = 42
23
Slices
A slice, on the other hand, is a dynamically-sized,
flexible view(reference) into the elements of an array
var foo []int
24
Slices
foo := make([]int, 5)
25
foo[3] = 42
foo[4] = 100
Slices
bytes := [5]byte{} // array
var slice = bytes[2:4]
names := []string{"leto", "paul", "teg"}
c := make([]string, len(names))
copy(c, names)
names = append(names,"ioav")
26
Maps
m = make(map[string]int) // declare
m["route"] = 66 // put
i := m["route"] // get
delete(m, "route")
_, ok := m["route"] //check is present
27
Maps
Important to remember: when no value is
assigned to key, zero value is returned
28
for key, value := range m { //iterate
fmt.Println("Key:", key, "Value:", value)
}
commits := map[string]int{ //static population
"gri": 1908,
"adg": 912,
}
29
Maps
Interfaces
Just a set of methods. No data. Simple idea, but more
complex than expected.
type Reader interface {
Read(p []byte) (n int, err error)
}
_, err := reader.Read(p)
30
Structs
type Person struct {
FirstName string
LastName string
}
person := Person{FirstName:"title", LastName:"http:..."}
31
Tags aka annotations
type Person struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
MiddleName string `json:"-"`
}
32
xml:"FirstName"`
xml:"LastName"`
xml:"MiddleName"`
Pointers
A pointer holds the memory address of a variable.
The & operator generates a pointer to its operand:
i := 42
p = &i
The * operator denotes the pointer's underlying value:
fmt.Println(*p) // read i through the pointer p
*p = 21 // set i through the pointer p
33
Receivers
type Server struct {
...
}
34
func (srv *Server) Close() error {
...
}
func (srv Server) Name() string {
...
}
Demo
35
Packages
We can import one or more package, there are three types:
system, local and remote.
System – out of the box. Like http, testing, etc
Local – in your repository, no need to use full path.
Remote – has complete import path pointing to the server.
To import remote package:
import "github.com/nf/wav"
36
Getting dependencies
For remote package use go get to fetch into workspace.
go get github.com/nf/wav
Other operations also done via go CLI tool:
go build
go test
go run
and more
37
38
export GOPATH = $HOME/go_workspace
Concurrency
Based on CSP that was first described in a 1978 paper by
Tony Hoare.
Has three elements:
● coroutines (execution)
● channels (communication)
● select (coordination)
39
“
Don't communicate by
sharing memory, share
memory by communicating
40
Goroutines
Start a goroutine with the go keyword:
go function(args)
Like garbage collection, eliminate considerations from the
programmer's concern:
● no stack size
● no return or completion status
● no mechanism for management
● no "ID"
41
Goroutines
●Goroutines are like lightweight threads.
●Go programs can have hundreds of
thousands of them
●The Go runtime schedules goroutines
onto OS threads
●Blocked goroutines don't use a thread
42
Channels
Channels provide communication between
goroutines.
c := make(chan string)
// goroutine 1
c <- "hello!"
// goroutine 2
s := <-c
fmt.Println(s) // "hello!"
43
Select
A select statement blocks until one of its cases can run, then it
executes that case.
msg := "hi"
select {
case n := <-in:
fmt.Println("received", n)
case out <- msg:
fmt.Println("sent", msg)
}
44
Demo time
45
46
Go and Java have much in common
● C family (imperative, braces)
● Statically typed
● Garbage collected
● Memory safe (nil references,
runtime bounds checks)
47
● Variables are always initialized
(zero/nil/false)
● Methods
● Interfaces
● Type assertions (instanceof)
● Reflection
48
Go and Java have much in common
Go differs from Java in several ways
● Programs compile to machine code. There's no VM.
● Statically linked binaries
● Multiple return
● Error handling
● Bit different GC(no compaction)
49
Go intentionally leaves out many features
● No classes
● No ‘implements’ keyword
● No final
● No exceptions
● No user-defined generics
50
Exceptions go away
● no exceptions by design
● handling with multiple return
● panic!
type error interface {
Error() string
}
51
Errors design
rpm, err := rpm.OpenPackageFile(localPath)
if err != nil {
log.Error("Failed to read RPM headers: %v", err)
return
}
file, err = file.ReadAt(archiveHead, int64(headerEnd))
if err != nil {
log.Error("Invalid archive head head: %v", err)
return
} 52
Tools
53
go get is great,
but we need
more
54
Vendoring
server-one uses the mux package in $GOPATH/src/github.com/gorilla/mux.
server-two uses the mux package in vendor.
$GOPATH
src/
server-one/
main.go (import "github.com/gorilla/mux")
server-two/
main.go (import "github.com/gorilla/mux")
vendor/
github.com/
gorilla/
mux/
...
55
Glide for Package Management
● Semantic Versions and Ranges
● Git, Bzr, Hg, Svn
● Works with Go toolchain
● Leverages vendor directory
● Imports from Godep, GB, GPM, Gom
● Private Repos and Forks
56
Go tools support
●go fmt
●goimports
●go lint or gometalinter
●godoc lookups
●go generate
●many more
●easy to write your own
57
IDE
There's no "Go IDE". Go tools meet you where you are.
●Eclipse
●JetBrains(GoLand)
●Atom
●Emacs
●Vim
●many others
58
My experience
Project that searches for vulnerabilities inside artifacts
●microservices
●RabbitMQ
●MongoDB/PostgreSQL
●REST API
●work with files and archives
●Docker
●34860 lines of code
59
Issues and
gotchas
60
Pointers, pointers to
pointers, more
pointers.
61
Nil pointer is still
there and happens in
runtime
62
No generics
63
“
If you want to do
something expensive —
do it explicitly
64
Missing comma in
multi-line Slice,
Array, and Map
Literals
65
func main() {
x := []int{
1,
2 //error
}
_ = x
}
66
Summary
67
“
I’m impressed about how easy
people can pick it up and start
being productive in a project ,
it’s also very easy to deploy
David Cuadrado, Authy
68
Simple can be expressive
69
Simplicity is complicated but
the clarity is worth the fight
70
Thanks!
71
Q&A
72

Mais conteúdo relacionado

Mais procurados

C Under Linux
C Under LinuxC Under Linux
C Under Linuxmohan43u
 
Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11corehard_by
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersJen Yee Hong
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in RSamuel Bosch
 
Go Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialGo Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialRomin Irani
 
Take advantage of C++ from Python
Take advantage of C++ from PythonTake advantage of C++ from Python
Take advantage of C++ from PythonYung-Yu Chen
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Yung-Yu Chen
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - englishJen Yee Hong
 
Practicing Python 3
Practicing Python 3Practicing Python 3
Practicing Python 3Mosky Liu
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetupsource{d}
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013Mosky Liu
 
С++ without new and delete
С++ without new and deleteС++ without new and delete
С++ without new and deletePlatonov Sergey
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in GoAmr Hassan
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with pythonroskakori
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright Andrei Alexandrescu
 

Mais procurados (20)

C Under Linux
C Under LinuxC Under Linux
C Under Linux
 
Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
Vim and Python
Vim and PythonVim and Python
Vim and Python
 
Go Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialGo Language Hands-on Workshop Material
Go Language Hands-on Workshop Material
 
Take advantage of C++ from Python
Take advantage of C++ from PythonTake advantage of C++ from Python
Take advantage of C++ from Python
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
 
GCC, GNU compiler collection
GCC, GNU compiler collectionGCC, GNU compiler collection
GCC, GNU compiler collection
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Practicing Python 3
Practicing Python 3Practicing Python 3
Practicing Python 3
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
GCC
GCCGCC
GCC
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
 
С++ without new and delete
С++ without new and deleteС++ without new and delete
С++ without new and delete
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 

Semelhante a Go. why it goes v2

Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016maiktoepfer
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGlobalLogic Ukraine
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golangBasil N G
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoRodolfo Carvalho
 
Debugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDBDebugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDBbmbouter
 
Python VS GO
Python VS GOPython VS GO
Python VS GOOfir Nir
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPyDong-hee Na
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with GoSteven Francia
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIYoni Davidson
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8Phil Eaton
 

Semelhante a Go. why it goes v2 (20)

Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
Golang
GolangGolang
Golang
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii Shapoval
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
Golang
GolangGolang
Golang
 
Golang
GolangGolang
Golang
 
Go at Skroutz
Go at SkroutzGo at Skroutz
Go at Skroutz
 
Why Go Lang?
Why Go Lang?Why Go Lang?
Why Go Lang?
 
Debugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDBDebugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDB
 
Python VS GO
Python VS GOPython VS GO
Python VS GO
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
 
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with Go
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8
 

Último

Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 

Último (20)

Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 

Go. why it goes v2

  • 2. About me Serhii Pichkurov ●6+ years of experience ●Mostly backend ●~ 1 year with Go 2
  • 3. Agenda ● Go is not C, not Java, not anything ● Gopher ● Rob Pike argument ● Main ideas ● Concurrency model ● Tools ● Issues and gotchas 3
  • 4. Characteristics Go (often referred to as golang) is: 4 ●Clean procedural language designed for scalable cloud software ●open source ●statically typed with duck typing
  • 5. Characteristics ●CSP(communicating sequential processes) as concurrent model ●with garbage collection ●created at Google in 2007 by Robert Griesemer(V8), Rob Pike(UNIX, UTF-8), and Ken Thompson(UNIX, regexp) 5
  • 6. Characteristics ●compiled ●two compilers: "gc"(many platforms including smartphones) and “gccgo”(more optimizations, more processors) ●Linux, OS X, FreeBSD, Windows and more 6
  • 7. Motivated by Google’s needs: Why new lang? 7 ● No surprises ● Efficiency ● Safety ● Concurrency ● Scalability ● Fast development cycle ● A cute mascot
  • 8. Who uses Go at Google? Lots of projects. Thousands of Go programmers. Millions of lines of Go code. Public examples: ● Kubernetes ● SPDY proxy for Chrome on mobile devices ● dl.google.com is written in Go ● YouTube Vitess MySQL balancer 8
  • 9. Who uses Go besides Google? 9
  • 11. Go use-cases ● Cloud/Networking - routers, proxies, etc ● Distributed services and storages ● Internal infrastructures ● Microservices (with frameworks, like GoKit) ● Containers and orchestration ● Command-line tools 11
  • 14. Rob Pike argument ● Go is different ● Go does not try to be like the other languages ● Go does not compete on features ● As of Go 1, the language is fixed 14
  • 16. GC in Go 1.6 16https://talks.golang.org/2016/state-of-go.slide
  • 17. Everything is passed by value 17
  • 18. Go elements ● concrete data types ● functions and methods ● interfaces ● structs ● packages ● concurrency ● good tools, fast builds All the pieces feel simple in practice 18
  • 19. Types ●bool ●string ●int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 ●byte //alias for uint8 ●rune //alias for int32, Unicode char ●float32 float64 ●complex32 complex64 19
  • 20. var c, python, java bool 20 k := 3 c, python, java := true, false, "no!"
  • 21. 21 func do_something() (string, int) { return "result", 0 } first, second := do_something()
  • 22. Unused variables or imports — compilation error 22
  • 23. Arrays An array's length is part of its type, so arrays cannot be resized. var arr [5]int arr[4] = 42 23
  • 24. Slices A slice, on the other hand, is a dynamically-sized, flexible view(reference) into the elements of an array var foo []int 24
  • 25. Slices foo := make([]int, 5) 25 foo[3] = 42 foo[4] = 100
  • 26. Slices bytes := [5]byte{} // array var slice = bytes[2:4] names := []string{"leto", "paul", "teg"} c := make([]string, len(names)) copy(c, names) names = append(names,"ioav") 26
  • 27. Maps m = make(map[string]int) // declare m["route"] = 66 // put i := m["route"] // get delete(m, "route") _, ok := m["route"] //check is present 27
  • 28. Maps Important to remember: when no value is assigned to key, zero value is returned 28
  • 29. for key, value := range m { //iterate fmt.Println("Key:", key, "Value:", value) } commits := map[string]int{ //static population "gri": 1908, "adg": 912, } 29 Maps
  • 30. Interfaces Just a set of methods. No data. Simple idea, but more complex than expected. type Reader interface { Read(p []byte) (n int, err error) } _, err := reader.Read(p) 30
  • 31. Structs type Person struct { FirstName string LastName string } person := Person{FirstName:"title", LastName:"http:..."} 31
  • 32. Tags aka annotations type Person struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` MiddleName string `json:"-"` } 32 xml:"FirstName"` xml:"LastName"` xml:"MiddleName"`
  • 33. Pointers A pointer holds the memory address of a variable. The & operator generates a pointer to its operand: i := 42 p = &i The * operator denotes the pointer's underlying value: fmt.Println(*p) // read i through the pointer p *p = 21 // set i through the pointer p 33
  • 34. Receivers type Server struct { ... } 34 func (srv *Server) Close() error { ... } func (srv Server) Name() string { ... }
  • 36. Packages We can import one or more package, there are three types: system, local and remote. System – out of the box. Like http, testing, etc Local – in your repository, no need to use full path. Remote – has complete import path pointing to the server. To import remote package: import "github.com/nf/wav" 36
  • 37. Getting dependencies For remote package use go get to fetch into workspace. go get github.com/nf/wav Other operations also done via go CLI tool: go build go test go run and more 37
  • 38. 38 export GOPATH = $HOME/go_workspace
  • 39. Concurrency Based on CSP that was first described in a 1978 paper by Tony Hoare. Has three elements: ● coroutines (execution) ● channels (communication) ● select (coordination) 39
  • 40. “ Don't communicate by sharing memory, share memory by communicating 40
  • 41. Goroutines Start a goroutine with the go keyword: go function(args) Like garbage collection, eliminate considerations from the programmer's concern: ● no stack size ● no return or completion status ● no mechanism for management ● no "ID" 41
  • 42. Goroutines ●Goroutines are like lightweight threads. ●Go programs can have hundreds of thousands of them ●The Go runtime schedules goroutines onto OS threads ●Blocked goroutines don't use a thread 42
  • 43. Channels Channels provide communication between goroutines. c := make(chan string) // goroutine 1 c <- "hello!" // goroutine 2 s := <-c fmt.Println(s) // "hello!" 43
  • 44. Select A select statement blocks until one of its cases can run, then it executes that case. msg := "hi" select { case n := <-in: fmt.Println("received", n) case out <- msg: fmt.Println("sent", msg) } 44
  • 46. 46
  • 47. Go and Java have much in common ● C family (imperative, braces) ● Statically typed ● Garbage collected ● Memory safe (nil references, runtime bounds checks) 47
  • 48. ● Variables are always initialized (zero/nil/false) ● Methods ● Interfaces ● Type assertions (instanceof) ● Reflection 48 Go and Java have much in common
  • 49. Go differs from Java in several ways ● Programs compile to machine code. There's no VM. ● Statically linked binaries ● Multiple return ● Error handling ● Bit different GC(no compaction) 49
  • 50. Go intentionally leaves out many features ● No classes ● No ‘implements’ keyword ● No final ● No exceptions ● No user-defined generics 50
  • 51. Exceptions go away ● no exceptions by design ● handling with multiple return ● panic! type error interface { Error() string } 51
  • 52. Errors design rpm, err := rpm.OpenPackageFile(localPath) if err != nil { log.Error("Failed to read RPM headers: %v", err) return } file, err = file.ReadAt(archiveHead, int64(headerEnd)) if err != nil { log.Error("Invalid archive head head: %v", err) return } 52
  • 54. go get is great, but we need more 54
  • 55. Vendoring server-one uses the mux package in $GOPATH/src/github.com/gorilla/mux. server-two uses the mux package in vendor. $GOPATH src/ server-one/ main.go (import "github.com/gorilla/mux") server-two/ main.go (import "github.com/gorilla/mux") vendor/ github.com/ gorilla/ mux/ ... 55
  • 56. Glide for Package Management ● Semantic Versions and Ranges ● Git, Bzr, Hg, Svn ● Works with Go toolchain ● Leverages vendor directory ● Imports from Godep, GB, GPM, Gom ● Private Repos and Forks 56
  • 57. Go tools support ●go fmt ●goimports ●go lint or gometalinter ●godoc lookups ●go generate ●many more ●easy to write your own 57
  • 58. IDE There's no "Go IDE". Go tools meet you where you are. ●Eclipse ●JetBrains(GoLand) ●Atom ●Emacs ●Vim ●many others 58
  • 59. My experience Project that searches for vulnerabilities inside artifacts ●microservices ●RabbitMQ ●MongoDB/PostgreSQL ●REST API ●work with files and archives ●Docker ●34860 lines of code 59
  • 61. Pointers, pointers to pointers, more pointers. 61
  • 62. Nil pointer is still there and happens in runtime 62
  • 64. “ If you want to do something expensive — do it explicitly 64
  • 65. Missing comma in multi-line Slice, Array, and Map Literals 65
  • 66. func main() { x := []int{ 1, 2 //error } _ = x } 66
  • 68. “ I’m impressed about how easy people can pick it up and start being productive in a project , it’s also very easy to deploy David Cuadrado, Authy 68
  • 69. Simple can be expressive 69
  • 70. Simplicity is complicated but the clarity is worth the fight 70