SlideShare a Scribd company logo
Overview of Go Language
GoLang
• Critics: There is nothing new in Go
• GoLang Designers: The task of programming
language designer "is consolidation not innovation"
• Less is exponentially more – Rob Pike, Go Designer
• Do Less, Enable More – Russ Cox, Go Tech Lead
Why new programming language
• Computers are faster but not software development
• Dependency management is critical
• Dynamically typed languages such as Python and JS
• Garbage collection and parallel are not well
supported by popular system languages
• Multicore computers
GoLang
• Go Fast
• Go Simple
• Natively complied (similar to C/C++)
• Static typing
• Fully garbage collection supported
• Support for concurrency and networking
• Rich standard library
• System & Server-side programming
• Scalable
• Open source. Inspired by: C, Pascal, CSP
Who
• Robert Griesemer, Ken Thompson, and Rob Pike
started the project in late 2007
• By mid 2008 the language was mostly designed and
the implementation (compiler, runtime) starting to
work
• Ian Lance Taylor and Russ Cox joined in 2008
• Lots of help from many others
• Officially announced in November 2009
• March 2012: Go 1.0
Go Users
• Google services: YouTube, Kubernetes
• Docker
• Dropbox
• eBay
• Facebook
• Lyft
• Uber
• PayPal
Go Usages
• Large scale distributed systems
• Cloud: GCP, Cloud Foundry, Heroku…
• Web development
• Scripting
• System programming
• Open-source project
Popularity
Install Go
• The Go Playground: https://go.dev/play/
• Install Go: https://go.dev/dl/
• Visual Studio Code + extension
• Go packages doc: https://pkg.go.dev/
First Go Program
• Every Go file starts with
package
• import: packages use
• func main: entry of a Go
program
• Can use semicolons to
separate statements
(optional)
• go run file.go
package main
import "fmt" //comments
func main() {
fmt.Println("Hello world!")
}
fmt Package
• Print
• Println
• Printf
• Scan
• Scanln
• Scanf
fmt Package
package main
import "fmt"
func main() {
var name string
fmt.Print("Enter your name: ")
fmt.Scanln(&name)
fmt.Printf("Hello, %s! n", name)
}
Variables
• Go is statically typed similar to C, C++, Pascal
• Implicit type declare
var name = " Hello " //name is string type
• Explicit declare
var name string = " Hello "
• Multiple declare
var x, y int
var (
name string
z int
)
• Multiple init
var x, y int = 1, 2
var (
name = " Hello "
z = 10
)
SIMILAR TO PASCAL
Variables
• Shorthand syntax
• Explicit declare
name string := " Hello " //no need var, := instead =
• Implicit declare
name := " Hello " //type is string
• Keyword const, cannot change value
const SIZE int = 10
Naming convention
• Camel case
• twoWordString
• iAmAPerson
• Global scope
• File scope
• Export global scope: starts with Uppercase
package main
import "fmt" //comments
var numberOne int = 10
var NumberTwo int = 20
func main() {
fmt.Println("Hello world!")
}
Primitive Data Types
• Boolean
• bool: true / false
• Numeric
• Integer: signed, unsigned (8 → 64 bit)
• Signed: int8, int16, int32, int64
• Unsigned: uint8, uint16, uint32, uint64
• Float:
• float32, float64
• Complex: complex64 (32 real, 32 imagine), complex128 (64 +
64)
• Text
• String: sequence of bytes, size varies
• Byte: UTF8
• Rune: UTF32
Primitive Data Types
package main
import "fmt" //comments
func main() {
var a complex64 = 2 + 3i
fmt.Println(a)
fmt.Println(real(a), imag(a))
a = complex(3, 5)
fmt.Println(a)
}
Type conversion
• Downsize or upsize
package main
import "fmt" //comments
func main() {
var i int = 1
var j float32 = float32(i)
j = 5.5
i = int(j)
i = 65
var s string = string(i)
}
String conversion
• strconv package
package main
import "fmt"
import "strconv"
func main() {
i := 65
var s string = strconv.Itoa(i)
}
Operators
• Mathematic: +, -, *, /, %
• Logical: &&, ||, !
• Relational: ==, !=, >, <, >=, <=
• Bitwise:
• & (and)
• | (or)
• ^ (xor, not)
• &^ (and not), 1 if both are 0s
• << (left shift)
• >> (right shift)
Enum
• List of constants
package main
import "fmt"
const (
zero = 0
one = 1
two = "two"
)
func main() {
}
Enum
• Using iota (default 0)
package main
import "fmt"
const (
zero = iota
one
two
)
func main() {
}
Array
• Fixed size
• Index starts at 0
• Declaration
var arr [3]int
• Initialization
nameList := [3]string {"A", "B", "C"}
• Implicit length
var arr […]int = {1, 2, 3}
• Multi dimensional array
var arr2D [2][3]int
Array
• Length of array: len(arr)
• Iterating through the array
for i,value := range arr {
fmt.Println(i, value)
}
• Assign array will copy
Slice
• Think of slice as dynamic array (but actually NOT)
var slc []int = {1, 2, 3}
//does not contain …
• Using make
slc := make([]int, 3) //len is 3
slc1 := make([]int, 0, 5)
//len is 0, cap is 5
• Append
slc = append(slc, 4)
• Assign slice will make reference. Use copy to duplicate
dup := make([]int, len(slc))
copy(dup, slc)
• Length: len(slc)
Slice Operator
• Slice support operator with the syntax
sliceName[low:high]
fmt.Println(slc[0:2])
fmt.Println(slc[0:3])
fmt.Println(slc[1:])
Map
• Similar to dictionary: map[key-type]value-type
student := map[int]string {
1: "A",
2: "B",
3: "C",}
• Using make
student := make(map[int]string)
• Length: len(student)
• Add new element: map[newKey] = value
• Delete: delete(map, key)
• Check existed
val, isExisted := student[5]
//val is empty string
• Slice cannot be key. Array is possible
• Assign will make reference
Struct
• Top level
type student struct {
id int
name string
grade float32
}
• Inline
studentA := struct {
id int
name string}{id:123,
name:"abc"}
• Access member using dot operator “.”
• Assign will make copy (same as array)
Struct
• Literals
student1 := student {
id: 123,
name: "abc",
grade: 5.5,
}
• Struct name and member must be capitalized to be
exported
Struct
• Embedded
type Person struct {
name string
age int
}
type Student struct {
Person //embedded by value
grade float32
}
• Access: student1.Person.name, student1.name
• Tag
type Student struct {
Person
grade float32 `grade must be 0 to 100`
}

