Notes and code sampesl for the first meeting of the Squaremouth book club. Covering Chapters 1 - 5 of the go lang book.
Nothing of note in this chapter.
Finally get to a "Hello World". Briefly explains packages ("main"), importing, and main. Some of the simplest types are broken down.
Starts of by explaining types in terms of philosophers and mathematics (man after my own heart).
uint8
,uint16
,uint32
,uint64
,int8
,int16
,int32
,int64
- Alias types:
byte
==uint8
andrune
==int32
- Machine specific:
uint
,int
,uintpr
float32
andfloat64
(increase in precision with bits).NaN
โ
- (OPTION + 5)complex64
andcomplex128
- Can be created with "" - Single line strings that allow escape characters
- Can be created with `` - Multi-line strings but no escape characters
len("String")
- String length"Sample"[0]
- String indexing, does not return what you'd expect
true
,false
- literals&&
,||
,!
- operations
Now we start looking at how we can declare variables in go. There are a few different ways to do the same thing.
var x int = 8
- declaring and assigning in one linevar x int
- only declaring followed byx = 18
later onx := 8
- assigning and inferring the typeconst stuff string
- Declaring a constant variable, can't be re-assigned
Can almost write a useful program now.
All loops are written in terms of for
for stuff == true { ... }
- While loop equivalentfor i := 1; i <= 5; i += 2 { ... }
- Traditional for-loop- Yet to be seen for-each style loop
Standard conditionals using real english words.
if
,else if
,else
- Main conditional statementsswitch
statement also exists
-
Capital lettered function/method names. ex)
fmt.Println("Hello World")
-
The
go
tool and thegodoc
command. Rungo help
to see what it can do. -
Go has a metric ton of types. Is this worth it?
-
You can use UTF-8 characters, think about that. Show gomega.
-
Go will not allow you to declare variables that aren't used (_ values)