SlideShare a Scribd company logo
Go Fundamentals
Agenda
● What is Go?
○ Guiding Principles
■ Why Simplicity is Important?
■ Why Readability is Important?
● Why You Should Learn Go?
○ Interest Over Time
○ Go In Production
○ What still needs work
● Syntax Overview
○ Hello World
● Go’s Concurrency Model
○ A Word on CSP And Communications Model
○ The Go Runtime
○ Goroutines
■ What Are Goroutines?
■ Goroutines VS. Threads
○ Channels
○ Examples
What Is Go?
Go (golang) is a programming language developed at
Google[9] in 2007 by Robert Griesemer, Rob Pike, and
Ken Thompson.[7]
Go is a general-purpose language designed with
systems programming in mind.
● strongly typed and garbage-collected and has
● explicit support for concurrent programming.
● Programs are constructed from packages, whose
properties allow efficient management of
dependencies.
● The existing implementations use a traditional
compile/link model to generate executable
binaries.
What Is Go?
Motivation:
● Needed a better language for what they do at Google
● Personal motivation: Wanted a clean, small, compiled language with
modern features.
● Clear about what was wrong: Complexity, missing concurrency support,
lack of scalability, insane build times.
● Good ideas about how to address issues.
● Unpolished thoughts about the rest.
● Three experienced people's insights on how not to do it.
Check out this lecture
History
● Project starts at Google in 2007 (by Griesemer, Pike, Thompson)
● Open source release in November 2009
● More than 250 contributors join the project
● Version 1.0 release in March 2012
Guiding Principles
Guiding principles
● Simplicity, safety, and readability are paramount.
● Striving for orthogonality in design.
● Minimal: One way to write a piece of code.
● It's about expressing algorithms, not the type
system.
Why Simplicity Is Important?
Simple Calculation The Ruby Way:
result = 0
for i in 0..10
result += i
end
(1..10).inject(0) { |result, element| result + element }
=> 55
(1..10).reduce(0) { |result, element| result + element }
=> 55
result = 0
(1..10).each{ |element| result += element }
=> 55
result = 0
(1..10).map { |element| result += element }
=> 55
This is without while, until and regular for
loops….
It's a bit overdoing it, but you get the picture..
Why Simplicity Is Important?
Simple Calculation The Gopher Way:
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
Why Readability Is Important?
• If a language has too many features, you waste time choosing which
ones to use.
• Then implement, refine, possibly rethink and redo.
• Later, "Why does the code work this way?"
• The code is harder to understand simply because it is using a more
complex language.
• Preferable to have just one way, or at least fewer, simpler ways.
• Features add complexity. We want simplicity.
• Features hurt readability. We want readability.
• Readability is paramount.
Why Readability Is Important?
• Readable means Reliable
• Readable code is reliable code.
• It's easier to understand.
• It's easier to work on.
• If it breaks, it's easier to fix.
• If the language is complicated:
– You must understand more things to read and work on the code.
– You must understand more things to debug and fix it.
A key tradeoff: More fun to write, or less work to maintain
Interpreted VS Statically Compiled
Interpreted Languages
• Execute instructions directly,
without previously compiling a
program into machine-
language instructions.
• The interpreter executes the
program directly, translating
each statement into a sequence
of one or more subroutines
already compiled into machine
code.
• Reflection
• Dynamic Typing - the process of
verifying the type safety of a
program at runtime
Compiled Languages
• Quicker than those translated
at run time, due to the
overhead of the translation
process.
• Static Typing - finding type
errors reliably at compile time,
which should increase the
reliability of the delivered
program
Interpreted VS Statically Compiled
Interpreted (High Level) Languages
• More Readable (Usually)
• Portable - Platform
Independent Like JVM
• Powerfull
• Flexible
• Slower execution compared to
direct native machine code
execution on the host CPU.
• Easily to Reverse Engineer
Some Examples:
Ruby, Python, Javascript, Perl,
Scheme and many more!
Compiled (Low Level) Languages
• Not platform-independent
• Adding one more step to
deployment and debugging
process
Some Examples:
C/C++, Java, C#, Go, Visual basic,
Haskell, Erlang, Rust and others
So, Why You Should Learn Go?
• Modern
• Compact, concise, general-
purpose
• Imperative statically type-
checked, dynamically type-safe
• Garbage-collected
• Compiles to native code,
statically linked
• Fast compilation, efficient
execution
• Multi Platform Support
• Extensive Standard Library
Designed by programmers for programmers!
Interest Over Time
Go In Production
Go Helps Google
• Slow builds
• Uncontrolled dependencies
• Each programmer using a different subset of the language
• Poor program understanding (code hard to read, poorly documented,
and so on)
• Duplication of effort
• Cost of updates
• Version skew
• Difficulty of writing automatic tools
• Cross-language builds
Not All Is Good In The Hood
● Error handling / no Exceptions
● No generics
● Stuck in 70’s
● No OOP - No Inheritance, You can Embed
● Version Management of Dependencies - Some Solutions but should be
released in the next Go release
● Getting time to get used to if you come from a Proper OOP Language.
Hello World
package main
import "fmt"
func main() {
fmt.Println("Greetings, fellow gopher")
}
Syntax Overview
Golang Tour
Go’s Concurrency Model
Why We Should care about languages that use concurrency?
The modern world is parallel
● Multicore.
● Networks.
● Clouds of CPUs.
● Loads of users.
● Our technology should help.
That's where concurrency comes in.
Go’s Concurrency Model
Go Concurrency relies on Tony Hoare's
Communicating sequential processes article
from 1978
Message Passing Model with Interprocess
communication
The Most important slogan of all:
“Do not communicate by sharing
memory; instead, share memory by
communicating.”
Go’s Concurrency Model
Traditional threading models (commonly used when writing Java, C++,
and Python programs, for example) require the programmer to
communicate between threads using shared memory. Typically, shared
data structures are protected by locks, and threads will contend over
those locks to access the data
Go provides:
● Concurrent execution (goroutines)
● Synchronization and messaging (channels)
● Multi-way concurrent control (select)
● (and Also mutex for old school locking)
The Go Runtime
Package runtime contains operations that interact with Go's runtime system,
such as functions to control goroutines.
it contains a runtime which provides garbage collection, reflection and many
other features.
Why Go’s Executable Are HUGE!?
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:
So This:
func main() {
fmt.Println("start")
doSomething()
fmt.Println("end")
}
Becomes:
func main() {
fmt.Println("start")
go doSomething()
fmt.Println("end")
}
Goroutines VS. Threads
• Memory Consumption - 2kb vs 1mb
• Setup and teardown costs - No Resources from the os, Only the runtime
• Switching costs - Registers Switching
• How goroutines are executed - Runtime allocated os threads and distribute
goroutines on them
Goroutines VS. Threads
• Goroutines blocking
Goroutines are cheap and do not cause the thread on which they are multiplexed to block if they
are blocked on
– network input
– sleeping
– channel operations or
– blocking on primitives in the sync package.
Even if tens of thousands of goroutines have been spawned, it's not a waste of system
resources if most of them are blocked on one of these since the runtime schedules another
goroutine instead.
In simple terms, goroutines are a lightweight abstraction over threads.
A Go programmer does not deal with threads, and similarly the OS is not aware of the existence
of goroutines. From the OS's perspective, a Go program will behave like an event-driven C
program. [5]
Examples Of Goroutines
Concurrency for beginners
Channels
Channels are a staple of
concurrency built right into the Go
language, and provide a way for
goroutines to synchronise, and
share information.
Example Of Channels
Ping Pong
Cool Example using Goroutines
Thank You.