More Related Content

PPTX
Golang - Overview of Go (golang) Language
PDF
Golang
PPTX
Golang iran - tutorial go programming language - Preliminary
PDF
Golang and Eco-System Introduction / Overview
PPTX
Introduction to Go
PDF
Go Lang Tutorial
PDF
golang_refcard.pdf
PPTX
Golang basics for Java developers - Part 1
Golang - Overview of Go (golang) Language
Golang
Golang iran - tutorial go programming language - Preliminary
Golang and Eco-System Introduction / Overview
Introduction to Go
Go Lang Tutorial
golang_refcard.pdf
Golang basics for Java developers - Part 1

Similar to Lecture 1 - Overview of Go Language 1.pdf (20)

PDF
Introduction to Programming in Go
PPTX
Should i Go there
PDF
Introduction to Go programming language
PDF
The GO programming language
PPTX
Go Programming Language (Golang)
PDF
Introduction to go language programming
PDF
Golang workshop
PDF
Go_ Get iT! .pdf
PPT
GO programming language
PPTX
Lab1GoBasicswithgo_foundationofgolang.pptx
PDF
Geeks Anonymes - Le langage Go
PPTX
Go programming introduction
PPTX
Go Language Hands-on Workshop Material
PDF
Go language presentation
PDF
Go Java, Go!
PDF
Coding in GO - GDG SL - NSBM
PPTX
The Go Programing Language 1
PDF
Getting started with Go at GDays Nigeria 2014
PPTX
Golang workshop - Mindbowser
PPT
Introduction to Go ProgrammingLanguage.ppt
Introduction to Programming in Go
Should i Go there
Introduction to Go programming language
The GO programming language
Go Programming Language (Golang)
Introduction to go language programming
Golang workshop
Go_ Get iT! .pdf
GO programming language
Lab1GoBasicswithgo_foundationofgolang.pptx
Geeks Anonymes - Le langage Go
Go programming introduction
Go Language Hands-on Workshop Material
Go language presentation
Go Java, Go!
Coding in GO - GDG SL - NSBM
The Go Programing Language 1
Getting started with Go at GDays Nigeria 2014
Golang workshop - Mindbowser
Introduction to Go ProgrammingLanguage.ppt
Ad

