Go language presentation

1,225 views

Published on

Go programming language introduction

Published in: Software, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,225
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
48
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Go language presentation

  1. 1. ParamiSoft’s Pragmatic Pandit Talks Go-programming language 1
  2. 2. Why Go? No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously. There are several trends:! ! •! Computers are enormously quicker but software development is not faster.! ! •! Dependency management is a big part of software development today but the “header files” of languages in the C tradition are antithetical to clean dependency analysis—and fast compilation.! ! •! There is a growing rebellion against cumbersome type systems like those of Java and C++, pushing people towards dynamically typed languages such as Python and JavaScript.! ! •! Some fundamental concepts such as garbage collection and parallel computation are not well supported by popular systems languages.! ! •! The emergence of multicore computers has generated worry and confusion.! We believe it's worth trying again with a new language, a concurrent, garbage-collected language with fast compilation. Regarding the points above:! ! •! It is possible to compile a large Go program in a few seconds on a single computer.! ! •! Go provides a model for software construction that makes dependency analysis easy and avoids much of the overhead of C-style include files and libraries.! ! •! Go's type system has no hierarchy, so no time is spent defining the relationships between types. Also, although Go has static types the language attempts to make types feel lighter weight than in typical OO languages.! ! •! Go is fully garbage-collected and provides fundamental support for concurrent execution and communication.! ! •! By its design, Go proposes an approach for the construction of system software on multicore machines.! A much more expansive answer to this question is available in the article, Go at Google: Language Design in the Service of Software Engineering. 2
  3. 3. Guiding Principles in Design • reduce the amount of typing in both senses of the word! • reduce clutter and complexity ! • no forward declarations and no header files; everything is declared exactly once! • most radically, there is no type hierarchy: types just are, they don't have to announce their relationships! • Want more? - Go read FAQs - http://golang.org/doc/faq 3
  4. 4. Whats Go? • DNA of Go :) • compiled, statically-typed,imperative, concurrent and structured language. • compiled - gc compiler, memory managed by - garbage collection • statically typed with some dynamically typed capabilities • imperative - tell computer how to do e.g ruby, • declarative - tell computer what to do e.g scala • concurrent - multithreading as well as CPU parallelism. 4
  5. 5. Go by Example :) • Hello World! ! package main ! import "fmt" ! func main() { fmt.Println("hello world") } 5
  6. 6. Go by Example • package - is like libraries • fmt - the formatter. No need to format lines :) 6
  7. 7. Go by Example :) $go run hello-world.go hello world ! $ go build hello-world.go $ ls hello-world hello-world.go ! $ ./hello-world hello world 7
  8. 8. Go by Example :) • Values ! package main ! import "fmt" ! func main() { ! //Strings, which can be added together with +. ! fmt.Println("go" + "lang") // Integers and floats. fmt.Println("1+1 =", 1+1) ! fmt.Println("7.0/3.0 =", 7.0/3.0) ! // Booleans, with boolean operators as you’d expect. ! fmt.Println(true && false) fmt.Println(true || false) fmt.Println(!true) } ! $ go run values.go golang 1+1 = 2 7.0/3.0 = 2.3333333333333335 false true false 8
  9. 9. Go by Example :) Variables ! package main ! import "fmt" ! func main() { ! // var declares 1 or more variables. var a string = "initial" fmt.Println(a) ! // You can declare multiple variables at once. var b, c int = 1, 2 fmt.Println(b, c) ! //Go will infer the type of initialized variables. var d = true fmt.Println(d) ! //Variables declared without a corresponding initialization are zero-valued. For example, the zero value for an int is 0. var e int fmt.Println(e) ! //The := syntax is shorthand for declaring and initializing a variable, e.g. for var f string = "short" in this case. ! f := "short" fmt.Println(f) } ! ! $ go run variables.go initial 1 2 9
  10. 10. Go by Example :) •Functions ! ! ! package main ! import “fmt" ! // Here’s a function that takes two ints and returns their sum as an int. ! func plus(a int, b int) int { ! // Go requires explicit returns, i.e. it won’t automatically return the value of the last expression. ! return a + b } ! func main() { ! // Call a function just as you’d expect, with name(args). ! res := plus(1, 2) fmt.Println("1+2 =", res) } ! $ go run functions.go 1+2 = 3 10
  11. 11. Go by Example :) • Multiple return values ! package main ! import "fmt" ! // The (int, int) in this function signature shows that the function returns 2 ints. ! func vals() (int, int) { return 3, 7 } ! func main() { ! // Here we use the 2 different return values from the call with multiple assignment. a, b := vals() fmt.Println(a) fmt.Println(b) ! // If you only want a subset of the returned values, use the blank identifier _. _, c := vals() fmt.Println(c) } ! $ go run multiple-return-values.go 3 7 7 11
  12. 12. Go - Learn More https://gobyexample.com/ http://tour.golang.org http://golang.org/doc/effective_go.html http://go-lang.cat-v.org http://www.stanford.edu/class/ee380/Abstracts/ 100428.html 12
  13. 13. Go - Thank YourSelf! 13

×