SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Learning Go for Perl
Programmers
Fred Moyer
SF Perl Mongers, 06082016
The Go Programming Language
Developed at Google circa 2007
Goroutines (threads)
Channels (queues)
One way to format code (gofmt)
Hello SF.pm!
package main
import "fmt"
func main() {
fmt.Println("Hello, サンフランシスコのPerlモンガー")
}
Hash || Object => Struct
type Person struct {
id int // lowercase fields are not exported
email string // note no commas after variable type
Name string
HeightCentimeters float32 // camelCase convention
IsAlive bool // true or false, defaults to false
}
Hash || Object => Struct
var famousActor = Person{
id: 1,
email: "jeff@goldblum.org",
Name: "Jeff Goldblum", // no single quotes
HeightCentimeters: 193.5,
IsAlive: true,
}
Hash || Object => Struct
// we all knew this day would come
// perhaps in Independence Day: Resurgence?
// use the dot notation to make it happen
famousActor.IsAlive = false
Array => Slice
var tallActors []string
tallActors = append(tallActors, “Dolph Lundgren”)
tallActors[0] = “Richard Kiel”
tallActors[1] = “Chevy Chase” // error: index out of range
tallActors = append(tallActors, “Vince Vaughn”)
tallActorsCopy := make([]string, len(tallActors))
copy(tallActorsCopy, tallActors)
Array => Array
// not used nearly as much as slices
var tenIntegers [10]int
fiveIntegers := [5]int{1,2,3,4,5}
lastThreeIntegers := fiveIntegers[2:] // outputs 3,4,5
firstTwoIntegers := fiveIntegers[:2] // outputs 1,2
Hash => Map
countries := make(map[string]int)
countries[“Canada”] = 1
countries[“US”] = 2
canadaId = countries[“Canada”] // 1
delete(countries, “US”)
countries := map[string]int{“Canada”: 1, “US”: 2}
countryId, exists := countries[“Atlantis”] // exists == nil
Loops
for i:= 0; i < 10; i++ {
fmt.Printf(“We’re going to 11”, i+1)
}
for i, actor := range []string{“Van Dam”, “Liam Neeson”} {
fmt.Printf(“#%d is %v”, i, actor) // %v default format
}
for _, actor := ... // _ ignores the loop iterator value
$@ => err
bytesRead, err := w.Write([]byte{“data written to client”})
if err != nil {
log.WithField("err", err).Error("write to client failed")
}
var err error // built in error type
err.Error() // format error as a string
use => import
import (
"database/sql"
"encoding/json"
"flag"
"fmt"
)
sub foo => func foo (bar string, boo int)
func httpEndpoint(world string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r
*http.Request) {
bytesRead, _ := w.Write([]byte(
fmt.Sprintf(“Hello %v!”, world)))
return
}
}
t/test.t => main_test.go
main.go # file containing your code, ‘go run main.go’
main_test.go # unit test for main.go
go test # runs main_test.go, executes all tests
func TestSomething(t *testing.T) {
// do some stuff
if err != nil { t.Errorf("test failed %v", err) }
}
perldoc => godoc
$ godoc fmt
use 'godoc cmd/fmt' for documentation on the fmt command
PACKAGE DOCUMENTATION
package fmt
import "fmt"
...
perldoc => godoc
$ godoc fmt Sprintf
use 'godoc cmd/fmt' for documentation on the fmt command
func Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and
returns the
resulting string.
CPAN => https://golang.org/pkg/
cpanminus => go get
go get github.com/quipo/statsd
$ ls gocode/src/github.com/quipo/statsd/
LICENSE bufferedclient_test.go event
README.md client.go interface.go
bufferedclient.go client_test.go noopclient.go
PERL5LIB => GOPATH
$ echo $GOPATH
/Users/phred/gocode
$ ls gocode/
bin pkg src
$ ls gocode/src/
github.com glenda golang.org
? => go build
$ pwd
~/gocode/src/myorg/myapp
$ ls
main.go main_test.go
$ go build; ls
main.go main_test.go myapp
./myapp # binary executable you can relocate to same arch
queues => channels
c := make(chan string) // queue for string data type
hello := “Hello SF.pm”
c <- hello
// ...
fmt.Println(<-c) // prints “Hello.SF.pm”
bufferedChannel := make(chan string, 2) // buffers 2 strings
// channels are first class citizens of Go
threads => goroutines
hello := “Hello SF.pm”
go myFunc(hello)
func myFunc(myString string) {
fmt.Println(myString)
}
// spawns an asynchronous thread which executes a function
// goroutines are first class citizens of Go
Tour of Golang web places
https://golang.org/
https://tour.golang.org/welcome/1
https://golang.org/pkg/
https://groups.google.com/forum/#!forum/golang-nuts
Questions?