Recently uploaded (20)

PPTX
Vitamins & Minerals: Complete Guide to Functions, Food Sources, Deficiency Si...
PPTX
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
PPTX
Microbiology with diagram medical studies .pptx
PDF
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
PPTX
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
PPTX
SCIENCE10 Q1 5 WK8 Evidence Supporting Plate Movement.pptx
PDF
Biophysics 2.pdffffffffffffffffffffffffff
PDF
AlphaEarth Foundations and the Satellite Embedding dataset
PDF
SEHH2274 Organic Chemistry Notes 1 Structure and Bonding.pdf
PPTX
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
PPTX
TOTAL hIP ARTHROPLASTY Presentation.pptx
PDF
. Radiology Case Scenariosssssssssssssss
PPTX
7. General Toxicologyfor clinical phrmacy.pptx
PDF
MIRIDeepImagingSurvey(MIDIS)oftheHubbleUltraDeepField
PPTX
Derivatives of integument scales, beaks, horns,.pptx
PPTX
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
PPTX
EPIDURAL ANESTHESIA ANATOMY AND PHYSIOLOGY.pptx
PDF
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
PDF
diccionario toefl examen de ingles para principiante
PDF
Phytochemical Investigation of Miliusa longipes.pdf
Vitamins & Minerals: Complete Guide to Functions, Food Sources, Deficiency Si...
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
Microbiology with diagram medical studies .pptx
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
SCIENCE10 Q1 5 WK8 Evidence Supporting Plate Movement.pptx
Biophysics 2.pdffffffffffffffffffffffffff
AlphaEarth Foundations and the Satellite Embedding dataset
SEHH2274 Organic Chemistry Notes 1 Structure and Bonding.pdf
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
TOTAL hIP ARTHROPLASTY Presentation.pptx
. Radiology Case Scenariosssssssssssssss
7. General Toxicologyfor clinical phrmacy.pptx
MIRIDeepImagingSurvey(MIDIS)oftheHubbleUltraDeepField
Derivatives of integument scales, beaks, horns,.pptx
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
EPIDURAL ANESTHESIA ANATOMY AND PHYSIOLOGY.pptx
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
diccionario toefl examen de ingles para principiante
Phytochemical Investigation of Miliusa longipes.pdf
Ad

