SlideShare a Scribd company logo
1 of 31
Download to read offline
The Go features I can't live without,
2nd round
Golang Brno meetup #2
16 June 2016
Rodolfo Carvalho
Red Hat
Previously
goo.gl/ZkHw4X
1. Simplicity
2. Single dispatch
3. Capitalization
4. gofmt
5. godoc
6. No exceptions
7. Table-Driven Tests
8. Interfaces
9
First-class functions
In Go, functions are rst-class citizens.
They can be taken as argument, returned as value, assigned to variables, and so on.
Trivial, but not all languages have it... Bash nightmares!
You know what, you can even implement methods on function types!
//FromGo'snet/http/server.go
typeHandlerFuncfunc(ResponseWriter,*Request)
func(fHandlerFunc)ServeHTTP(wResponseWriter,r*Request){
f(w,r)
}
Example
funcmain(){
cmd:=exec.Command("bash","-c","whiletrue;dodate&&sleep1;done")
cmd.Stdout=os.Stdout
iferr:=cmd.Start();err!=nil{
log.Fatal(err)
}
timeout:=5*time.Second
time.AfterFunc(timeout,func(){
cmd.Process.Kill()
})
iferr:=cmd.Wait();err!=nil{
log.Fatal(err)
}
} Run
10
Fully quali ed imports
Easy to tell where a package comes from.
packagebuilder
import(
"fmt"
"io/ioutil"
"os"
"os/exec"
"time"
"github.com/docker/docker/builder/parser"
kapi"k8s.io/kubernetes/pkg/api"
"github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/client"
)
Compare with Ruby
require'rubygems'
require'openshift-origin-node/model/frontend/http/plugins/frontend_http_base'
require'openshift-origin-node/utils/shell_exec'
require'openshift-origin-node/utils/node_logger'
require'openshift-origin-node/utils/environ'
require'openshift-origin-node/model/application_container'
require'openshift-origin-common'
require'fileutils'
require'openssl'
require'fcntl'
require'json'
require'tmpdir'
require'net/http'
Now we need a way to determine where each of those things come from.
Imports in Go
Plain strings, give exibility to language spec.
"The interpretation of the ImportPath is implementation-dependent but it is typically a substring
of the full le name of the compiled package and may be relative to a repository of installed
packages."
Path relative to GOPATH.
PackageName != ImportPath; by convention, the package name is the base name of its
source directory.
Making imports be valid URLs allows tooling (goget) to automate downloading
dependencies.
Note: fully quali ed imports doesn't solve package versioning.
11
Static typing with type inference
Stutter-fee static typing
Let the compiler type check, not unit tests
Easier refactorings
cmd:=exec.Command("yes")
varcmd=exec.Command("yes")
varcmd*exec.Cmd=exec.Command("yes")
varcmd*exec.Cmd
cmd=exec.Command("yes")
12
Speed
Development
Compilation
Execution
Just a super cial reason to justify Go's success.
What I like
Go is a compiled language that feels like scripting*.
Minimal boilerplate:
No need* for con g les, build scripts, header les, XML les, etc.
The only con guration is GOPATH.
* But not all the time...
E.g., big projects like OpenShift can take 330+s to build with Go 1.6 ☹
Fast feedback cycles
packagemain
import"fmt"
funcmain(){
fmt.Println("HelloBrno!")
} Run
How it improved over time
40
30
20
10
0
Speed (m/s)
1.0 2.0 3.0 4.0 5.0 6.0
Time (s)
13
Metaprogramming
Wikipedia says: ... the writing of computer programs with the ability to treat programs as their
data. It means that a program could be designed to read, generate, analyse or transform other
programs, and even modify itself while running.
Go has no support for generics, at least yet.
No macros.
But has:
re ect package.
Packages in the stdlib for parsing, type checking and manipulating Go code.
Go programs that write Go programs and can serve as example: gofmt, goimports,
stringer, gofix, etc.
gogeneratetool.
14
Static linking
The linker creates statically-linked binaries by default.
Easy to deploy/distribute.
Big binary sizes.
OpenShift is a single binary with 134 MB today. Includes server, client, numerous command
line tools, Web Console, ...
Tale: distributing a Python program.
15
Cross-compilation
Develop/build on your preferred platform, deploy anywhere.
Operating Systems:
Linux
OS X
Windows
*BSD, Plan 9, Solaris, NaCl, Android
Architectures:
amd64
x86
arm, arm64, ppc64, ppc64le, mips64, mips64le
Easy to use
$GOOS=linux GOARCH=armGOARM=7gobuild-ofunc-linux-arm7 func.go
$GOOS=linux GOARCH=armGOARM=6gobuild-ofunc-linux-arm6 func.go
$GOOS=linux GOARCH=386 gobuild-ofunc-linux-386 func.go
$GOOS=windowsGOARCH=386 gobuild-ofunc-windows-386func.go
$filefunc-*
func-linux-386: ELF32-bitLSBexecutable,Intel80386,version1(SYSV),
staticallylinked,notstripped
func-linux-arm6: ELF32-bitLSBexecutable,ARM,EABI5version1(SYSV),
staticallylinked,notstripped
func-linux-arm7: ELF32-bitLSBexecutable,ARM,EABI5version1(SYSV),
staticallylinked,notstripped
func-windows-386:PE32executable(console)Intel80386(strippedtoexternal
PDB),forMSWindows
$dufunc-*
2184 func-linux-386
2188 func-linux-arm6
2184 func-linux-arm7
2368 func-windows-386
16
Go Proverbs
Similar to The Zen of Python, there is a lot of accumulated experience and shared knowledge
expressed by Go Proverbs.
Not actually a feature, but a "philosophical guidance".
Go Proverbs 1/4
Don't communicate by sharing memory, share memory by communicating.
Concurrency is not parallelism.
Channels orchestrate; mutexes serialize.
The bigger the interface, the weaker the abstraction.
Make the zero value useful.
Go Proverbs 2/4
interface{} says nothing.
Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.
A little copying is better than a little dependency.
Syscall must always be guarded with build tags.
Cgo must always be guarded with build tags.
Go Proverbs 3/4
Cgo is not Go.
With the unsafe package there are no guarantees.
Clear is better than clever.
Re ection is never clear.
Errors are values.
Go Proverbs 4/4
Don't just check errors, handle them gracefully.
Design the architecture, name the components, document the details.
Documentation is for users.
Don't panic.
Recap
9. First-class functions
10. Fully quali ed imports
11. Static typing with type inference
12. Speed
13. Metaprogramming
14. Static linking
15. Cross-compilation
16. Go Proverbs
Thank you
Rodolfo Carvalho
Red Hat
rhcarvalho@gmail.com
http://rodolfocarvalho.net