Contenu connexe

Tendances

Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in GoAmr Hassan
 
From 0 to mine sweeper in pyside
From 0 to mine sweeper in pysideFrom 0 to mine sweeper in pyside
From 0 to mine sweeper in pysideDinesh Manajipet
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminarygo-lang
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script ProgrammingLin Yo-An
 
Getting groovy (ODP)
Getting groovy (ODP)Getting groovy (ODP)
Getting groovy (ODP)Nick Dixon
 
How to develop a rich terminal UI application
How to develop a rich terminal UI applicationHow to develop a rich terminal UI application
How to develop a rich terminal UI applicationMasashi Shibata
 
Golangにおける端末制御 リッチなターミナルUIの実現方法
Golangにおける端末制御 リッチなターミナルUIの実現方法Golangにおける端末制御 リッチなターミナルUIの実現方法
Golangにおける端末制御 リッチなターミナルUIの実現方法Masashi Shibata
 
Unix And C
Unix And CUnix And C
Unix And CDr.Ravi
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutesSumit Raj
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with GoSteven Francia
 
Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Steven Francia
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Languageguestaa63aa
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMRaveen Perera
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAhmed Salama
 

Tendances (20)

Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
From 0 to mine sweeper in pyside
From 0 to mine sweeper in pysideFrom 0 to mine sweeper in pyside
From 0 to mine sweeper in pyside
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script Programming
 
Getting groovy (ODP)
Getting groovy (ODP)Getting groovy (ODP)
Getting groovy (ODP)
 
How to develop a rich terminal UI application
How to develop a rich terminal UI applicationHow to develop a rich terminal UI application
How to develop a rich terminal UI application
 
Golangにおける端末制御 リッチなターミナルUIの実現方法
Golangにおける端末制御 リッチなターミナルUIの実現方法Golangにおける端末制御 リッチなターミナルUIの実現方法
Golangにおける端末制御 リッチなターミナルUIの実現方法
 
Unix And C
Unix And CUnix And C
Unix And C
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with Go
 
Defer, Panic, Recover
Defer, Panic, RecoverDefer, Panic, Recover
Defer, Panic, Recover
 
Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go
 
Golang
GolangGolang
Golang
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Language
 
Linux basic1&amp;2
Linux basic1&amp;2Linux basic1&amp;2
Linux basic1&amp;2
 
Отладка в GDB
Отладка в GDBОтладка в GDB
Отладка в GDB
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 

En vedette

GO programming language
GO programming languageGO programming language
GO programming languagetung vu
 
Как устроен поиск (Андрей Аксёнов)
Как устроен поиск (Андрей Аксёнов)Как устроен поиск (Андрей Аксёнов)
Как устроен поиск (Андрей Аксёнов)Ontico
 
Анатомия веб сервиса (HighLoad-2014)
Анатомия веб сервиса (HighLoad-2014)Анатомия веб сервиса (HighLoad-2014)
Анатомия веб сервиса (HighLoad-2014)Andrey Smirnov
 
Консольные приложения на Go
Консольные приложения на GoКонсольные приложения на Go
Консольные приложения на GoAndrey Smirnov
 
Клиентские приложения под нагрузкой (HighLoad 2014)
Клиентские приложения под нагрузкой (HighLoad 2014)Клиентские приложения под нагрузкой (HighLoad 2014)
Клиентские приложения под нагрузкой (HighLoad 2014)Andrey Smirnov
 
Fuzzing: The New Unit Testing
Fuzzing: The New Unit TestingFuzzing: The New Unit Testing
Fuzzing: The New Unit TestingDmitry Vyukov
 
Develop Android app using Golang
Develop Android app using GolangDevelop Android app using Golang
Develop Android app using GolangSeongJae Park
 

En vedette (7)

GO programming language
GO programming languageGO programming language
GO programming language
 
Как устроен поиск (Андрей Аксёнов)
Как устроен поиск (Андрей Аксёнов)Как устроен поиск (Андрей Аксёнов)
Как устроен поиск (Андрей Аксёнов)
 
Анатомия веб сервиса (HighLoad-2014)
Анатомия веб сервиса (HighLoad-2014)Анатомия веб сервиса (HighLoad-2014)
Анатомия веб сервиса (HighLoad-2014)
 
Консольные приложения на Go
Консольные приложения на GoКонсольные приложения на Go
Консольные приложения на Go
 
Клиентские приложения под нагрузкой (HighLoad 2014)
Клиентские приложения под нагрузкой (HighLoad 2014)Клиентские приложения под нагрузкой (HighLoad 2014)
Клиентские приложения под нагрузкой (HighLoad 2014)
 
