Upload
exotel
View
8.579
Download
3
Embed Size (px)
Citation preview
AgendaModern Compute Environment
Focus: What Problem does it Solve?
History
How is it Achieved
For C Programmers - Major Differences
Challenges in Modern Compute Landscape
EnvironmentMulti-CoreNetworked SystemsComputational ClustersWeb Programming ModelThousands of ProgrammersSame code baseScale of Development
Legacy LanguagesLanguage Feature ComplexGarbage CollectionMissing language support for ConcurrencyCompilation TimesDependency Management
Programmers digress from the real task!
Crux:
Focus
“Go’s purpose is therefore not to do research into programming language design; it is to improve the working
environment for its designers and their coworkers.”–Rob Pike
(Co-Designer of Go and Distinguished Engineer at Google)
History
HistoryInception: 2007Go 1.0 released in 2012Rob Pike, Ken Thompson and Robert Griesemer
HistoryBinary = 2000 X C++ Source BytesUnused Library IncludesConditional IncludesExtremely Slow Compilation
Even on Distributed Compilation System!
Desired FeaturesLight WeightIncrease Programmer EfficiencyCompiled LanguageConcurrencyGarbage CollectionStatically Typed
How is it Achieved?
HowNo unused import packagesDependency graph is preciseNo dependency cyclesOnly exported data availableOne object both exported and complete data
How40X faster compilation times than C++!
Differences between Go and C
SyntaxImport paths are URLsCleaner syntax
Syntax//Ctypedef struct A { int a; char b; }
//Gotype A struct { a int b char }
Syntax/* C *///Expression Syntaxint main(int argc, char *argv[])
// The Clockwise-Spiral Rule in C syntax parsingint (*(*fp)(int (*)(int, int), int))(int, int)
/* Go */// Type Syntaxfunc main(argc int, argv []string) int
//Left to rightf func(func(int,int) int, int) func(int, int) int
Syntax//Go can also return multiple value from function func ReadFile(r io.Reader) (num int, err error) { ...}...n, err := ReadFile(r)
Syntaxpackage util//Counter is visible when package is imported var Counter int
//name is not var name string
//Seenfunc ThisIsAlsoAvailable() error { }
//not seenfunc thisIsAPrivateFunction() error { }
ScopesUniverse (language identifiers)PackageFileFunctionBlock
SemanticsNo pointer arithmeticsNo implicit numeric conversionsArray bounds are always checkedtypes are not type aliases
type X int // X and int are distinct
Interface typesReflectionType switch
ConcurrencyGo RoutinesChannels - Communication Pipes
Concurrency
Light-weight threads of executionManaged by Go RuntimeRun concurrently with other go routinesExample
Shared resource manager QuerierDB Readeretc...
Go Routines
Concurrencypackage main import “fmt”
func myPrinter(str string) { fmt.Println(str)}
func main() { myPrinter(“one”) go myPrinter(“maybetwo”) go myPrinter(“maybethree”)}
//Output one maybetwo Maybethree
//Orone maybethree maybetwo
//Orone...
Concurrency
Shared pipes connecting concurrent go routinesChannels
Concurrencypackage main
import "fmt”
func main() { messages := make(chan string)
// Send a value `channel <-` go func() { messages <- "ping" }() //continued
//continued // Receive a value `<-channel` msg := <-messages fmt.Println(msg)}
//Output ping
GCEasier for ProgrammerNo overhead of memory allocation and freeingNo explicit memory freeing
InterfacesSet of methodsMethods on any typeData types implementing all methods satisfy
Thank You!SMITA [email protected]