More Related Content

What's hot

A sip of elixir
A sip of elixirA sip of elixir
A sip of elixir
Uttam Kini
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
Barry Jones
 
Clojure
ClojureClojure
Clojure
Diego Pacheco
 
Powerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesPowerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming Languages
FAST
 
One VM to Rule Them All
One VM to Rule Them AllOne VM to Rule Them All
One VM to Rule Them All
Tianxiang Xiong
 
OpenMP
OpenMPOpenMP
Java Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextJava Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and context
Tomek Borek
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
Bruno Bossola
 
Microservices - the lean way
Microservices - the lean wayMicroservices - the lean way
Microservices - the lean way
Bruno Bossola
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
Filip Bruun Bech-Larsen
 
Jython in workflow and rules engines
Jython in workflow and rules enginesJython in workflow and rules engines
Jython in workflow and rules enginesVaclav Tunka
 
Learning Python
Learning PythonLearning Python
Learning Python
Mindy McAdams
 
10 books that every developer must read
10 books that every developer must read10 books that every developer must read
10 books that every developer must read
Ganesh Samarthyam
 
Green Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native PerformanceGreen Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native Performance
Green Custard
 
Want to write a book in Jupyter - here's how
Want to write a book in Jupyter - here's howWant to write a book in Jupyter - here's how
Want to write a book in Jupyter - here's how
Jim Arlow
 