More Related Content

What's hot

What's hot (20)

Golang
GolangGolang
Golang
 
How to build SDKs in Go
How to build SDKs in GoHow to build SDKs in Go
How to build SDKs in Go
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
 
Using TypeScript at Dashlane
Using TypeScript at DashlaneUsing TypeScript at Dashlane
Using TypeScript at Dashlane
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Introduction to Clime
Introduction to ClimeIntroduction to Clime
Introduction to Clime
 
Decision making - for loop , nested loop ,if-else statements , switch in goph...
Decision making - for loop , nested loop ,if-else statements , switch in goph...Decision making - for loop , nested loop ,if-else statements , switch in goph...
Decision making - for loop , nested loop ,if-else statements , switch in goph...
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
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
 
Static Analysis in Go
Static Analysis in GoStatic Analysis in Go
Static Analysis in Go
 
Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)
 
Python debugging techniques
Python debugging techniquesPython debugging techniques
Python debugging techniques
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
FTD JVM Internals
FTD JVM InternalsFTD JVM Internals
FTD JVM Internals
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | Edureka
 
GO programming language
GO programming languageGO programming language
GO programming language
 
Clonedigger-Python
Clonedigger-PythonClonedigger-Python
Clonedigger-Python
 

Similar to The Go features I can't live without, 2nd round

Similar to The Go features I can't live without, 2nd round (20)

Golang workshop
Golang workshopGolang workshop
Golang workshop
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
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
 
Beginning development in go
Beginning development in goBeginning development in go
Beginning development in 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
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyists
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija SiskoTrivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
 
Introduction to Google's Go programming language
Introduction to Google's Go programming languageIntroduction to Google's Go programming language
Introduction to Google's Go programming language
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_world
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 

More from Rodolfo Carvalho

More from Rodolfo Carvalho (20)

OpenShift Overview - Red Hat Open School 2017
OpenShift Overview - Red Hat Open School 2017OpenShift Overview - Red Hat Open School 2017
OpenShift Overview - Red Hat Open School 2017
 
OpenShift Overview - Red Hat Open House 2017
OpenShift Overview - Red Hat Open House 2017OpenShift Overview - Red Hat Open House 2017
OpenShift Overview - Red Hat Open House 2017
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Go 1.8 Release Party
Go 1.8 Release PartyGo 1.8 Release Party
Go 1.8 Release Party
 
Building and Deploying containerized Python Apps in the Cloud
Building and Deploying containerized Python Apps in the CloudBuilding and Deploying containerized Python Apps in the Cloud
Building and Deploying containerized Python Apps in the Cloud
 
Python deployments on OpenShift 3
Python deployments on OpenShift 3Python deployments on OpenShift 3
Python deployments on OpenShift 3
 
Composing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it allComposing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it all
 
Pykonik Coding Dojo
Pykonik Coding DojoPykonik Coding Dojo
Pykonik Coding Dojo
 
Concurrency in Python4k
Concurrency in Python4kConcurrency in Python4k
Concurrency in Python4k
 
Coding Kwoon
Coding KwoonCoding Kwoon
Coding Kwoon
 
Python in 15 minutes
Python in 15 minutesPython in 15 minutes
Python in 15 minutes
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
 
Redes livres de escala
Redes livres de escalaRedes livres de escala
Redes livres de escala
 
Redes livres de escala
Redes livres de escalaRedes livres de escala
Redes livres de escala
 
XMPP
XMPPXMPP
XMPP
 
Content Delivery Networks
Content Delivery NetworksContent Delivery Networks
Content Delivery Networks
 
TDD do seu jeito
TDD do seu jeitoTDD do seu jeito
TDD do seu jeito
 
Intro Dojo Rio Python Campus
Intro Dojo Rio Python CampusIntro Dojo Rio Python Campus
Intro Dojo Rio Python Campus
 
Intro Dojo Rio
Intro Dojo RioIntro Dojo Rio
Intro Dojo Rio
 
Pyndorama
PyndoramaPyndorama
Pyndorama
 

Recently uploaded

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
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%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
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
%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
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
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
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 

The Go features I can't live without, 2nd round