-
Notifications
You must be signed in to change notification settings - Fork 127
/
go_worth_learning.slide
352 lines (226 loc) · 7.95 KB
/
go_worth_learning.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
Is Go language actually worth learning?
Red Hat
19 Sep 2023
Tags: golang, go
Pavel Tišnovský <ptisnovs@redhat.com>
Red Hat, Inc.
* Introduction
There are lots of interesting programming languages that you can learn.
The question is, should you perfect them all? The answer is no, of course.
So what about the Go language - is it worth try?
In this presentation we are going to talk about Go's pros (goroutines,
channels, GC, type systems) and cons (a language with attributes taken from the
previous century :)
* 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/...
- Better suits corporations needs
- „Less is more“
* Introduction
- (statically) compiled
- statically typed
- allows cross-compilation
- garbage collected
- built-in concurrency
- strict formatting rules
- type inference
* Usage
- server-side web (PHP, Node.js, Python, Ruby, Java)
- client-side web (compilation to WebAssembly)
- cloud technologies (Docker, Podman, Kubernetes, Kubernetes Operators, MinIO, ...)
- available for all interesting systems
- and most architectures (x86-64, ARMv6, ARMv8, even s390x and PowerPC64 LE)
- custom back end + cgo
* More readable compared to C/C++
- Evolved from C
- Declarations in postfix
- Much faster for parser to parse sources
- Exported symbols begin with Capital letter
- [[https://blog.golang.org/gos-declaration-syntax]]
.code src/syntax_c.go
.code src/syntax_go.go
* More readable compared to C++
- In C++ we don't say "Missing asterisk"
- we say:
"error C2664:
'void std::vector<block,std::alocator<_Ty> >::push_back(const block &)':
cannot convert argument 1 from
'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<block> > >'
to 'block &&'"
- and i think that's beautiful
- not mine, source:
.link https://goo.gl/Akxjih
* More readable compared to C++
#include <vector>
#include <algorithm>
int main()
{
int a;
std::vector< std::vector <int> > v;
std::vector< std::vector <int> >::const_iterator it = std::find( v.begin(), v.end(), a );
}
- gcc -c error.cpp will produce 15786 bytes of output, with a longest line of 330 characters
* Cloud technologies
.link https://www.docker.com/ Docker
.link https://podman.io/ Podman
.link https://kubernetes.io/ Kubernetes
.link https://coreos.com/operators/ Kubernetes Operators
.link https://min.io/ MinIO
.link https://nsq.io/ NSQ
.link https://nats.io/ NATS
.link https://www.redhat.com/en/technologies/cloud-computing/openshift OpenShift
.link https://geth.ethereum.org/ Go Ethereum
* Goals
- simplicity
- unambiguity
- performance
- pragmatic
- safer applications (compared to C/C++)
- microservices
- ease to install ("DLL hell" can't happen)
- for DevOps from DevOps
- fast (actually super fast) builds (CI tools like it ;-)
* Attention
- Go is a blend of modern approaches combined with quite old ideas
- explicit error handling
- no generics till version 1.18
- no class-based OOP
- no `try`/`catch`/`finally`
- no ternary operator
- `goto` keyword
- `nil` identifier
* Interfaces are automatically implemented
- "satisfied" in Go lingo
.image ./images/interface.svg _ 500
* Go vs C(++)
- stronger type system
- no text substitution macros
- no header files
- package system + checks
- safer memory operations + GC
- standardized framework for tests
- stricter rules (`++`/`--`, pointers, ...)
- no exception handling control structures (yet?)
- no generic data types till Go 1.18
* But... we are in 21th century!
.image ./images/ural.jpg _ 700
* But... we are in 21th century!
- Multi-core CPUs
- Distributed systems
- Memory locality
- Readability
* Multi-core CPUs
.image ./images/perf.jpg _ 700
* Multi-core CPUs
.image ./images/Amdahl.png
* Bit of history
- 60's: insufficient program flow control
- "GOTO considered harmful"
- solved by introducing structured programming
- -> new syntax
* Bit of history
- 70's: insufficient state control
- solved by introducing OOP
- -> new syntax
* Bit of history
- 2000: insufficient concurrency control
- not solved for a long time
- Go's goroutines + channels
- Python's + JavaScript's async
- -> new syntax
* Support for concurrency
- Communicating sequential processes (a formal language etc. etc.)
- "Don't communicate by sharing memory; share memory by communicating"
- So called _goroutines_
- Channels
* Concurrency and/or parallelism
- Serial: runs tasks in an order with one CPU core
- Concurrent: runs many tasks simultaneously with a less number of CPU cores (or even 1)
- Parallel: runs n tasks simultaneously with n CPU cores
* Concurrency
- when multiple tasks can run in overlapping periods
- needs only one CPU core
- main problem: interruptions
* Parallelism
- needs more than one CPU core
- main problem: isolation
- second problem: coordination
* Solutions for concurrency and parallelism
- processes
- threads
- coroutines
* Solutions for concurrency and parallelism
- processes
- threads
- **goroutines*
- coroutines
* Goroutines + channels is a way to ... Go
- Deadlocks are not such a big problem then
.image ./images/deadlock.gif _ 700
* Memory locality
- True structures
- True value types
- No object headers
- Java: no value types, no structures, object headers
* Memory locality
- RAM is no longer "Random Access Memory"
* Memory locality
.image ./images/computer_latency_1.jpg _ 300
* Memory locality and access times
- We humans are bad comparing very small time periods
- Dtto for other units (length, money etc.)
* Memory locality and access times
.image ./images/computer_latency_2.png _ 500
* Go and KISS principle
* Dynamic devel teams
.image ./images/teams.png _ 500
* Dynamic devel teams
- stability
- on source code level: if it compiles in version X, it will compile in version X+1 too
- OTOH: https://pythonclock.org/
- readability
* go-fmt
- Gofmt’s style is no one’s favorite, yet gofmt is everyone’s favorite. — Rob Pike
- standard tool
* Wanna be mainstream?
- [[http://pypl.github.io/PYPL.html]]
- [[https://hackernoon.com/10-best-programming-languages-to-learn-in-2019-e5b05af4a972]]
- [[https://insights.dice.com/2018/12/17/5-programming-languages-consider-learning-2019/]]
- [[https://www.rankred.com/new-programming-languages-to-learn/]]
* Popularity
- [[https://insights.stackoverflow.com/survey/2020#technology-most-loved-dreaded-and-wanted-languages-loved]]
- [[https://insights.stackoverflow.com/survey/2020#technology-most-loved-dreaded-and-wanted-languages-dreaded]]
- [[https://insights.stackoverflow.com/survey/2020#technology-most-loved-dreaded-and-wanted-languages-wanted]]
* Popularity chart
.image ./images/popularity.png _ 600
* So...is it worth to spend time learning Go?
- networking - YES
- (micro)services - YES
- scalable systems - YES
- you like strict formatting rules - YES
- you like strong type systems - YES
- you like minimalism - YES
- pretty fast compilation - YES
- the simplest deployment - YES
- guaranteed source code compatibility - YES
* So...is it worth to spend time learning Go?
- you like classic (broken) class-bases OOP - NO
- you like baroque languages - NO, enjoy C++
- you like inconsistent languages - NO, enjoy Perl
- you like homoiconic languages - NO, LISP/Scheme/Clojure are better then
- you want to manage memory ourself - NO
- you like to have buffer overflows - NO, there are "better" choices
- you like really very strong type system & fast language - Rust
#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 ./images/bumper.png _ 900
# finito