A peek into Python's Metaclass and Bytecode from a Smalltalk User
A peek into Python's Metaclass and Bytecode from a Smalltalk UserA peek into Python's Metaclass and Bytecode from a Smalltalk User
A peek into Python's Metaclass and Bytecode from a Smalltalk User
Koan-Sin Tan
 
Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...
Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...
Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...
eraser Juan José Calderón
 
Switching from Puppet to Ansible
Switching from Puppet to AnsibleSwitching from Puppet to Ansible
Switching from Puppet to Ansible
Dennis Rowe
 
Functional programming is not about complicated things
Functional programming is not about complicated thingsFunctional programming is not about complicated things
Functional programming is not about complicated things
Michael Langford
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
Camille Bell
 

What's hot (20)

A sip of elixir
A sip of elixirA sip of elixir
A sip of elixir
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
 
Clojure
ClojureClojure
Clojure
 
Powerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesPowerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming Languages
 
One VM to Rule Them All
One VM to Rule Them AllOne VM to Rule Them All
One VM to Rule Them All
 
OpenMP
OpenMPOpenMP
OpenMP
 
Java Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextJava Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and context
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 
Microservices - the lean way
Microservices - the lean wayMicroservices - the lean way
Microservices - the lean way
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
 
Jython in workflow and rules engines
Jython in workflow and rules enginesJython in workflow and rules engines
Jython in workflow and rules engines
 
Learning Python
Learning PythonLearning Python
Learning Python
 
10 books that every developer must read
10 books that every developer must read10 books that every developer must read
10 books that every developer must read
 
Green Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native PerformanceGreen Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native Performance
 
Want to write a book in Jupyter - here's how
Want to write a book in Jupyter - here's howWant to write a book in Jupyter - here's how
Want to write a book in Jupyter - here's how
 
A peek into Python's Metaclass and Bytecode from a Smalltalk User
A peek into Python's Metaclass and Bytecode from a Smalltalk UserA peek into Python's Metaclass and Bytecode from a Smalltalk User
A peek into Python's Metaclass and Bytecode from a Smalltalk User
 
Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...
Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...
Google’s Multilingual Neural Machine Translation System: Enabling Zero-Shot T...
 
Switching from Puppet to Ansible
Switching from Puppet to AnsibleSwitching from Puppet to Ansible
Switching from Puppet to Ansible
 
Functional programming is not about complicated things
Functional programming is not about complicated thingsFunctional programming is not about complicated things
Functional programming is not about complicated things
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 

Similar to Go fundamentals

Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
Amal Mohan N
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
SingleStore
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
paramisoft
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 
Creating a compiler for your own language
Creating a compiler for your own languageCreating a compiler for your own language
Creating a compiler for your own language
Andrea Tino
 
