-
Notifications
You must be signed in to change notification settings - Fork 128
/
lesson1.slide
179 lines (135 loc) · 4.31 KB
/
lesson1.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Introduction, Syntax, Formatting, Packages, Types
Lesson 1
30 May 2024
Tags: golang, go
Stanislav Kozina <[email protected]>
Jakub Čajka <[email protected]>
Red Hat, Inc.
https://github.com/RedHatOfficial/GoCourse
* Sources
- [[https://github.com/RedHatOfficial/GoCourse]]
.image ./common/qr_address.png
* Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/fiveyears.jpg
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/fiveyears.jpg _ 900
* Introduction
- Launched in November 2009 by Google
- Rob Pike, Ken Thompson, Robert Griesemer
- More readable replacement for C/C++/Java/...
- statically typed, compiled, garbage collected
- built-in concurrency
- server-side web (PHP, Node.js, Python)
- cloud technologies (docker, kubernetes)
* Resources
- Tour of Go [[https://tour.golang.org/welcome/1]]
- Effective Go [[https://golang.org/doc/effective_go.html]]
- Go Doc [[https://godoc.org/]]
- Go cheatsheet [[http://www.cheat-sheets.org/saved-copy/go-lang-cheat-sheet-master.20181212/golang_refcard.pdf]]
- The Zen of Go [[https://the-zen-of-go.netlify.app/]]
* Development interface
- Vim;-)
- Visual Studio Code + go lang support [[https://code.visualstudio.com/docs/setup/linux]]
- GoLand from JetBrains
* Go keywords
break case chan const continue
default defer else fallthrough for
func go goto if import
interface map package range return
select struct switch type var
* Packages and Imports
- Program building blocks ("libraries")
- Imported by other programs
- Package name is the last element of the import path
- Standard packages: [[https://golang.org/pkg/]]
.code lesson1/packages.go
* Hello world
.play lesson1/hello.go
.code lesson1/run_hello.go
.code lesson1/build_hello.go
* Unicode support
.play lesson1/hello_u.go
* Packages
- special package main: main() for executables
- Workspace defined by $GOPATH
- Structure for libraries, binaries: src, bin
* go-fmt
.play lesson1/gofmt1.go
.code lesson1/gofmt.go
.play lesson1/gofmt2.go
* Syntax
- Evolved from C
- Declarations in postfix
- Exported symbols begin with Capital letter
- [[https://blog.golang.org/gos-declaration-syntax]]
.code lesson1/syntax_c.go
.code lesson1/syntax_go.go
* Functions
.play lesson1/functions.go
* Multiple return values
.play lesson1/functions2.go
* Multiple return values
.play lesson1/functions2B.go
* Named return values
.play lesson1/functions3.go
* Variables
.play lesson1/vars.go
* Types
- Similar to C
- No auto casts
- Type inference && default types
- Each type has clear zero value (0, false, "")
.code lesson1/types.go
* Outside basic types
- math.big/Int
- math.big/Rat
- math.big/Float
* Type conversions
- No auto casts
.play lesson1/casts.go
* Constants
.play lesson1/const.go
* Loops
- Just for loop which also serves as while loop
.play lesson1/for.go
* Loops
- break keyword
- continue keyword
* Conditions
- Similarly to for loop allows init statement
- Variables declared there don't exist outside of the if block
.play lesson1/if.go
* Else statement
- Variables declared in the init statement do exist in the else block
.play lesson1/if2.go
* Switch statement
- Again allows init statement
- Like set of if-else statements
- Evaluated top-bottom, first successful case is executed
- Thus there's no break statement
.play lesson1/switch.go
* Switch statement 2
- Allows non-constant and non-integer values
.play lesson1/switch2.go
* Switch with no condition
- switch without condition is like switch true
.play lesson1/switch3.go
* Error handling
- error is built-in type
[[https://blog.golang.org/error-handling-and-go]]
.play lesson1/ret.go
* Ignoring return values
- '_' idiom can be used to drop return values
.play lesson1/ret2.go
* Useful links
The Why of Go (put many Go-related things into context)
[[https://www.youtube.com/watch?v=bmZNaUcwBt4&list=WL]]
GothamGo 2018 - Things in Go I Never Use by Mat Ryer
[[https://www.youtube.com/watch?v=5DVV36uqQ4E]]
#last slide
* More Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/bumper.png
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/bumper.png _ 900