This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
03-types.slide
112 lines (65 loc) · 1.67 KB
/
03-types.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Go Types
Brett McKay
* Declaring variables
How to declare a variable:
.play -edit 03-types/declaration.go /BEGIN OMIT/,/END OMIT/
What happens if you don't use a declared variable?
* Go Strings
- Are immutable
- Generally created using double quotes
- Raw strings are created with back ticks
.play -edit 03-types/string.go /BEGIN OMIT/,/END OMIT/
* Go Bools
*Values*
.play -edit 03-types/bool.go /BEGIN OMIT/,/END OMIT/
What will happen?
.play -edit 03-types/conflict.go /BEGIN OMIT/,/END OMIT/
* Type Systems
- Strong
- Weak
What is the difference between the two?
* Weak Typing
- Types are determined at run time
- Best match is used
- Cause problems when no match is possible
"1" + 1 = "11"
"!" - 1 = problem
* Strong Typing
- Types are determined at compile
- Types must match exactly
- Compiler errors occur when types don't match
"1" + 1 = error
Is Go strongly or weakly typed?
* Go Integers
*Signed*
- int8
- int16
- int32
- int64
*Unsigned*
- uint8
- uint16
- uint32
- uint64
* Continued
What will happen?
.play -edit 03-types/conflict-integer.go /BEGIN OMIT/,/END OMIT/
* Increment Example
What is the maximum number for int8?
What happens if you add 1?
* Continued
.play -edit 03-types/increment.go /BEGIN OMIT/,/END OMIT/
* Overflow assingment
What happens if you assign 128 to int8?
.play -edit 03-types/overflow.go /BEGIN OMIT/,/END OMIT/
* Implementation specific
- int either 32 bits or 64 bits
- uint same size as int
The size depends on the implementation of your system
* Go Floats
- float32
- float64
They exist and work how you would now expect
* Assignment
- What is the default value for each type?
- What happens if you divide a float by 0?