Golang
GolangGolang
Golang
GolangGolang
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
ShubhamMishra485
 
Go lang
Go langGo lang
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
Simon Hewitt
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Dave Fancher
 
go language- haseeb.pptx
go language- haseeb.pptxgo language- haseeb.pptx
go language- haseeb.pptx
ArsalanMaqsood1
 
Go programming language
Go programming languageGo programming language
Go programming language
Appstud
 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)
Wilfried Schobeiri
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
Ganesh Samarthyam
 
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
Ganesh Samarthyam
 
Advantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworksAdvantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworks
Katy Slemon
 
Go Language presentation
Go Language presentationGo Language presentation
Go Language presentation
Gh-Mohammed Eldadah
 
Presentation-1.pptx
Presentation-1.pptxPresentation-1.pptx
Presentation-1.pptx
animewatcher7
 

Similar to Go fundamentals (20)

Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
 
computer languages
computer languagescomputer languages
computer languages
 
Creating a compiler for your own language
Creating a compiler for your own languageCreating a compiler for your own language
Creating a compiler for your own language
 
Golang
GolangGolang
Golang
 
Golang
GolangGolang
Golang
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
 
Go lang
Go langGo lang
Go lang
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
go language- haseeb.pptx
go language- haseeb.pptxgo language- haseeb.pptx
go language- haseeb.pptx
 
Go programming language
Go programming languageGo programming language
Go programming language
 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)
 
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
 
Advantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworksAdvantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworks
 
Go Language presentation
Go Language presentationGo Language presentation
Go Language presentation
 
Presentation-1.pptx
Presentation-1.pptxPresentation-1.pptx
Presentation-1.pptx
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 

Recently uploaded (20)

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 

