SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Go
Because most times Javascript 

isn’t enough
Simon Hewitt / @tyndyll
caveat emptor
I’m an engineer, not a computer scientist… these are the opinions of someone that has been using Go in production for 5+ years and likes it because it gets stuff done,
not because it is some version of computing purity
What is Go? Go (often referred to
as Golang) is a
statically typed,
compiled
programming
language designed at
Google
– Wikipedia
A definition of Go as a programming language. Static typed, so we are having to declare what type are variables are, and compiled, so that to run our code we need to
use the go compiler to execute the code
Why is Go?
Asking the question Why is Go is important, as the context it was created in, and the problems it was trying to solve explains the rationalisation behind the language and
why some decisions were made
– Rob Pike
“The goals of the Go project were to eliminate the
slowness and clumsiness of software development at
Google, and thereby to make the process more productive
and scalable. The language was designed by and for
people who write—and read and debug and maintain—
large software systems.”
Google was originally created at Google in 2007. According to Rob Pike, one of Go’s authors at his talk at Splash 2012 Google was having issues regarding build speeds,
on boarding developers and drift across their code. His presentation gives a lot of context

https://talks.golang.org/2012/splash.article

His talks are always worth a watch.

The conclusion we can come to is that Go was created, not as a exercise in language design, but rather an attempt to solve software engineering problems.
It must work at scale
It must be familiar, roughly C-like.
It must be modern.
dl.google.com
These are the three conclusions that the Go development team came up with initially. Working at scale refers to both running the software, and to the number and size of
teams. Familiar and C like refers to the fact that Java, C++ and Python were the developers that Google had and were hiring at the time so it had to take that into
account. Must be modern refers to the fact that it was being developed in 2007. At this time Google had been working in the web for a considerable time, and new what
was required for success in this environment - HTTP, cryptography, concurrency and memory protection.

dl.google.com was one of the first services written in Go that was released into production. This services handles all downloads at Google - Chrome, Android, SDKs - so
it is heavily loaded and well tested
What is Go?
So lets look at some Go
This is the code we are going to be looking at. It’s a simple Hello World application, but it is a web server, with some concurrency built in, so that when a request to say
hello comes in, it will return, but also pass the request through to a Printer service

The code and more comments and commentary, including how to execute and build the code, will be found at 

https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
This slide shows packages and how they are imported. This `main` package is the entry point to the program. The two packages imported, `fmt` and `net/http` are part of
the standard library. The lower code snippets show how external packages are imported. These are pulled by using the built in tool `go get`, which will clone code from a
repository. This repository can be public or private. Once imported, the packages would be available as `alexa.TypeName`. For more see

https://tour.golang.org/basics/1
This is a demonstration of how structs are implemented. See the gist for further details

https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
What if I want to log?
This is a demonstration of how interfaces are implemented. The interface declares that this interface is satisfied by any struct that has a `Print(string)` function. There are
no additional keywords such as implements. Also note that there are no public or private keywords. This is because this is implemented in go by making functions and
types that have a capital letter Public, and functions and types with a lower case letter private.

Something else of interest - if the developer decides that simply printing the string is not enough and they want a timestamped log entry instead, they can import the log
by adding it to the import statement above, and changing the fmt on line 15 to log. However, this will not compile. One of the features of Go is that it demands that
unused code is removed. This is in response to the problem of non required dependencies existing, and causing confusion in future development. Removing the fmt
package would allow the file to compile again

See the gist for further details, including an additional implementation of a Printer

https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
This is where all of the action happens. As in many programming languages, main is the programs entry point. See the gist for further commentary

https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
Why Should
You Care?
So we’ve seen Go, so why should we pick it up in 2019?
Squillions
of Dollars
Can’t Be
Wrong*
* This is a terrible reason
This page lists a number of companies and products that are using Go heavily. This is not to indicate that writing in Go will create a billion dollar unicorn, but more to
demonstrate that many types of products (networking, APIs, tooling, databases, smart contracts) are being developed and heavily used in production across the industry
Similarly, with our Belfast focus, these are companies locally that are using Go everyday. Learning Go isn’t niche, and there are jobs and opportunities available
Tooling
• Built in Libraries

