SlideShare a Scribd company logo
Introduction to Golang
Speak Your Way, February 1, 2017
Yoni Davidson
Sears Israel
From Wikipedia - What is Go
Go (often referred to as golang) is a free and open source[12]
programming language created at Google[13]
in 2007 by Robert Griesemer,
Rob Pike, and Ken Thompson.
[10]
It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited
structural typing,[3]
memory safety features and CSP-style concurrent programming features added.[14]
Hello, world
package main
import "fmt"
func main() {
fmt.Printf("Hello, 世界n");
}
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Who
Robert Griesemer, Ken Thompson, and Rob Pike started the project in late 2007.
By mid 2008 the language was mostly designed and the implementation (compiler,
run-time) starting to work.
Ian Lance Taylor and Russ Cox joined in 2008.
Lots of help from many others (Open source).
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Why
Go fast! Make programming fun again.
There is focus on building client/server systems.
Clusters can be massive.
The rise of multi-core CPUs.
Major system languages were not designed with all these factors in mind.
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Construction speed
Takes too long to build software.
Tools are slow.
Dependencies management is hard.
Machines stopped getting faster (Dramatically).
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Type system
Clunky typing: Taints good idea with bad implementation. Makes programming
harder (think of C's const: well-intentioned but awkward in practice).
Hierarchy is too stringent: Types in large programs do not easily fall into
hierarchies.
Programmers spend too much time deciding tree structure and rearranging
inheritance.
You can be productive or safe, not both.
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Why a new language?
These problems are endemic and linguistic.
New libraries won’t help. (Adding anything is going in the wrong direction.)
Need to start over, thinking about the way programs are written and constructed.
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Goals
The efficiency of a statically-typed compiled language with the ease of
programming of a dynamic language.
Safety: type-safe and memory-safe.
Good support for concurrency and communication.
Efficient, latency-free garbage collection.
High-speed compilation.
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
https://xkcd.com/303/
Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
Example
Where can we find go?
Traditionally in server side infrastructure (High query rate servers, Web crawlers):
Some well known CLI/Server projects.
Where can we find go?
IOT devices:
Mobile:
Go best advantages:
Golang compiles natively to most important architectures (arm, x86).
Development is faster in comparison to C ,C++ Java.
Deployment of code on ServerpcIOT is simple due to the nature of static
compilation.
Context switch between backend and device is simpler if you use go in both.
Concurrency is easily used in go (in comparison to C/C++/java) lets you better
exploit multi core architectures (very common today).
Go best advantages:
No file system dependency (Java , Nodejs, C++ - boost) - Code runs natively.
Large and growing collection of open source code for large range of abilities.
Compiles easily with C.
Internal tools in go
build compile packages and dependencies
clean remove object files
doc show documentation for package or symbol
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
generate generate Go files by processing source
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Example simple web server:
package main
import (
"fmt"
"http"
)
func handler(c *http.Conn, r *http.Request) {
fmt.Fprintf(c, "Hello, %s.", r.URL.Path[1:])
}
func main() {
http.ListenAndServe(":8080",
http.HandlerFunc(handler))
}
https://talks.golang.org/2010/ExpressivenessOfGo-2010.pdf
Structs
type Point struct { x, y float }
func (p Point) Abs() float {
return math.Sqrt(p.x*p.x + p.y*p.y)
}
Structs describe (and control) the layout of data.
Methods are not mixed with the data definition.
They are orthogonal to types.
https://talks.golang.org/2010/ExpressivenessOfGo-2010.pdf
Methods
Orthogonality of methods allows any type to have them.
type Vector []float
func (v Vector) Abs() float {
sumOfSquares := 0.0
for i := range v {
sumOfSquares += v[i]*v[i]
}
return math.Sqrt(sumOfSquares)
}
It also allows receivers to be values or pointers:
func (p *Point) Scale(ratio float) {
p.x, p.y = ratio*p.x, ratio*p.y
}
func swap(x, y string) (string, string) { //multiple results
return y, x
}
Interfaces
Interfaces are just sets of methods. work for any type.
type Abser interface {
Abs() float
}
var a Abser
a = Point{3, 4}
print(a.Abs())
a = Vector{1, 2, 3, 4}
print(a.Abs())
Interfaces are satisfied implicitly. Point and Vector do not
declare that they implement Abser, they just do!
Error handling
Functions often return an error value, and calling code should handle errors by testing whether
the error equals nil.
type error interface {
Error() string
}
Error handling - example
type MyError struct {
When time.Time
What string
}
func (e *MyError) Error() string {
return fmt.Sprintf("at %v, %s",
e.When, e.What)
}
func run() error {
return &MyError{
time.Now(),
"it didn't work",
}
}
func main() {
if err := run(); err != nil {
fmt.Println(err)
}
}
Concurrency
Go's approach to concurrency differs from the traditional use of threads and shared memory. Philosophically, it can be summarized:
Don't communicate by sharing memory; share memory by communicating.
Goroutines
A goroutine is a function that is capable of running concurrently with other functions. To create a goroutine we use the keyword
go followed by a function invocation.
Channels
Channels provide a way for two goroutines to communicate with one another and synchronize their execution.
Go concurrency basics
Start a goroutine:
go f()
Channel send (arrow points in direction of flow):
ch <- value
Channel receive:
value = <-ch
Channels are unbuffered by default, which combines
synchronization with communication.
Launching a goroutine
Start a service, return a channel to communicate with it:
package main
func main() {
// create new channel of type int
ch := make(chan int)
// start new anonymous goroutine
go func() {
// send 42 to channel
ch <- 42
}()
// read from channel
<-ch
}
1. package main
2. import "time"
3. func main() {
4. var Ball int
5. table := make(chan int)
6. go player(table)
7. go player(table)
8. table <- Ball
9. time.Sleep(1 * time.Second)
10. <-table
11. }
12. func player(table chan int) {
13. for {
14. ball := <-table
15. ball++
16. time.Sleep(100 * time.Millisecond)
17. table <- ball
18. }
19. }
Closures are just local functions
func Compose(f, g func(x float) float) func(x float) float {
return func(x float) float {
return f(g(x))
}
}
Closures
Closures and concurrency
Query servers in replicated database, return first response.
func Query(conns []Conn, query string) Result {
ch := make(chan Result, 1) // buffer of 1 item
for _, conn := range conns {
go func(c Conn) {
_ = ch <- c.DoQuery(query)
}(conn)
}
return <-ch
}
This is a true open source project:
Much more information at:
http://golang.org
https://tour.golang.org/welcome/1
shameless self promotion - Golang and IOT
https://www.elastic.co/products/beats
https://eng.uber.com/go-geofence/
React native + Go for mobile
http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/
http://www.slideshare.net/SergeyLanzman/gett-golang
Go and Data science - Daniel whitenack
Inroduction to golang

More Related Content

What's hot

Optimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest ApiOptimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest Api
Iman Syahputra Situmorang
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
Bo-Yi Wu
 
Golang online course
Golang online courseGolang online course
Golang online course
bestonlinecoursescoupon
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
Dvir Volk
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
Giulio De Donato
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Aniruddha Chakrabarti
 
Rest, sockets em golang
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golang
jefferson Otoni Lima
 
Golang for PHP programmers: A practical introduction
Golang for PHP programmers: A practical introductionGolang for PHP programmers: A practical introduction
Golang for PHP programmers: A practical introduction
Richard Tuin
 
kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs
sangam biradar
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
Ting-Li Chou
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
Nexus FrontierTech
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
HannahMoss14
 
Golang
GolangGolang
Developing Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangDeveloping Cross Platform Applications with Golang
Developing Cross Platform Applications with Golang
Erhan Yakut
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
Tim Burks
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks
 
Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
Andreas Schreiber
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with Golang
Takaaki Mizuno
 
Let the contribution begin (EST futures)
Let the contribution begin  (EST futures)Let the contribution begin  (EST futures)
Let the contribution begin (EST futures)
SeongJae Park
 

What's hot (20)

Optimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest ApiOptimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest Api
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
 
Golang online course
Golang online courseGolang online course
Golang online course
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
 
Rest, sockets em golang
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golang
 
Golang for PHP programmers: A practical introduction
Golang for PHP programmers: A practical introductionGolang for PHP programmers: A practical introduction
Golang for PHP programmers: A practical introduction
 
kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
 
Golang
GolangGolang
Golang
 
Developing Cross Platform Applications with Golang
Developing Cross Platform Applications with GolangDeveloping Cross Platform Applications with Golang
Developing Cross Platform Applications with Golang
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with Golang
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Let the contribution begin (EST futures)
Let the contribution begin  (EST futures)Let the contribution begin  (EST futures)
Let the contribution begin (EST futures)
 

Viewers also liked

Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
Bo-Yi Wu
 
The internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolutionThe internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolution
Yoni Davidson
 
Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern
理 傅
 
A microservice architecture based on golang
A microservice architecture based on golangA microservice architecture based on golang
A microservice architecture based on golang
Gianfranco Reppucci
 
Gett && Golang
Gett && GolangGett && Golang
Gett && Golang
Sergey Lanzman
 
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
Bo-Yi Wu
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
Karthik Gaekwad
 
Functional go
Functional goFunctional go
Functional go
Geison Goes
 
Go, el lenguaje de Google
Go, el lenguaje de GoogleGo, el lenguaje de Google
Go, el lenguaje de Google
JM Robles
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
Bo-Yi Wu
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
Bo-Yi Wu
 
Golang Template
Golang TemplateGolang Template
Golang Template
Karthick Kumar
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
Bo-Yi Wu
 
Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniter
Bo-Yi Wu
 
Go 1.8 Release Party
Go 1.8 Release PartyGo 1.8 Release Party
Go 1.8 Release Party
Rodolfo Carvalho
 
Golang 入門初體驗
Golang 入門初體驗Golang 入門初體驗
Golang 入門初體驗
政斌 楊
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
Suraj Deshmukh
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作
Bo-Yi Wu
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Bo-Yi Wu
 
Why to choose laravel framework
Why to choose laravel frameworkWhy to choose laravel framework
Why to choose laravel framework
Bo-Yi Wu
 

Viewers also liked (20)

Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
The internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolutionThe internet of things in now , see how golang is a part of this evolution
The internet of things in now , see how golang is a part of this evolution
 
Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern
 
A microservice architecture based on golang
A microservice architecture based on golangA microservice architecture based on golang
A microservice architecture based on golang
 
Gett && Golang
Gett && GolangGett && Golang
Gett && Golang
 
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
 
Functional go
Functional goFunctional go
Functional go
 
Go, el lenguaje de Google
Go, el lenguaje de GoogleGo, el lenguaje de Google
Go, el lenguaje de Google
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
Golang Template
Golang TemplateGolang Template
Golang Template
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 
Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniter
 
Go 1.8 Release Party
Go 1.8 Release PartyGo 1.8 Release Party
Go 1.8 Release Party
 
Golang 入門初體驗
Golang 入門初體驗Golang 入門初體驗
Golang 入門初體驗
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Why to choose laravel framework
Why to choose laravel frameworkWhy to choose laravel framework
Why to choose laravel framework
 

Similar to Inroduction to golang

The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
Alessandro Sanino
 
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
Mario Castro Contreras
 
Introduction to Go language
Introduction to Go languageIntroduction to Go language
Introduction to Go language
Tzar Umang
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
Sergey Pichkurov
 
Golang
GolangGolang
Golang
GolangGolang
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
Raveen Perera
 
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
Trivadis
 
Golang 101
Golang 101Golang 101
Golang 101
宇 傅
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
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
Rodolfo Carvalho
 
Eclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classesEclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classes
Luca D'Onofrio
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
Amr Hassan
 
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascriptwendy017
 
Lighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on GiraphLighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on Giraph
LDBC council
 
Lighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on GiraphLighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on Giraph
Ioan Toma
 
Golang
GolangGolang
Golang
Felipe Mamud
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
Barry Jones
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
guestd9065
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
Matthew Campbell
 

Similar to Inroduction to golang (20)

The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
 
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
 
Introduction to Go language
Introduction to Go languageIntroduction to Go language
Introduction to Go language
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
Golang
GolangGolang
Golang
 
Golang
GolangGolang
Golang
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
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
 
Golang 101
Golang 101Golang 101
Golang 101
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
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
 
Eclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classesEclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classes
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
 
Lighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on GiraphLighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on Giraph
 
Lighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on GiraphLighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on Giraph
 
Golang
GolangGolang
Golang
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
 

Recently uploaded

Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Inroduction to golang

  • 1. Introduction to Golang Speak Your Way, February 1, 2017 Yoni Davidson Sears Israel
  • 2. From Wikipedia - What is Go Go (often referred to as golang) is a free and open source[12] programming language created at Google[13] in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. [10] It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing,[3] memory safety features and CSP-style concurrent programming features added.[14]
  • 3. Hello, world package main import "fmt" func main() { fmt.Printf("Hello, 世界n"); } Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 4. Who Robert Griesemer, Ken Thompson, and Rob Pike started the project in late 2007. By mid 2008 the language was mostly designed and the implementation (compiler, run-time) starting to work. Ian Lance Taylor and Russ Cox joined in 2008. Lots of help from many others (Open source). Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 5. Why Go fast! Make programming fun again. There is focus on building client/server systems. Clusters can be massive. The rise of multi-core CPUs. Major system languages were not designed with all these factors in mind. Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 6. Construction speed Takes too long to build software. Tools are slow. Dependencies management is hard. Machines stopped getting faster (Dramatically). Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 7. Type system Clunky typing: Taints good idea with bad implementation. Makes programming harder (think of C's const: well-intentioned but awkward in practice). Hierarchy is too stringent: Types in large programs do not easily fall into hierarchies. Programmers spend too much time deciding tree structure and rearranging inheritance. You can be productive or safe, not both. Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 8. Why a new language? These problems are endemic and linguistic. New libraries won’t help. (Adding anything is going in the wrong direction.) Need to start over, thinking about the way programs are written and constructed. Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 9. Goals The efficiency of a statically-typed compiled language with the ease of programming of a dynamic language. Safety: type-safe and memory-safe. Good support for concurrency and communication. Efficient, latency-free garbage collection. High-speed compilation. Taken from: https://talks.golang.org/2009/go_talk-20091030.pdf
  • 12. Where can we find go? Traditionally in server side infrastructure (High query rate servers, Web crawlers): Some well known CLI/Server projects.
  • 13. Where can we find go? IOT devices: Mobile:
  • 14. Go best advantages: Golang compiles natively to most important architectures (arm, x86). Development is faster in comparison to C ,C++ Java. Deployment of code on ServerpcIOT is simple due to the nature of static compilation. Context switch between backend and device is simpler if you use go in both. Concurrency is easily used in go (in comparison to C/C++/java) lets you better exploit multi core architectures (very common today).
  • 15. Go best advantages: No file system dependency (Java , Nodejs, C++ - boost) - Code runs natively. Large and growing collection of open source code for large range of abilities. Compiles easily with C.
  • 16. Internal tools in go build compile packages and dependencies clean remove object files doc show documentation for package or symbol env print Go environment information fix run go tool fix on packages fmt run gofmt on package sources generate generate Go files by processing source get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet run go tool vet on packages
  • 17. Example simple web server: package main import ( "fmt" "http" ) func handler(c *http.Conn, r *http.Request) { fmt.Fprintf(c, "Hello, %s.", r.URL.Path[1:]) } func main() { http.ListenAndServe(":8080", http.HandlerFunc(handler)) } https://talks.golang.org/2010/ExpressivenessOfGo-2010.pdf
  • 18. Structs type Point struct { x, y float } func (p Point) Abs() float { return math.Sqrt(p.x*p.x + p.y*p.y) } Structs describe (and control) the layout of data. Methods are not mixed with the data definition. They are orthogonal to types. https://talks.golang.org/2010/ExpressivenessOfGo-2010.pdf
  • 19. Methods Orthogonality of methods allows any type to have them. type Vector []float func (v Vector) Abs() float { sumOfSquares := 0.0 for i := range v { sumOfSquares += v[i]*v[i] } return math.Sqrt(sumOfSquares) } It also allows receivers to be values or pointers: func (p *Point) Scale(ratio float) { p.x, p.y = ratio*p.x, ratio*p.y } func swap(x, y string) (string, string) { //multiple results return y, x }
  • 20. Interfaces Interfaces are just sets of methods. work for any type. type Abser interface { Abs() float } var a Abser a = Point{3, 4} print(a.Abs()) a = Vector{1, 2, 3, 4} print(a.Abs()) Interfaces are satisfied implicitly. Point and Vector do not declare that they implement Abser, they just do!
  • 21. Error handling Functions often return an error value, and calling code should handle errors by testing whether the error equals nil. type error interface { Error() string }
  • 22. Error handling - example type MyError struct { When time.Time What string } func (e *MyError) Error() string { return fmt.Sprintf("at %v, %s", e.When, e.What) } func run() error { return &MyError{ time.Now(), "it didn't work", } } func main() { if err := run(); err != nil { fmt.Println(err) } }
  • 23. Concurrency Go's approach to concurrency differs from the traditional use of threads and shared memory. Philosophically, it can be summarized: Don't communicate by sharing memory; share memory by communicating. Goroutines A goroutine is a function that is capable of running concurrently with other functions. To create a goroutine we use the keyword go followed by a function invocation. Channels Channels provide a way for two goroutines to communicate with one another and synchronize their execution.
  • 24. Go concurrency basics Start a goroutine: go f() Channel send (arrow points in direction of flow): ch <- value Channel receive: value = <-ch Channels are unbuffered by default, which combines synchronization with communication.
  • 25. Launching a goroutine Start a service, return a channel to communicate with it: package main func main() { // create new channel of type int ch := make(chan int) // start new anonymous goroutine go func() { // send 42 to channel ch <- 42 }() // read from channel <-ch }
  • 26. 1. package main 2. import "time" 3. func main() { 4. var Ball int 5. table := make(chan int) 6. go player(table) 7. go player(table) 8. table <- Ball 9. time.Sleep(1 * time.Second) 10. <-table 11. } 12. func player(table chan int) { 13. for { 14. ball := <-table 15. ball++ 16. time.Sleep(100 * time.Millisecond) 17. table <- ball 18. } 19. }
  • 27. Closures are just local functions func Compose(f, g func(x float) float) func(x float) float { return func(x float) float { return f(g(x)) } } Closures
  • 28. Closures and concurrency Query servers in replicated database, return first response. func Query(conns []Conn, query string) Result { ch := make(chan Result, 1) // buffer of 1 item for _, conn := range conns { go func(c Conn) { _ = ch <- c.DoQuery(query) }(conn) } return <-ch }
  • 29. This is a true open source project: Much more information at: http://golang.org https://tour.golang.org/welcome/1 shameless self promotion - Golang and IOT https://www.elastic.co/products/beats https://eng.uber.com/go-geofence/ React native + Go for mobile http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/ http://www.slideshare.net/SergeyLanzman/gett-golang Go and Data science - Daniel whitenack