Fuzzing: The New Unit Testing
Fuzzing: The New Unit TestingFuzzing: The New Unit Testing
Fuzzing: The New Unit Testing
 
Develop Android app using Golang
Develop Android app using GolangDevelop Android app using Golang
Develop Android app using Golang
 

Similaire à Learning go for perl programmers

Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Robert Stern
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with goHean Hong Leong
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFDror Bereznitsky
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyiststchandy
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
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 GoChris McEniry
 
Unit 8
Unit 8Unit 8
Unit 8siddr
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of GoFrank Müller
 
Formatting ForThe Masses
Formatting ForThe MassesFormatting ForThe Masses
Formatting ForThe MassesHolger Schill
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceMaarten Balliauw
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptKamil Toman
 
NodeJs
NodeJsNodeJs
NodeJsdizabl
 

Similaire à Learning go for perl programmers (20)

Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
 
Golang workshop
Golang workshopGolang workshop
Golang workshop
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOF
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyists
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Txjs
TxjsTxjs
Txjs
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
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
 
Unit 8
Unit 8Unit 8
Unit 8
 
A Tour of Go - Workshop
A Tour of Go - WorkshopA Tour of Go - Workshop
A Tour of Go - Workshop
 
Sbaw091006
Sbaw091006Sbaw091006
Sbaw091006
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
 
Formatting ForThe Masses
Formatting ForThe MassesFormatting ForThe Masses
Formatting ForThe Masses
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
 
NodeJs
NodeJsNodeJs
NodeJs
 

Plus de Fred Moyer

Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+Fred Moyer
 
Practical service level objectives with error budgeting
Practical service level objectives with error budgetingPractical service level objectives with error budgeting
Practical service level objectives with error budgetingFred Moyer
 
SREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done RightSREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done RightFred Moyer
 
Scale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done RightScale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done RightFred Moyer
 
Latency SLOs Done Right
Latency SLOs Done RightLatency SLOs Done Right
Latency SLOs Done RightFred Moyer
 
Latency SLOs done right
Latency SLOs done rightLatency SLOs done right
Latency SLOs done rightFred Moyer
 
Comprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and IstioComprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and IstioFred Moyer
 
Comprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istioComprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istioFred Moyer
 
Effective management of high volume numeric data with histograms
Effective management of high volume numeric data with histogramsEffective management of high volume numeric data with histograms
Effective management of high volume numeric data with histogramsFred Moyer
 
Statistics for dummies
Statistics for dummiesStatistics for dummies
Statistics for dummiesFred Moyer
 
GrafanaCon EU 2018
GrafanaCon EU 2018GrafanaCon EU 2018
GrafanaCon EU 2018Fred Moyer
 
Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017Fred Moyer
 
Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016Fred Moyer
 
Better service monitoring through histograms
Better service monitoring through histogramsBetter service monitoring through histograms
Better service monitoring through histogramsFred Moyer
 
The Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL DatabaseThe Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL DatabaseFred Moyer
 
Surge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightningSurge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightningFred Moyer
 
Apache Dispatch
Apache DispatchApache Dispatch
Apache DispatchFred Moyer
 
Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008Fred Moyer
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator SimplifiedFred Moyer
 

Plus de Fred Moyer (20)

Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+
 
Practical service level objectives with error budgeting
Practical service level objectives with error budgetingPractical service level objectives with error budgeting
Practical service level objectives with error budgeting
 
SREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done RightSREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done Right
 
Scale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done RightScale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done Right
 
Latency SLOs Done Right
Latency SLOs Done RightLatency SLOs Done Right
Latency SLOs Done Right
 
Latency SLOs done right
Latency SLOs done rightLatency SLOs done right
Latency SLOs done right
 
Comprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and IstioComprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and Istio
 
Comprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istioComprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istio
 
Effective management of high volume numeric data with histograms
Effective management of high volume numeric data with histogramsEffective management of high volume numeric data with histograms
Effective management of high volume numeric data with histograms
 
Statistics for dummies
Statistics for dummiesStatistics for dummies
Statistics for dummies
 
GrafanaCon EU 2018
GrafanaCon EU 2018GrafanaCon EU 2018
GrafanaCon EU 2018
 
Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017
 
Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016
 
Better service monitoring through histograms
Better service monitoring through histogramsBetter service monitoring through histograms
Better service monitoring through histograms
 
The Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL DatabaseThe Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL Database
 
Surge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightningSurge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightning
 
Qpsmtpd
QpsmtpdQpsmtpd
Qpsmtpd
 
Apache Dispatch
Apache DispatchApache Dispatch
Apache Dispatch
 
Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
 

Dernier

Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 

Dernier (20)

Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 