• Built in tools…

• Testing

• Deployment
Tooling is one of the primary features of Go, and it’s one of the reasons that Go is scalable across teams. Aside from the fantastic standard library (https://golang.org/
pkg/), Go has a huge number of tools as part of the distribution (https://golang.org/cmd/). The standout is gofmt, which formats code into the Right Way. This makes Go
code extremely readable no matter what team has written it. go test is also built in, which makes testing a first class component of Go. 

Deployment is interesting also. Go is a compiled language, producing a single binary with all libraries statically compiled into it. Compiling for different platforms or
architectures is as simple as setting the GOOS (darwin, linux, windows) or GOARCH (386, amd64, arm etc) environmental variables respectively. There is more
information in the `Compiling` section of the gist. Also of interest - Go is now available as AWS Lambdas or Google Cloud Functions, as well as being an ideal candidate
for docker containers.
Learning and Support
•Tiny base language
•Decisions made for
you
•Good docs
•IDE’s
•Helpful community
•Playground
•Fast development
cycle
I believe that Go makes an excellent teaching language, and as such is easy to pick up (25 keywords with a fully populated standard library). While static typing may
seem more complicated than dynamic typing, the compiler is helpful in its error messages. 

Go is opinionated, deciding what the style of code should be and enforcing it both through gofmt and the compiler. You may have strong opinions about where curly
braces should be placed, but Go really doesn’t care. This is enforced through the compiler, for example, by not requiring semi colons to terminate statements and only
accepting newlines or braces.

The docs are great, and are locally available in the distribution by executing godoc -http :6060 (makes them available in a browser on port 6060). They are also built into
your code in a similar way to Javadocs (https://blog.golang.org/godoc-documenting-go-code)

Recommended IDE’s 

Goland - https://www.jetbrains.com/go/

VS Code - https://code.visualstudio.com/docs/languages/go

If you want to just dabble rather than setting everything up have a look at Golang Playground 

http://play.golang.org

What can’t be underestimated is the fast compile times. Compiling even large projects takes seconds, to the point where running `go run code.go` makes for a really
good scripting environment
So It’s Perfect? Well…
• Dependencies are
complicated
• Generics
• Error handling
These are currently being
actively addressed by the
community
I could explain these, but it’s easier to go straight to the source. The community is getting better at discussing their issues in public and using the community to help

Dependencies issues and conversation - https://github.com/golang/go/wiki/Modules

Generics issue and conversation - https://go.googlesource.com/proposal/+/master/design/go2draft-generics-overview.md

Error handling - https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md
• Easy to pick up

• Scales to Teams

• Feature packed standard
library

• Fantastic Tooling

• Good community

• 2.0 is coming
So Why Go?
Summing everything up
• Web services

• Networking services

• Command line tools

• Glue…

• Multi platform

• Lambda/Cloud Functions
So When Go?
When would you use it? Ironically on the morning of the talk Garth Gilmour (https://twitter.com/GarthGilmour) retweeted this

https://twitter.com/GarthGilmour/status/1084760622397575168

If you want to try Go, it’s design makes this really straightforward. Download and install, and get started. Everything is possible in a single file, managing dependencies is
straightforward, if it is required (again, you can go far on the standard library alone). If you have a simple idea for anything like the above, I strongly encourage you to give
Go a look. If I can help, my Twitter handle is on the next slide

With regard to “Glue” above. Using C libraries in Go is pretty straightforward. If you have something you need a C library for, why not wrap it in Go? 

https://blog.golang.org/c-go-cgo
GOTO
• https://tour.golang.org/

• https://gobyexample.com

• Belfast Gophers

• Training?

• @tyndyll on Twitter
Twitter is the easiest place to find me

Weitere ähnliche Inhalte

Was ist angesagt?

0581OS_FM_Final_NT
0581OS_FM_Final_NT0581OS_FM_Final_NT
0581OS_FM_Final_NT
Vibhor Kumar
 
New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...
New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...
New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...
Vũ Nguyễn
 

Was ist angesagt? (20)

[INNOVATUBE] Tech Talk #3: Golang - Vũ Nguyễn
[INNOVATUBE] Tech Talk #3: Golang - Vũ Nguyễn [INNOVATUBE] Tech Talk #3: Golang - Vũ Nguyễn
[INNOVATUBE] Tech Talk #3: Golang - Vũ Nguyễn
 
When, how & why use golang in 2021 go benefits & use cases
When, how & why use golang in 2021  go benefits & use casesWhen, how & why use golang in 2021  go benefits & use cases
When, how & why use golang in 2021 go benefits & use cases
 
Golang
GolangGolang
Golang
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventure
 
0581OS_FM_Final_NT
0581OS_FM_Final_NT0581OS_FM_Final_NT
0581OS_FM_Final_NT
 
Advantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworksAdvantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworks
 
Microservices in Golang
Microservices in GolangMicroservices in Golang
Microservices in Golang
 
GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
 
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
 
(Live) build and run golang web server on android.avi
(Live) build and run golang web server on android.avi(Live) build and run golang web server on android.avi
(Live) build and run golang web server on android.avi
 
Golang skills session1: introduction
Golang skills session1: introductionGolang skills session1: introduction
Golang skills session1: introduction
 
Kotlin – Alternative oder Ergänzung zu Java?
Kotlin – Alternative oder Ergänzung zu Java?Kotlin – Alternative oder Ergänzung zu Java?
Kotlin – Alternative oder Ergänzung zu Java?
 
Water Softening Of the House Water with the Help of Water Softener Systems
Water Softening Of the House Water with the Help of Water Softener SystemsWater Softening Of the House Water with the Help of Water Softener Systems
Water Softening Of the House Water with the Help of Water Softener Systems
 
really really really awesome php application with bdd behat and iterfaces
really really really awesome php application with bdd behat and iterfacesreally really really awesome php application with bdd behat and iterfaces
really really really awesome php application with bdd behat and iterfaces
 
GraphQL - hot or not? How to simplify API based services?
GraphQL - hot or not? How to simplify  API based services?GraphQL - hot or not? How to simplify  API based services?
GraphQL - hot or not? How to simplify API based services?
 
Let's Go @ St. Louis CocoaHeads
Let's Go @ St. Louis CocoaHeadsLet's Go @ St. Louis CocoaHeads
Let's Go @ St. Louis CocoaHeads
 
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
 
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering LabVoxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
 
New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...
New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...
New trends of web technology on mobile: HTML5, PhoneGap & NaCl - Barcamp Saig...
 
The Why of Go
The Why of GoThe Why of Go
The Why of Go
 

Ähnlich wie Introduction to Go

Go Within Cloud Foundry
Go Within Cloud FoundryGo Within Cloud Foundry
Go Within Cloud Foundry
Platform CF
 

Ähnlich wie Introduction to Go (20)

Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Enterprise 2020
Enterprise 2020Enterprise 2020
Enterprise 2020
 
Why Go Lang?
Why Go Lang?Why Go Lang?
Why Go Lang?
 
Untangling4
Untangling4Untangling4
Untangling4
 
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
 
Golang : A Hype or the Future?
Golang : A Hype or the Future?Golang : A Hype or the Future?
Golang : A Hype or the Future?
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language
 
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5
 
Beginning development in go
Beginning development in goBeginning development in go
Beginning development in go
 
Hire golang developers and make the shift to brighter business future (build ...
Hire golang developers and make the shift to brighter business future (build ...Hire golang developers and make the shift to brighter business future (build ...
Hire golang developers and make the shift to brighter business future (build ...
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
A First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageA First Look at Google's Go Programming Language
A First Look at Google's Go Programming Language
 
Go Within Cloud Foundry
Go Within Cloud FoundryGo Within Cloud Foundry
Go Within Cloud Foundry
 
Grails at DMC Digital
Grails at DMC DigitalGrails at DMC Digital
Grails at DMC Digital
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
[2020 git lab commit] continuous infrastructure
[2020 git lab commit] continuous infrastructure[2020 git lab commit] continuous infrastructure
[2020 git lab commit] continuous infrastructure
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
 
Introduction to go, and why it's awesome
Introduction to go, and why it's awesomeIntroduction to go, and why it's awesome
Introduction to go, and why it's awesome
 
Features of go
Features of goFeatures of go
Features of go
 

Kürzlich hochgeladen

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Kürzlich hochgeladen (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in 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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%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
 

Introduction to Go

  • 1. Go Because most times Javascript isn’t enough Simon Hewitt / @tyndyll
  • 2. caveat emptor I’m an engineer, not a computer scientist… these are the opinions of someone that has been using Go in production for 5+ years and likes it because it gets stuff done, not because it is some version of computing purity
  • 3. What is Go? Go (often referred to as Golang) is a statically typed, compiled programming language designed at Google – Wikipedia A definition of Go as a programming language. Static typed, so we are having to declare what type are variables are, and compiled, so that to run our code we need to use the go compiler to execute the code
  • 4. Why is Go? Asking the question Why is Go is important, as the context it was created in, and the problems it was trying to solve explains the rationalisation behind the language and why some decisions were made
  • 5. – Rob Pike “The goals of the Go project were to eliminate the slowness and clumsiness of software development at Google, and thereby to make the process more productive and scalable. The language was designed by and for people who write—and read and debug and maintain— large software systems.” Google was originally created at Google in 2007. According to Rob Pike, one of Go’s authors at his talk at Splash 2012 Google was having issues regarding build speeds, on boarding developers and drift across their code. His presentation gives a lot of context https://talks.golang.org/2012/splash.article His talks are always worth a watch. The conclusion we can come to is that Go was created, not as a exercise in language design, but rather an attempt to solve software engineering problems.
  • 6. It must work at scale It must be familiar, roughly C-like. It must be modern. dl.google.com These are the three conclusions that the Go development team came up with initially. Working at scale refers to both running the software, and to the number and size of teams. Familiar and C like refers to the fact that Java, C++ and Python were the developers that Google had and were hiring at the time so it had to take that into account. Must be modern refers to the fact that it was being developed in 2007. At this time Google had been working in the web for a considerable time, and new what was required for success in this environment - HTTP, cryptography, concurrency and memory protection. dl.google.com was one of the first services written in Go that was released into production. This services handles all downloads at Google - Chrome, Android, SDKs - so it is heavily loaded and well tested
  • 7. What is Go? So lets look at some Go
  • 8. This is the code we are going to be looking at. It’s a simple Hello World application, but it is a web server, with some concurrency built in, so that when a request to say hello comes in, it will return, but also pass the request through to a Printer service The code and more comments and commentary, including how to execute and build the code, will be found at https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
  • 9. This slide shows packages and how they are imported. This `main` package is the entry point to the program. The two packages imported, `fmt` and `net/http` are part of the standard library. The lower code snippets show how external packages are imported. These are pulled by using the built in tool `go get`, which will clone code from a repository. This repository can be public or private. Once imported, the packages would be available as `alexa.TypeName`. For more see https://tour.golang.org/basics/1
  • 10. This is a demonstration of how structs are implemented. See the gist for further details https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
  • 11. What if I want to log? This is a demonstration of how interfaces are implemented. The interface declares that this interface is satisfied by any struct that has a `Print(string)` function. There are no additional keywords such as implements. Also note that there are no public or private keywords. This is because this is implemented in go by making functions and types that have a capital letter Public, and functions and types with a lower case letter private. Something else of interest - if the developer decides that simply printing the string is not enough and they want a timestamped log entry instead, they can import the log by adding it to the import statement above, and changing the fmt on line 15 to log. However, this will not compile. One of the features of Go is that it demands that unused code is removed. This is in response to the problem of non required dependencies existing, and causing confusion in future development. Removing the fmt package would allow the file to compile again See the gist for further details, including an additional implementation of a Printer https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
  • 12. This is where all of the action happens. As in many programming languages, main is the programs entry point. See the gist for further commentary https://gist.github.com/tyndyll/cce72c16dc112cbe7ffac44dbb1dc5e8
  • 13. Why Should You Care? So we’ve seen Go, so why should we pick it up in 2019?
  • 14. Squillions of Dollars Can’t Be Wrong* * This is a terrible reason
  • 15. This page lists a number of companies and products that are using Go heavily. This is not to indicate that writing in Go will create a billion dollar unicorn, but more to demonstrate that many types of products (networking, APIs, tooling, databases, smart contracts) are being developed and heavily used in production across the industry
  • 16. Similarly, with our Belfast focus, these are companies locally that are using Go everyday. Learning Go isn’t niche, and there are jobs and opportunities available
  • 17. Tooling • Built in Libraries • Built in tools… • Testing • Deployment Tooling is one of the primary features of Go, and it’s one of the reasons that Go is scalable across teams. Aside from the fantastic standard library (https://golang.org/ pkg/), Go has a huge number of tools as part of the distribution (https://golang.org/cmd/). The standout is gofmt, which formats code into the Right Way. This makes Go code extremely readable no matter what team has written it. go test is also built in, which makes testing a first class component of Go. Deployment is interesting also. Go is a compiled language, producing a single binary with all libraries statically compiled into it. Compiling for different platforms or architectures is as simple as setting the GOOS (darwin, linux, windows) or GOARCH (386, amd64, arm etc) environmental variables respectively. There is more information in the `Compiling` section of the gist. Also of interest - Go is now available as AWS Lambdas or Google Cloud Functions, as well as being an ideal candidate for docker containers.
  • 18. Learning and Support •Tiny base language •Decisions made for you •Good docs •IDE’s •Helpful community •Playground •Fast development cycle I believe that Go makes an excellent teaching language, and as such is easy to pick up (25 keywords with a fully populated standard library). While static typing may seem more complicated than dynamic typing, the compiler is helpful in its error messages. Go is opinionated, deciding what the style of code should be and enforcing it both through gofmt and the compiler. You may have strong opinions about where curly braces should be placed, but Go really doesn’t care. This is enforced through the compiler, for example, by not requiring semi colons to terminate statements and only accepting newlines or braces. The docs are great, and are locally available in the distribution by executing godoc -http :6060 (makes them available in a browser on port 6060). They are also built into your code in a similar way to Javadocs (https://blog.golang.org/godoc-documenting-go-code) Recommended IDE’s Goland - https://www.jetbrains.com/go/ VS Code - https://code.visualstudio.com/docs/languages/go If you want to just dabble rather than setting everything up have a look at Golang Playground http://play.golang.org What can’t be underestimated is the fast compile times. Compiling even large projects takes seconds, to the point where running `go run code.go` makes for a really good scripting environment
  • 19. So It’s Perfect? Well… • Dependencies are complicated • Generics • Error handling These are currently being actively addressed by the community I could explain these, but it’s easier to go straight to the source. The community is getting better at discussing their issues in public and using the community to help Dependencies issues and conversation - https://github.com/golang/go/wiki/Modules Generics issue and conversation - https://go.googlesource.com/proposal/+/master/design/go2draft-generics-overview.md Error handling - https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md
  • 20. • Easy to pick up • Scales to Teams • Feature packed standard library • Fantastic Tooling • Good community • 2.0 is coming So Why Go? Summing everything up
  • 21. • Web services • Networking services • Command line tools • Glue… • Multi platform • Lambda/Cloud Functions So When Go? When would you use it? Ironically on the morning of the talk Garth Gilmour (https://twitter.com/GarthGilmour) retweeted this https://twitter.com/GarthGilmour/status/1084760622397575168 If you want to try Go, it’s design makes this really straightforward. Download and install, and get started. Everything is possible in a single file, managing dependencies is straightforward, if it is required (again, you can go far on the standard library alone). If you have a simple idea for anything like the above, I strongly encourage you to give Go a look. If I can help, my Twitter handle is on the next slide With regard to “Glue” above. Using C libraries in Go is pretty straightforward. If you have something you need a C library for, why not wrap it in Go? https://blog.golang.org/c-go-cgo
  • 22. GOTO • https://tour.golang.org/ • https://gobyexample.com • Belfast Gophers • Training? • @tyndyll on Twitter Twitter is the easiest place to find me