Lecture 1 - Overview of Go Language 1.pdf

  • 1. Overview of Go Language
  • 2. GoLang • Critics: There is nothing new in Go • GoLang Designers: The task of programming language designer "is consolidation not innovation" • Less is exponentially more – Rob Pike, Go Designer • Do Less, Enable More – Russ Cox, Go Tech Lead
  • 3. Why new programming language • Computers are faster but not software development • Dependency management is critical • Dynamically typed languages such as Python and JS • Garbage collection and parallel are not well supported by popular system languages • Multicore computers
  • 4. GoLang • Go Fast • Go Simple • Natively complied (similar to C/C++) • Static typing • Fully garbage collection supported • Support for concurrency and networking • Rich standard library • System & Server-side programming • Scalable • Open source. Inspired by: C, Pascal, CSP
  • 5. Who • Robert Griesemer, Ken Thompson, and Rob Pike started the project in late 2007 • By mid 2008 the language was mostly designed and the implementation (compiler, runtime) starting to work • Ian Lance Taylor and Russ Cox joined in 2008 • Lots of help from many others • Officially announced in November 2009 • March 2012: Go 1.0
  • 6. Go Users • Google services: YouTube, Kubernetes • Docker • Dropbox • eBay • Facebook • Lyft • Uber • PayPal
  • 7. Go Usages • Large scale distributed systems • Cloud: GCP, Cloud Foundry, Heroku… • Web development • Scripting • System programming • Open-source project
  • 9. Install Go • The Go Playground: https://go.dev/play/ • Install Go: https://go.dev/dl/ • Visual Studio Code + extension • Go packages doc: https://pkg.go.dev/
  • 10. First Go Program • Every Go file starts with package • import: packages use • func main: entry of a Go program • Can use semicolons to separate statements (optional) • go run file.go package main import "fmt" //comments func main() { fmt.Println("Hello world!") }
  • 11. fmt Package • Print • Println • Printf • Scan • Scanln • Scanf
  • 12. fmt Package package main import "fmt" func main() { var name string fmt.Print("Enter your name: ") fmt.Scanln(&name) fmt.Printf("Hello, %s! n", name) }
  • 13. Variables • Go is statically typed similar to C, C++, Pascal • Implicit type declare var name = " Hello " //name is string type • Explicit declare var name string = " Hello " • Multiple declare var x, y int var ( name string z int ) • Multiple init var x, y int = 1, 2 var ( name = " Hello " z = 10 ) SIMILAR TO PASCAL
  • 14. Variables • Shorthand syntax • Explicit declare name string := " Hello " //no need var, := instead = • Implicit declare name := " Hello " //type is string • Keyword const, cannot change value const SIZE int = 10
  • 15. Naming convention • Camel case • twoWordString • iAmAPerson • Global scope • File scope • Export global scope: starts with Uppercase package main import "fmt" //comments var numberOne int = 10 var NumberTwo int = 20 func main() { fmt.Println("Hello world!") }
  • 16. Primitive Data Types • Boolean • bool: true / false • Numeric • Integer: signed, unsigned (8 → 64 bit) • Signed: int8, int16, int32, int64 • Unsigned: uint8, uint16, uint32, uint64 • Float: • float32, float64 • Complex: complex64 (32 real, 32 imagine), complex128 (64 + 64) • Text • String: sequence of bytes, size varies • Byte: UTF8 • Rune: UTF32
  • 17. Primitive Data Types package main import "fmt" //comments func main() { var a complex64 = 2 + 3i fmt.Println(a) fmt.Println(real(a), imag(a)) a = complex(3, 5) fmt.Println(a) }
  • 18. Type conversion • Downsize or upsize package main import "fmt" //comments func main() { var i int = 1 var j float32 = float32(i) j = 5.5 i = int(j) i = 65 var s string = string(i) }
  • 19. String conversion • strconv package package main import "fmt" import "strconv" func main() { i := 65 var s string = strconv.Itoa(i) }
  • 20. Operators • Mathematic: +, -, *, /, % • Logical: &&, ||, ! • Relational: ==, !=, >, <, >=, <= • Bitwise: • & (and) • | (or) • ^ (xor, not) • &^ (and not), 1 if both are 0s • << (left shift) • >> (right shift)
  • 21. Enum • List of constants package main import "fmt" const ( zero = 0 one = 1 two = "two" ) func main() { }
  • 22. Enum • Using iota (default 0) package main import "fmt" const ( zero = iota one two ) func main() { }
  • 23. Array • Fixed size • Index starts at 0 • Declaration var arr [3]int • Initialization nameList := [3]string {"A", "B", "C"} • Implicit length var arr […]int = {1, 2, 3} • Multi dimensional array var arr2D [2][3]int
  • 24. Array • Length of array: len(arr) • Iterating through the array for i,value := range arr { fmt.Println(i, value) } • Assign array will copy
  • 25. Slice • Think of slice as dynamic array (but actually NOT) var slc []int = {1, 2, 3} //does not contain … • Using make slc := make([]int, 3) //len is 3 slc1 := make([]int, 0, 5) //len is 0, cap is 5 • Append slc = append(slc, 4) • Assign slice will make reference. Use copy to duplicate dup := make([]int, len(slc)) copy(dup, slc) • Length: len(slc)
  • 26. Slice Operator • Slice support operator with the syntax sliceName[low:high] fmt.Println(slc[0:2]) fmt.Println(slc[0:3]) fmt.Println(slc[1:])
  • 27. Map • Similar to dictionary: map[key-type]value-type student := map[int]string { 1: "A", 2: "B", 3: "C",} • Using make student := make(map[int]string) • Length: len(student) • Add new element: map[newKey] = value • Delete: delete(map, key) • Check existed val, isExisted := student[5] //val is empty string • Slice cannot be key. Array is possible • Assign will make reference
  • 28. Struct • Top level type student struct { id int name string grade float32 } • Inline studentA := struct { id int name string}{id:123, name:"abc"} • Access member using dot operator “.” • Assign will make copy (same as array)
  • 29. Struct • Literals student1 := student { id: 123, name: "abc", grade: 5.5, } • Struct name and member must be capitalized to be exported
  • 30. Struct • Embedded type Person struct { name string age int } type Student struct { Person //embedded by value grade float32 } • Access: student1.Person.name, student1.name • Tag type Student struct { Person grade float32 `grade must be 0 to 100` }