Happy Go programing
-
Upload
pravin-mishra -
Category
Technology
-
view
116 -
download
0
description
Transcript of Happy Go programing
![Page 1: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/1.jpg)
Happy Go Programing.!
A Short Introduction
![Page 2: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/2.jpg)
Who am I
Pravin Mishra
Software Engineer @ShepHertz
Working on App42 PaaS (Public Cloud Platform-as-a-Service)
Keep in touch - @pravinmishra88
![Page 3: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/3.jpg)
What is Go?
- Go is a general-purpose language that bridges the gap between efficient statically typed languages and productive dynamic language.
- Go is an open source programming language. Go makes it easy to build simple, reliable, and efficient software.
![Page 4: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/4.jpg)
Go
• Initially developed at Google
• Created by Ken Thompson (Unix), Rob Pike
(Plan 9), and Russ Cox (libtask)
• Development started in 2007
• First release in 2009 (Fairly new!)
![Page 5: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/5.jpg)
Features
● Simple, minimal syntax● Fast compilation times● Easy concurrency support via goroutines● Garbage-collected● A flexible interface system● Statically linked binaries● Simple & Fun!
![Page 6: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/6.jpg)
Language focus
• System programming
• Networked / multi-core
• Fast
• Compatible with C
• Best of static typed language and dynamic typed languages
![Page 7: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/7.jpg)
Hello World
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
![Page 8: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/8.jpg)
Compiled language
$ go build hello.go
$ ls
hello hello.go
$ ./hello
Hello Word
![Page 9: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/9.jpg)
Strong types
func main() {
var str string
var value int
str = "abc"
value = 123
str + value
}
$ go run strong_type.go
prog.go:8: invalid operation: str + value (mismatched types string and int)
[process exited with non-zero status]
![Page 10: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/10.jpg)
Static Typed
// types.go
func main() {
var a string
a = 123
}
$ go run types.go
prog.go:5: cannot use 123 (type int) as type string in assignment
[process exited with non-zero status]
![Page 11: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/11.jpg)
with dynamic casting
package main
import ( "fmt" )
func main() {
a := 123
fmt.Printf("Value of a: %d", a)
}
- Value of a: 123
![Page 12: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/12.jpg)
User defined types
package main;
type Animal struct {
Name string
Age int
}
func main() {
var anaconda Animal
}
![Page 13: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/13.jpg)
Compiler
• Uses GCC as back end
• Checks for unused packages and variables
• Checks types and return values
![Page 14: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/14.jpg)
Go tools
• go fmt -> format your source code (cool!)
• go get -> manage and install your
dependencies
• go build / run -> compile and run your
program
• go test -> run your tests
![Page 15: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/15.jpg)
Organizing code
package string_processing;
func Process(str string) {
// Code code code
}
package main
import "string_processing"
func main() {
string_processing.Process("foobar")
}
![Page 16: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/16.jpg)
Who is using Go?
• Google (dl.google.com, youtube)
• SoundCloud
• Heroku
• CloudFlare
• Ubuntu
![Page 17: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/17.jpg)
Wrapping up...
• Cool language
• Concurrent and networked
• Benefits from both dynamic and static typed languages
• Modern
• Give it a try!
![Page 18: Happy Go programing](https://reader033.fdocuments.net/reader033/viewer/2022051210/54c845db4a795965098b45d8/html5/thumbnails/18.jpg)
Thank you.!