2. 1 – Go Overview – What is Go?
Compiled
Garbage-collected
Concurrent
3. Compiled
Code adapted to machine that they’re running on
Compiled down to machine languages like C, C++
More efficient and better performance than interpreted languages
Supported operating systems: Linux, Mac OS
X, FreeBSD, OpenBSD, Plan 9, Windows
Supported processors: i386, amd64, ARM
4. Garbage-collected
You do not have to manage memory as programmer, unlike C, C++
Runtime handles for you
Garbage collection is very fast, latency free
5. Concurrent
Concurrency is to do more than one thing at a time
Programming languages like C++ and Java, concurrency is possible but hard to
manage. It is not part of language
Go has built in concurrency support
It is called Go Routines for concurrent functions
6. Go’s Origins
Three Google engineers want a system level languages for aging systems level
languages
Go was designed very fast compiling language
Sept 2007
Dream of Go
March 2012
Go 1
released
May 2010
Used
internally at
Google
Nov 2009
Officially
announced
7. What makes Go different?
Efficient like a static language, ease of use like dynamic language
Type-safe and memory-safe
Latency free garbage collection
Fast compile times
It does not have assertions and method overloading
8. 2 – Go Development - Packages
Way to modularize code
Similar to namespaces
Collection of types and functions
Can import packages in your code
Redistribute those packages
A lot of built-in packages, https://golang.org/pkg/
10. Imports
Go knows whether your code needs those packages
Has ability to go out and get remote packages
Your code could refer to github etc. repositories
11. Hello World
package main Required package name "main"
import "fmt" Package comes with Go
func main(){ Curly braces is near by function name
fmt.Println("Hello World")
}
Println start with upper case, cause it is exported method
12. Hello World
Direct run, not generate .exe file
go run hello.go
To Build to generate .exe file
go build hello.go
To run after build
hello.exe
19. Pointer Basics
Pointer is a type of variable that is going to contain a memory address of another
variable
string pointer has same type with string type
Hello
World
0xc042
00a270
20. Pointer Basics, Passing Things
Pointer’s type is that type is going to refer to what type of variable
We pass value in Go function, this value will be copied, inside function, we change
this value, originial value is not changed
function
43
43
function
43
45
21. Passing Things
If we pass a pointer to function, pointer also will be copied but it points same
memory location. So if we change value inside function, originial value will also be
changed
function
43
0x0123
0x0123
22. Basic Pointer Example
greeting is a pointer, if we write it directly, it shows memory address
If we write *greeting, it shows Hello world