Learning go for perl programmers

  • 1. Learning Go for Perl Programmers Fred Moyer SF Perl Mongers, 06082016
  • 2. The Go Programming Language Developed at Google circa 2007 Goroutines (threads) Channels (queues) One way to format code (gofmt)
  • 3. Hello SF.pm! package main import "fmt" func main() { fmt.Println("Hello, サンフランシスコのPerlモンガー") }
  • 4. Hash || Object => Struct type Person struct { id int // lowercase fields are not exported email string // note no commas after variable type Name string HeightCentimeters float32 // camelCase convention IsAlive bool // true or false, defaults to false }
  • 5. Hash || Object => Struct var famousActor = Person{ id: 1, email: "jeff@goldblum.org", Name: "Jeff Goldblum", // no single quotes HeightCentimeters: 193.5, IsAlive: true, }
  • 6. Hash || Object => Struct // we all knew this day would come // perhaps in Independence Day: Resurgence? // use the dot notation to make it happen famousActor.IsAlive = false
  • 7. Array => Slice var tallActors []string tallActors = append(tallActors, “Dolph Lundgren”) tallActors[0] = “Richard Kiel” tallActors[1] = “Chevy Chase” // error: index out of range tallActors = append(tallActors, “Vince Vaughn”) tallActorsCopy := make([]string, len(tallActors)) copy(tallActorsCopy, tallActors)
  • 8. Array => Array // not used nearly as much as slices var tenIntegers [10]int fiveIntegers := [5]int{1,2,3,4,5} lastThreeIntegers := fiveIntegers[2:] // outputs 3,4,5 firstTwoIntegers := fiveIntegers[:2] // outputs 1,2
  • 9. Hash => Map countries := make(map[string]int) countries[“Canada”] = 1 countries[“US”] = 2 canadaId = countries[“Canada”] // 1 delete(countries, “US”) countries := map[string]int{“Canada”: 1, “US”: 2} countryId, exists := countries[“Atlantis”] // exists == nil
  • 10. Loops for i:= 0; i < 10; i++ { fmt.Printf(“We’re going to 11”, i+1) } for i, actor := range []string{“Van Dam”, “Liam Neeson”} { fmt.Printf(“#%d is %v”, i, actor) // %v default format } for _, actor := ... // _ ignores the loop iterator value
  • 11. $@ => err bytesRead, err := w.Write([]byte{“data written to client”}) if err != nil { log.WithField("err", err).Error("write to client failed") } var err error // built in error type err.Error() // format error as a string
  • 12. use => import import ( "database/sql" "encoding/json" "flag" "fmt" )
  • 13. sub foo => func foo (bar string, boo int) func httpEndpoint(world string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { bytesRead, _ := w.Write([]byte( fmt.Sprintf(“Hello %v!”, world))) return } }
  • 14. t/test.t => main_test.go main.go # file containing your code, ‘go run main.go’ main_test.go # unit test for main.go go test # runs main_test.go, executes all tests func TestSomething(t *testing.T) { // do some stuff if err != nil { t.Errorf("test failed %v", err) } }
  • 15. perldoc => godoc $ godoc fmt use 'godoc cmd/fmt' for documentation on the fmt command PACKAGE DOCUMENTATION package fmt import "fmt" ...
  • 16. perldoc => godoc $ godoc fmt Sprintf use 'godoc cmd/fmt' for documentation on the fmt command func Sprintf(format string, a ...interface{}) string Sprintf formats according to a format specifier and returns the resulting string.
  • 18. cpanminus => go get go get github.com/quipo/statsd $ ls gocode/src/github.com/quipo/statsd/ LICENSE bufferedclient_test.go event README.md client.go interface.go bufferedclient.go client_test.go noopclient.go
  • 19. PERL5LIB => GOPATH $ echo $GOPATH /Users/phred/gocode $ ls gocode/ bin pkg src $ ls gocode/src/ github.com glenda golang.org
  • 20. ? => go build $ pwd ~/gocode/src/myorg/myapp $ ls main.go main_test.go $ go build; ls main.go main_test.go myapp ./myapp # binary executable you can relocate to same arch
  • 21. queues => channels c := make(chan string) // queue for string data type hello := “Hello SF.pm” c <- hello // ... fmt.Println(<-c) // prints “Hello.SF.pm” bufferedChannel := make(chan string, 2) // buffers 2 strings // channels are first class citizens of Go
  • 22. threads => goroutines hello := “Hello SF.pm” go myFunc(hello) func myFunc(myString string) { fmt.Println(myString) } // spawns an asynchronous thread which executes a function // goroutines are first class citizens of Go
  • 23. Tour of Golang web places https://golang.org/ https://tour.golang.org/welcome/1 https://golang.org/pkg/ https://groups.google.com/forum/#!forum/golang-nuts