Go fundamentals

  • 2. Agenda ● What is Go? ○ Guiding Principles ■ Why Simplicity is Important? ■ Why Readability is Important? ● Why You Should Learn Go? ○ Interest Over Time ○ Go In Production ○ What still needs work ● Syntax Overview ○ Hello World ● Go’s Concurrency Model ○ A Word on CSP And Communications Model ○ The Go Runtime ○ Goroutines ■ What Are Goroutines? ■ Goroutines VS. Threads ○ Channels ○ Examples
  • 3. What Is Go? Go (golang) is a programming language developed at Google[9] in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.[7] Go is a general-purpose language designed with systems programming in mind. ● strongly typed and garbage-collected and has ● explicit support for concurrent programming. ● Programs are constructed from packages, whose properties allow efficient management of dependencies. ● The existing implementations use a traditional compile/link model to generate executable binaries.
  • 4. What Is Go? Motivation: ● Needed a better language for what they do at Google ● Personal motivation: Wanted a clean, small, compiled language with modern features. ● Clear about what was wrong: Complexity, missing concurrency support, lack of scalability, insane build times. ● Good ideas about how to address issues. ● Unpolished thoughts about the rest. ● Three experienced people's insights on how not to do it. Check out this lecture
  • 5. History ● Project starts at Google in 2007 (by Griesemer, Pike, Thompson) ● Open source release in November 2009 ● More than 250 contributors join the project ● Version 1.0 release in March 2012
  • 6. Guiding Principles Guiding principles ● Simplicity, safety, and readability are paramount. ● Striving for orthogonality in design. ● Minimal: One way to write a piece of code. ● It's about expressing algorithms, not the type system.
  • 7. Why Simplicity Is Important? Simple Calculation The Ruby Way: result = 0 for i in 0..10 result += i end (1..10).inject(0) { |result, element| result + element } => 55 (1..10).reduce(0) { |result, element| result + element } => 55 result = 0 (1..10).each{ |element| result += element } => 55 result = 0 (1..10).map { |element| result += element } => 55 This is without while, until and regular for loops…. It's a bit overdoing it, but you get the picture..
  • 8. Why Simplicity Is Important? Simple Calculation The Gopher Way: sum := 0 for i := 0; i < 10; i++ { sum += i }
  • 9. Why Readability Is Important? • If a language has too many features, you waste time choosing which ones to use. • Then implement, refine, possibly rethink and redo. • Later, "Why does the code work this way?" • The code is harder to understand simply because it is using a more complex language. • Preferable to have just one way, or at least fewer, simpler ways. • Features add complexity. We want simplicity. • Features hurt readability. We want readability. • Readability is paramount.
  • 10. Why Readability Is Important? • Readable means Reliable • Readable code is reliable code. • It's easier to understand. • It's easier to work on. • If it breaks, it's easier to fix. • If the language is complicated: – You must understand more things to read and work on the code. – You must understand more things to debug and fix it. A key tradeoff: More fun to write, or less work to maintain
  • 11. Interpreted VS Statically Compiled Interpreted Languages • Execute instructions directly, without previously compiling a program into machine- language instructions. • The interpreter executes the program directly, translating each statement into a sequence of one or more subroutines already compiled into machine code. • Reflection • Dynamic Typing - the process of verifying the type safety of a program at runtime Compiled Languages • Quicker than those translated at run time, due to the overhead of the translation process. • Static Typing - finding type errors reliably at compile time, which should increase the reliability of the delivered program
  • 12. Interpreted VS Statically Compiled Interpreted (High Level) Languages • More Readable (Usually) • Portable - Platform Independent Like JVM • Powerfull • Flexible • Slower execution compared to direct native machine code execution on the host CPU. • Easily to Reverse Engineer Some Examples: Ruby, Python, Javascript, Perl, Scheme and many more! Compiled (Low Level) Languages • Not platform-independent • Adding one more step to deployment and debugging process Some Examples: C/C++, Java, C#, Go, Visual basic, Haskell, Erlang, Rust and others
  • 13. So, Why You Should Learn Go? • Modern • Compact, concise, general- purpose • Imperative statically type- checked, dynamically type-safe • Garbage-collected • Compiles to native code, statically linked • Fast compilation, efficient execution • Multi Platform Support • Extensive Standard Library Designed by programmers for programmers!
  • 16. Go Helps Google • Slow builds • Uncontrolled dependencies • Each programmer using a different subset of the language • Poor program understanding (code hard to read, poorly documented, and so on) • Duplication of effort • Cost of updates • Version skew • Difficulty of writing automatic tools • Cross-language builds
  • 17. Not All Is Good In The Hood ● Error handling / no Exceptions ● No generics ● Stuck in 70’s ● No OOP - No Inheritance, You can Embed ● Version Management of Dependencies - Some Solutions but should be released in the next Go release ● Getting time to get used to if you come from a Proper OOP Language.
  • 18. Hello World package main import "fmt" func main() { fmt.Println("Greetings, fellow gopher") }
  • 20. Go’s Concurrency Model Why We Should care about languages that use concurrency? The modern world is parallel ● Multicore. ● Networks. ● Clouds of CPUs. ● Loads of users. ● Our technology should help. That's where concurrency comes in.
  • 21. Go’s Concurrency Model Go Concurrency relies on Tony Hoare's Communicating sequential processes article from 1978 Message Passing Model with Interprocess communication The Most important slogan of all: “Do not communicate by sharing memory; instead, share memory by communicating.”
  • 22. Go’s Concurrency Model Traditional threading models (commonly used when writing Java, C++, and Python programs, for example) require the programmer to communicate between threads using shared memory. Typically, shared data structures are protected by locks, and threads will contend over those locks to access the data Go provides: ● Concurrent execution (goroutines) ● Synchronization and messaging (channels) ● Multi-way concurrent control (select) ● (and Also mutex for old school locking)
  • 23. The Go Runtime Package runtime contains operations that interact with Go's runtime system, such as functions to control goroutines. it contains a runtime which provides garbage collection, reflection and many other features. Why Go’s Executable Are HUGE!?
  • 24. 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: So This: func main() { fmt.Println("start") doSomething() fmt.Println("end") } Becomes: func main() { fmt.Println("start") go doSomething() fmt.Println("end") }
  • 25. Goroutines VS. Threads • Memory Consumption - 2kb vs 1mb • Setup and teardown costs - No Resources from the os, Only the runtime • Switching costs - Registers Switching • How goroutines are executed - Runtime allocated os threads and distribute goroutines on them
  • 26. Goroutines VS. Threads • Goroutines blocking Goroutines are cheap and do not cause the thread on which they are multiplexed to block if they are blocked on – network input – sleeping – channel operations or – blocking on primitives in the sync package. Even if tens of thousands of goroutines have been spawned, it's not a waste of system resources if most of them are blocked on one of these since the runtime schedules another goroutine instead. In simple terms, goroutines are a lightweight abstraction over threads. A Go programmer does not deal with threads, and similarly the OS is not aware of the existence of goroutines. From the OS's perspective, a Go program will behave like an event-driven C program. [5]
  • 28. Channels Channels are a staple of concurrency built right into the Go language, and provide a way for goroutines to synchronise, and share information.
  • 29. Example Of Channels Ping Pong Cool Example using Goroutines

