-
Notifications
You must be signed in to change notification settings - Fork 0
/
govspython.slide
213 lines (135 loc) · 5.25 KB
/
govspython.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
#+theme=black
Go vs. Python
Dmytro Grendach
Nokia
[[https://github.com/grendach/GOvsPython]]
* Agenda
.image images/golang_vs_python.jpg 130 800
1. Who is Who
2. Hello World
3. Differences in:
- lists
- dictionaries
- loops
- error handling
- other differences
4. And the winner is...
* Who is who: Python
- Created by *Guido* *van* *Rossum* in 1991.
- Python is dynamicly typed, interpreter language.
- Use whitespace for indentation.
- Has 33 keywords (`class`, `def`, `for`, `if`, `while`, etc.)
The Zen of Python
- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Flat is better than nested.
.image images/python.png 100 100
* Who is who: Go
- Created by Rob Pike , Robert Griesemer and Ken Thompson in 2009.
- Go is a statically typed, compiled language.
- Built in `fmt` package makes code formate for you.
- Go has 25 kyewords (`go`, `goto`, `chan`, `func`, `for`, `if`, etc. )
The designers wanted to resolve common criticisms of other languages, while retaining many of their useful characteristics:
- Statically typed and efficient (like C++ or Java)
- Productive and easy to use (like Python or JavaScript)
- Go has pointers but unlice C, Go has no pointer arithmetic.
- Enabling high-performance networking and multiprocessing.
.image images/strongGopher.jpg 100 100
* Python vs Go
.image images/begin.gif 350 500
Let the battle begin...
* Hello world in Python
.code -numbers code/hello.py
* Hello world in Go
.play -numbers code/hello.go
* Differences in
- Lists(slices)
- Dictionaries(maps)
- Loops.
- Error handling.
- Pointers.
- Coroutine vs Goroutine and channell.
- Inheritance.
* List in Python
Python has next data types:
- *List* [ ] - ordered and changeable collection.
- *Tuple* ( )- ordered and unchangeable.
- *Set* { } - unordered and unindexed.
- *Dictionary* { } - unordered, changeable and indexed.
.code -numbers code/lists.py
* Slices (lists) in Go
Slices are like references to arrays.
A slice does not store any data, it just describes a section of an underlying array.
Slices can be created with the built-in `make` function.
This is how you create dynamically-sized arrays.
.play -numbers code/lists.go
* Dictionary in Python
.code -numbers code/dict.py
* Dictionary in Go it's Map!
.play -numbers code/dict.go
* Loop in Python
Python has two primitive loop commands:
*while* loops
*for* loops
.code -numbers code/loop.py
* Loop in Go
Go has only one looping construct, the *for* loop.
.play -numbers code/loop.go
* Error handling in Python:
Error handling in Python is done through the use of exceptions.
.code -numbers code/error.py
* Error handling in Go
Go doesn’t have exceptions.
Errors are represented using the built-in `error` type, same as `int`, `string`.
Each time you need to check for error manually.
.play -numbers code/error.go
* Pointers in Python
*Python* *doesn't* *use* *pointers!*
Variables cannot point to other variables.
Variables always point to the underlying object instead.
.code -numbers code/pointers.py
* Pointers in Go
Go use *pointers* but doesn't use *pointer* math.
*Pointer* holds the memory address of a value and represented using the `*` (asterisk).
Operator `&` used to find the address of a variable.
.play -numbers code/pointers.go
* Coroutine in Python
*Coroutines* declared with `async`/`await` syntax.
Is the preferred way of writing asyncio applications.
The following snippet of code (requires Python 3.7+) prints “hello”,
waits 1 second, and then prints “world”
.code -numbers code/routine.py
* Goroutine and channell
*Channels* are the pipes that connect concurrent *goroutines*.
You can send values into channels from one *goroutine* and receive those values into another *goroutine*.
.play -numbers code/routine.go
* Inheritance in Python
For *inheritance* Python use *base* (parent) and *sub* (child) classes.
*Base* class create a pattern out of which *sub*, child can be based on.
.code -numbers code/inheritance.py
* Inheritance in Go
Go is unique from a lot of object-oriented languages in that it doesn’t have classes.
Instead, Go has two awesome features: *interface* and *struct*.
*Interfaces*:
- You don’t explicitly say a data type implements an interface.
- Your data types must implement all of the methods that the interface defines.
- Compiler checks to see if assignments to variables of the interface type are valid.
*Struct*:
- It's a sequence of named elements, called fields, each of which has a name and a type.
- Field names may be specified explicitly (IdentifierList) or implicitly (EmbeddedField)
- Within a struct, non-blank field names must be unique.
* Inheritance in Go
.code -numbers code/inheritance.go
* Python vs Go
.image images/finish.gif 350 500
And the winner is...
* And the winner is...
Go is a very performant language with great support for concurrency.
It is almost as fast as languages like C++ and Java.
While it does take a bit more time to build things using Go compared to Python you’ll save a ton of time spent on optimizing the code.
*Python* *usage*: it's almost everywhere :)
*Golang* *usage*: Docker, K8s, Prometheus are written in Go.
Google and Soundcloud using it!
.image images/codeGopher.gif 100 100