Editor's Notes

  1. Large Codebase and many Developers its important that code will be readable and easy to understand for new developers
  2. https://talks.golang.org/2015/simplicity-is-complicated.slide#1
  3. https://talks.golang.org/2015/simplicity-is-complicated.slide#1
  4. https://github.com/golang/go/wiki/GoUsers
  5. https://divan.github.io/posts/go_complain_howto/
  6. Main Package, Imports, Main Func
  7. http://tour.golang.org/welcome/1
  8. Go's concurrency primitives - goroutines and channels - provide an elegant and distinct means of structuring concurrent software. (These concepts have an interesting history that begins with C. A. R. Hoare's Communicating Sequential Processes.) Instead of explicitly using locks to mediate access to shared data, Go encourages the use of channels to pass references to data between goroutines. This approach ensures that only one goroutine has access to the data at a given time. The concept is summarized in the document
  9. http://divan.github.io/posts/go_concurrency_visualize/
  10. http://blog.nindalf.com/how-goroutines-work/ Memory Consumption The creation of a goroutine does not require much memory - only 2kB of stack space. They grow by allocating and freeing heap storage as required.[2][3] Threads on the other hand start out at 1Mb (500 times more), along with a region of memory called a guard page that acts as a guard between one thread's memory and another.[7] A server handling incoming requests can therefore create one goroutine per request without a problem, but one thread per request will eventually lead to the dreaded OutOfMemoryError. Setup and teardown costs Threads have significant setup and teardown costs because it has to request resources from the OS and return it once its done. The workaround to this problem is to maintain a pool of threads. In contrast, goroutines are created and destroyed by the runtime and those operations are pretty cheap. The language doesn't support manual management of goroutines. Switching costs When a thread blocks another has to be scheduled in its place. Threads are scheduled preemptively, and during a thread switch, the scheduler needs to save/restore ALL registers, that is, 16 general purpose registers, PC (Program Counter), SP (Stack Pointer), segment registers, 16 XMM registers, FP coprocessor state, 16 AVX registers, all MSRs etc. This is quite significant when there is rapid switching between threads. Goroutines are scheduled cooperatively and when a switch occurs, only 3 registers need to be saved/restored - Program Counter, Stack Pointer and DX. The cost is much lower. How goroutines are executed As mentioned earlier, the runtime manages the goroutines throughout from creation to scheduling to teardown. The runtime is allocated a few threads on which all the goroutines are multiplexed. At any point of time, each thread will be executing one goroutine. If that goroutine is blocked, then it will be swapped out for another goroutine that will execute on that thread instead.[6]
  11. http://blog.nindalf.com/how-goroutines-work/
  12. http://divan.github.io/posts/go_concurrency_visualize/
  13. Any Questions? https://talks.golang.org/2012/waza.slide#22