Go for Python Programmers
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Part Number | 31 | |
Number of Parts | 169 | |
Author | ||
License | CC Attribution - NonCommercial - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/21223 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
EuroPython 201631 / 169
1
5
6
7
10
11
12
13
18
20
24
26
29
30
31
32
33
36
39
41
44
48
51
52
53
59
60
62
68
69
71
79
82
83
84
85
90
91
98
99
101
102
106
110
113
114
115
118
122
123
124
125
132
133
135
136
137
140
143
144
145
147
148
149
151
153
154
155
156
158
162
163
166
167
169
00:00
DemonSoftware developerSoftware engineeringProgrammer (hardware)Right angleShared memoryConstructor (object-oriented programming)Lecture/Conference
00:28
CodeFormal languageResultantMultiplication signAdaptive behaviorRight angleWritingBitJSON
01:17
Data structureFormal languageCodeWritingSemantics (computer science)Multiplication signLecture/Conference
01:49
Semantics (computer science)Data structureExpected valueSemantics (computer science)Point (geometry)Data compressionPairwise comparisonVideo gameCoroutineGodLevel (video gaming)JSONLecture/Conference
02:42
Formal languageComputer programmingMultiplication signEndliche ModelltheorieSet (mathematics)Programming language
03:14
Formal languageConcurrency (computer science)Graph (mathematics)Key (cryptography)Declarative programmingLecture/Conference
03:55
Declarative programmingRight angleDirectory serviceDivisorWeb 2.0Line (geometry)Computer fileBitJSON
04:33
Computer fileDeclarative programmingSingle-precision floating-point formatDirectory serviceStandard deviationLecture/ConferenceJSON
05:04
Function (mathematics)Statement (computer science)Electronic mailing listDeclarative programmingFunctional (mathematics)Formal languageString (computer science)Marginal distributionLecture/ConferenceJSON
05:55
Category of beingType theoryMereologyCASE <Informatik>CompilerString (computer science)Cross-correlationMultilaterationSpeech synthesisInstance (computer science)Metropolitan area networkType theoryPairwise comparisonData structureInterface (computing)Electronic mailing listInterior (topology)Normal (geometry)BitLecture/ConferenceComputer animation
06:52
Interior (topology)Type theoryString (computer science)BitData typeRight anglePhysical systemDifferent (Kate Ryan album)Type theoryEvent horizonElement (mathematics)Electronic mailing listMultiplication signFood energySequenceCategory of beingComplex (psychology)LengthString (computer science)Array data structureInterior (topology)DampingCompilation albumLecture/Conference
08:35
Type theoryField (computer science)System callData structureSinc functionSocial classLecture/Conference
09:05
Type theoryType theoryElectronic mailing listProgram slicingMappingHash functionSurfaceQuantum statePoint (geometry)Power (physics)QuicksortEquivalence relationMereologyArray data structureLecture/Conference
09:45
Interface (computing)Process (computing)Type theoryMultiplication signGroup actionPairwise comparisonPointer (computer programming)Lecture/Conference
10:14
Type theoryInterface (computing)Universe (mathematics)Interface (computing)Declarative programmingJSON
10:40
Standard deviationType theoryNumberoutputCountingKey (cryptography)Multiplication signLevel (video gaming)RandomizationPoint (geometry)String (computer science)Interior (topology)Lecture/ConferenceJSON
11:56
Type theoryResultantSimilarity (geometry)Multiplication signDefault (computer science)Functional (mathematics)Interior (topology)Lecture/Conference
12:34
Function (mathematics)HypothesisIntegerElectronic mailing listString (computer science)DampingEvent horizonResultantFunctional (mathematics)TupleAuthorizationParameter (computer programming)JSON
13:14
Function (mathematics)Instance (computer science)Functional (mathematics)MathematicsRecursionCASE <Informatik>ResultantSystem callLecture/ConferenceJSON
13:47
Function (mathematics)Mathematical optimizationLocal ringFunctional (mathematics)Context awarenessMultiplication signLoop (music)Function (mathematics)SequenceInterior (topology)Type theoryoutputVariable (mathematics)Social classElectronic signatureString (computer science)Student's t-testLecture/ConferenceJSON
14:34
BitException handlingFunctional (mathematics)TupleError messageDifferent (Kate Ryan album)MultiplicationModal logicLecture/Conference
15:16
Error messageException handlingError messageLogicFunctional (mathematics)Insertion loss
15:53
Error messageComputer fileWord1 (number)Formal languageLatent heatLecture/Conference
16:24
Error messageBasis <Mathematik>Functional (mathematics)Computer fileMultilaterationBitLecture/Conference
17:01
Error messageFunctional (mathematics)Point (geometry)PressureComputer programmingUniverse (mathematics)Multiplication signDemosceneBitCASE <Informatik>Message passingWeb 2.0CodePointer (computer programming)Bound stateMechanism designCrash (computing)Server (computing)JSON
18:04
Process (computing)Server (computing)Web 2.0Complex (psychology)Client (computing)Connected spaceSoftware bugParsingOpen setError messageLecture/Conference
18:32
Error messageFunctional (mathematics)CASE <Informatik>Data recoveryComputer programmingGame controllerJSON
19:09
Object-oriented programmingMultiplication signPointer (computer programming)Lecture/Conference
19:34
Functional (mathematics)Type theoryBitObject (grammar)Inheritance (object-oriented programming)Position operatorJSONLecture/Conference
20:09
Point (geometry)BitField (computer science)DistanceSpacetimeType theoryFormal languageDampingFunctional (mathematics)Line (geometry)Data structureMultiplication signSocial class
21:17
Instance (computer science)Point (geometry)Social classBitVariable (mathematics)Line (geometry)Einbettung <Mathematik>DistanceReading (process)Inheritance (object-oriented programming)Formal languageDifferent (Kate Ryan album)Type theoryLecture/Conference
22:16
StrutEinbettung <Mathematik>Point (geometry)MereologyFunctional (mathematics)Inheritance (object-oriented programming)Embedded systemArithmetic meanJSON
22:48
Interface (computing)Einbettung <Mathematik>Interface (computing)Inheritance (object-oriented programming)Data structureReading (process)Expert systemWaveLecture/ConferenceJSON
24:05
Concurrency (computer science)Similarity (geometry)Interface (computing)Lecture/Conference
24:38
Concurrency (computer science)Process (computing)Formal languageProteinSemiconductor memoryConcurrency (computer science)
25:14
CoroutineSystem callMultiplication signProteinSemiconductor memoryShared memoryThread (computing)CoroutineTelecommunicationFunctional (mathematics)Letterpress printingType theoryRight angleOperator (mathematics)AuthorizationExecution unitComputer programmingBitFlow separationLecture/ConferenceJSON
27:02
Software testingSoftware testingLocal ringMultiplication sign2 (number)Radical (chemistry)BitType theoryTerm (mathematics)Functional (mathematics)QuicksortBenchmarkUnit testingCodeComputer fileLecture/ConferenceComputer animation
27:59
File formatCodeCodeFile formatBus (computing)Control flowMultiplication signLine (geometry)PlanningEnvelope (mathematics)Source codePlug-in (computing)Computer fileLecture/ConferenceComputer animation
28:30
Data managementIntegrated development environmentLine (geometry)Data managementDifferent (Kate Ryan album)Projective planeRevision controlVirtualizationIntegrated development environmentRadical (chemistry)Visualization (computer graphics)Lecture/ConferenceComputer animation
29:24
Electric generatorStandard deviationComputer programmingMedical imagingLecture/Conference
29:54
Control flowMultiplication signPhysical systemWordAnalogyGroup actionProgrammer (hardware)Lecture/Conference
Transcript: English(auto-generated)
00:00
So, let's welcome Shariar with the talk Go for Python Developers. Thank you. Thank you. So, we'll talk about Go for Python programmers as a way of introduction. My name is Shariar. I'm a software engineer based in London. I work at OSPIR.
00:26
OSPIR is a pretty cool company that we can talk about after the talk if you're interested. Before I start, I think I owe everyone an apology. As I spent more and more time preparing this talk, I realized it's probably not a great idea.
00:44
And it's not a great idea because it implies that we should use Go as we would use Python, and that results in un-edumatic Go code. It's just not a good idea. And then I thought about it a bit more, and I was still convinced about the idea this morning.
01:05
But I've done it now. But my intention here is not to write Go code like you write Python or write Python like you write Go. I think it's just as a way to compare the two languages. More so, I think this is probably more appropriate as a Go conference.
01:24
Not sure why it brought it to PyCon, but you're a Python. But you know, I've spent the time now, and we might as well have a go at it. It's quite interesting regardless, as long as we know that the intention is not to write Go code like Python. Because why would you ever do that?
01:41
The talk structure is, we're going to quickly go over some history, very, very basic, brief history of the two languages. Then talk about general syntax and semantics comparison. And finally, one thing that I think is quite interesting, because Python's very strong at it, is talking about the ecosystems and tools available to developers.
02:03
To set the expectation, there's expected that you have some knowledge of Python at least, to be able to make the comparison. No particular knowledge of Go required, and the depth at which we discuss Go is not necessarily something intense. It's going to be very brief, very high level.
02:24
If anyone's here for a deep dive into, for example, comparing AsyncIO with Go routines, that's probably its own talk. It's not going to be here. But we can start with some history. So, Go, well let's start with Python. Python first appeared around 1991, and we know it was influenced a lot by ABC, which was by the name.
02:48
It was meant to be a very simple programming language to learn, etc. Python, a lot of Python's philosophy is from ABC. And a bunch of other stuff, Algos 68, Haskell, Modular 3, etc.
03:01
Go, on the other hand, is very young. 2009 was around the first time it appeared. But the languages that influenced it still go way back. So there's stuff like Algos 68 and Pascal, C, big influence. But there's also, one of the key things about Go we'll talk about later is the concurrency.
03:24
And that was influenced by CSV, which is not necessarily a language. I'll talk about that later, we don't have to worry about it now. But we'll see, Go's quite young, it's been quite popular, but Python, obviously huge history, it's been going on for a while. Well, huge. 1991.
03:41
To start for syntax and semantics, I think the most boring thing to do, which I've done, would be to just do a simple hello world. And go over the basics, and then try and dig a bit deeper. So we can see on your right, the hello world in Python, with the weird caveat that I have an extra weird variable declaration.
04:03
That's just to show the example for declaration assignment. And on the left is the Go one. The thing about Go is every Go file has to have a package name, for example. So the first line of every Go file is usually a package name. It should be a comment, but then after the first real line of any Go file would be a package.
04:25
And that is pretty explicit. And it's interesting, in Python, packages work a bit differently, you kind of know it from the directory, if the directory is a package in Python 2. But in Go, that is super explicit, you have to have the package declaration at the beginning of each file.
04:47
And every single Go file that you put in the same directory has the same package. Again, very explicit. If everything is directory foo, every file in that directory will have package foo at the top of it. So when you're working with it, you just go right to the top, you know exactly what package you're in.
05:02
I quite like being explicit, so does every other Python programmer, I guess. The next thing typically, like most Python files, are import statements. And it is very similar to Python. You import packages, there's no concept of, you know, packages and modules, so you don't say
05:22
from something, import something else, you generally import the whole package, and then you can use that. If you have multiple packages, you put them on separate lines, it doesn't matter how it works, because it's quite simple. You kind of use a parenthesis, and then you just say import once, and you just list everything in a string. It doesn't matter.
05:43
And then there are also functions, you know, like there would be in any language. We'll talk about this later. The weird thing that I put there, which is a kind of declaration and assignment that is not necessary, was just to go over how that would work. So for example, text in this case is a string. Now one thing I didn't
06:01
mention, so Go is statically typed, which is very different to Python, being dynamically typed. And in this case, we haven't really said text is a string, but the compiler can infer that. We'll talk a bit about that later. Speaking of declaration and types, we can do a quick comparison of types in Go and Python.
06:29
Generally speaking, there are kind of four types in Go, so we have the normal basic types, and we'll look at them a bit. We'll look at the list in a bit, which is you have the ints and floats and stuff.
06:42
You have the aggregate types, like a struct. Again, we'll look at it later. The reference types, like a map. And there is one thing that is an interface type that kind of doesn't exist in Python. And I say kind of because we'll see conceptually Python uses it, and we do have the ABC stuff, but they work a bit different to how it works in Go.
07:06
So we'll get to that shortly as well. But as far as the basic data types are concerned, Go gives you a bit more granular types, which is what you would expect because it's statically typed.
07:20
So you kind of want to be a bit wise with what you choose. So you have many different bits of ints and unsigned ints. In Python, they're all just longs. You have, again, different sized floats. In Python, they're just floats. We don't really need to care about how many bits there are in Python, although we can if we wanted to.
07:42
And then you have complex bool and string. I guess bool and string are pretty standard. Complex is useful, too. The int and uint are, you know, we're not specifying how many bits are in there. That's system dependent. It's usually 32 or 64 bits. But it depends on the system, where you're compiling. Nothing we need to worry about for the purpose of this talk.
08:06
The other category of talk types or aggregate types, one of them is an array, which an array, arrays are just fixed length sequences of zero or more elements of a particular type.
08:21
Now, they're not really lists in Python. They're really more Python arrays that you can also use. You know, because they have to be typed and will show there is a concept, there is something similar to lists in Python as well in Go. But they're not arrays. And struct is just, you know, the thing you use to contain certain fields inside it.
08:45
It could be similar to classes. It seems to name TOEFL, which is really a class, but whatever. But it isn't, you know, it's not apples to apples, but you typically use struct where you would probably use a class in Python.
09:01
Or a dict, or, you know, that kind of having fields and put, you know, to create a certain concept. Then we have the reference types. Slices are the things that are very similar to lists. Generally speaking, you wouldn't want to work with arrays in Go.
09:23
You have slices, and slice is a kind of part of an array, and then you can do all sorts of stuff, you can do a list with them. So they're pretty powerful. Maps are basically dicts. They're hash maps. Yeah, very similar. Nothing different there. There's also this reference type called channels in Go that I can't, there's no equivalent in Python really.
09:46
Channels, we'll talk about later, are the way, are used for concurrency, and for like two processes to talk to each other. And they're an actual type. We'll talk again later, channels are typed.
10:01
There's also a pointer type I'm not going to talk about because it doesn't really matter. Well, it matters in Go, but it doesn't matter for the purpose of discussing this comparison. Finally, and I said there's an interface type in Go. Interfaces used for generalization architectures, as you would expect for an interface.
10:25
There's this thing that I want to mention now, we'll talk about later, which is in Go interfaces are satisfied implicitly. And that is why I think they're very similar to how things work in Python. Again, we'll talk about that later. We can go back to declaration and usage, so there are really three ways you can declare and assign stuff in Go.
10:47
For example, the first one is you create a variable of type string, then you assign some text to it. Now, at the point where that variable is declared, so var text string, text is an empty string.
11:03
And one of the things in Go is that when you declare a variable, it automatically takes a zero value of its type. For example, ints would be zero, floats would be 0.0, reference types would be nil. And that is quite interesting because it's meant to be used and you can have some fun with it.
11:21
For example, if we wanted to take, I don't know why you'd do this, but if you want to take random input from a user from the standard input and count the number of times they typed something, we could create a map called counts, and that's a map that's going, you know, the key is a string and the value is an int, it will be our count.
11:42
You take the input, it doesn't matter how we do it with the new scanner. And then you go through every time someone types something, you read that. So what we can do is we can look at that text as the key into the map, but initially, because it doesn't exist, the default value, the zero value for int is returned because that's the value of the map,
12:02
and then you can just do a plus plus on that and you're good to go. Doing something similar in Python, we'll probably use a counter, but if not, this particular behavior results in something similar to default dict. But again, every other type has zero values too, so ints have zero values, floats have zero values, everything has zero values.
12:25
Functions are very similar to Python. The only thing is because Go is statically typed, and kind of declaring your types matter, you give your type, we'll look at an example now, in a parameter list, you also need to have a result list.
12:41
For example, you might take an int and return a string or take an int and return a tuple of string and float. So you would want to specify that. A crappy example would be to take a and b and add it to each other. If David McIver, author of Hypothesis, I don't know if you guys know him, he would probably stab me,
13:03
because that could break in so many ways, but anyway. So that function will take two ints, will return an int, it just adds them. One thing you could also do, which is kind of sweet, is that you could name your results,
13:24
so you could say, in this case call it c, and then you can straight away assign to it and do stuff with it. Again, in this case it doesn't make sense, because I even forgot to change return c, as you can see. But you can do stuff like that.
13:42
And just like you could do recursion with functions, like Python, there's no tail call optimization, or at least it wasn't last time I checked. The idea being that if your function can be optimized, just write a loop.
14:00
And a type of a function is a signature, and it's just a sequence of inputs and a sequence of outputs. So the signature for this function, any function that takes two ints and returns one int has the same signature. And that is useful because like Python, functions are first class citizens in Go as well, so you can pass them around, so you can have variables that point to them,
14:23
so you might want a variable that points to a function that takes two ints and returns a string. And that would be the signature of your function. I just said that. The zero value for functions is nil, we don't really care about that, but again, it's this emphasis that things have zero values.
14:46
And you can return multiple values from a function, like a tuple that you can do in Python. If you don't want one of them, again, the idiom is very similar, you use an underscore as a throwaway name, and you take it.
15:02
But this is interesting because the ability to return multiple values from a function leads us nicely to how error and error handling is done in Go, which is quite a bit different to Python. In Python, we would typically do a try except else finally, and we would catch exceptions and do things with them.
15:23
In Go, there's no concept of an exception in that sense. What you do is usually the last thing returned by function is an error, and then you check for that, check to see if it's nil. If it is nil, then you're good. If it's not nil, then you're good.
15:44
That's incorrect. But you can do the same logic with the errors in Go. Sometimes you want to catch a particular one, for example, the io package could return an end of file error, so you can check.
16:01
You could say if error equals it calls io.eof. So you can do specific ones as well. Now, you might say, well, what do we do with finally? How do we make sure something gets run? Go has these concepts of defer, and defer is often used where you would use finally or ensure in other languages.
16:23
And what it does, it says, okay, so create a file, doesn't matter how that does that, and you defer close file. And what that says is run close file whenever I'm kind of leaving the scope of this function, basically. So you can do that immediately after you open a resource. You can immediately say defer, close it later,
16:41
and it's all in one place and you won't forget later. We'll probably get back to this in a bit as well again. But it's kind of interesting, interesting way of dealing with that. There are, however, sometimes where there are genuinely exceptional circumstances.
17:02
You know, dereferencing a nail pointer or out of bounds in an array. And in those cases, go just panics. And you can also, panic is actually a function that you can call yourself. You can make your program panic too. And the thing about panic is that the idea is that it will stop the execution of the code where it panicked.
17:24
It will run all the deferred functions, and it will do them in the last and first out. So if you do like three defers, it will kind of do the last one first. And then the program crashes with a log message, if you don't do anything with it.
17:41
And the idea as far as I've seen and used and understood is that you don't really want to stop panics. You don't really want to handle them. If there's been a situation where Go has panicked, then you're done. But it is sometimes useful to recover from it, and there's mechanisms to do that.
18:03
For example, if you have a web server and something bad happens, you don't want to just keep the connection open forever. You might want to recover from that panic, even maybe send an error back to the client, and then maybe you can close everything, or maybe you can recover from it. We can take a quick example, for example, in a parser.
18:26
Sometimes, even if everything appears to work fine, the complexity of a job is in a way where bugs may still lurk in. And generally speaking, what you can do in those cases, you don't necessarily want to panic. So there's this concept of recover.
18:41
So what you do right to the top of your function, you defer a function. And because we said when in Go you panic, all the deferred functions get called. So when this deferred function gets called after panic, recover will return that panic, if there was a panic. And if there was a case, then you could deal with it and either die or try and control it and carry on with your program.
19:04
So in this case, in the case of a parser, you can just write the error and carry on or whatever. I took this example directly from the Go book, and recover will return nil if there has been no panic. So it's not really a problem.
19:22
You also shouldn't... I'm not going to talk about panics anymore. They exist. Running out of time. So what about object-oriented programming? Python is pretty object-oriented. Everything is an object. Go is also apparently considered object-oriented, though Go's definition of it is a bit.
19:44
So Go says an object is simply a value or variable that has methods, and a method is a function associated with a particular type. So you could... yes, you have that. And I'll go through how you can use it in a sec.
20:01
There is no inheritance. I don't particularly enjoy inheritance, usually. So composition is the way to do things. And let... you know, we can go through a quick, again, pointless example. Pointless. Because it's a point. I didn't even realize that.
20:22
So in Python, you would define a class. You know, a point has X and Y coordinates, at least in 2D space. In Go, you would do the same with a struct. So you define this type point. It has an X and a Y that are float 64s. Those are called fields, so we have an X field and a Y field.
20:43
And we all know how to add methods in Python. You just add another def under there, it takes self, and then it does some stuff. For example, if you want to take the distance between two points. Well, in Go, you kind of attach a function onto that type.
21:00
And you could do this to basically any type. Any user-defined type. So although it looks a bit different, it's not in the same scope, you know, that's how it works. So that's how you end up having methods. And both of those, you know, calculate distance between two lines in the different languages.
21:22
But, as I mentioned earlier, there's no inheritance in Go. But the way Go kind of handles that, the circumstances where you wouldn't need inheritance, is struct embedding. And when I first read this a few months ago, it said it composes types by struct embedding.
21:42
And I thought, what, by what, it was a bit of a mouthful. But when we take an example, it would be pretty sweet. Imagine we had the point class, and now we have a named point class. And the point of it is that it has a, I keep on saying point when talking about point. So we have a point class, and a named point class, and a named point class,
22:02
also has a name for a particular point. In Python, to do that, you would probably create a new named point class, subclass point, and just add a new instance variable to it. In Go, what you can do, we already have our point struct, we create a named point struct, and you can embed point inside it.
22:22
And what does that mean, is that when you create named points, you already have access to x, and you already have access to y. So you just, I can show you here. So named points, you pass it that point, and you can access name point of x, as if x was part of named point.
22:41
Because it is, it's embedded inside there, and you can call the functions and everything as well. So that's the way, I don't want to say inheritance is handled, but that's the way you do embedding for those kind of circumstances. And obviously there's one more OOP-esque thing in Go as well,
23:02
which are interfaces. Conceptually, they're actually very similar to duck typing in Python. You know, if you have dunder len, then something that needs dunder len just knows how to deal with it, you don't really have to do much, or dunder equal, or whatever. It's really the same in Go.
23:21
And the way, earlier I mentioned that they're satisfied implicitly, and that's what I meant. You don't really have to do anything. As long as a struct, for example, has all the methods that an interface expects it to have, then it conforms to that, it satisfies that interface. And an example, kind of from the actual built-in IO package,
23:42
is like writers, and readers, and readwriters. So, you know, a writer interface, as long as something has a write method that takes some bytes and returns it into an error, then that satisfies that interface. And you can also mix up interfaces like that, so readwriter takes writer and reader.
24:04
For example, OS that stood out conforms to some of those, it also conforms to the, satisfies the closed interface. Similar in some ways to ABCs in Python as well, although I actually think it's just the way duck typing is.
24:24
I'm just trying to think, I have one minute left. Let's see what happens. Go, one of its main strengths is concurrency, and that's kind of what everyone bangs on about. Python also has concurrency. Concurrency in Go is mainly done in two ways,
24:42
either Go routines, which is the thing that is quite famous, or traditional shared memory. We're not going to talk about that, because that's not really interesting. Just to talk about communicating sequential processes, I mentioned CSP earlier on. It's something Tony Hoare was working on in 1970s,
25:01
and it isn't really programming language. CSP is more of a formal language for defining how concurrent things interact. And the thing that, I don't know if it came from Go, or whether it was there before, but people who do Go often say, they do not communicate by sharing memory, instead share memory by communicating.
25:21
So the whole idea is that you don't really share memory, but you have these things we talk about called channels that talk to each other. Go routines are just lightweight threads managed by Go runtime, and they're pretty sweet to run. You just prepend Go to a function, and that's run in a separate Go routine.
25:44
To show you a quick example, because I have to hurry up, that's literally how it works. You say Go waste time, and it does that in the background, and it carries on. So it prints end of main first, then it will print time wasted because that thing delayed for 2,000 milliseconds.
26:03
I don't know why anyone would do that, but still. And then there's the concept of channels, and channels are the way you communicate between two Go routines. By the way, you always have one Go routine at least, which is the main Go routine. That's when you start the program.
26:21
And another basic example of a channel, you create it. Channels are like pipes in Unix, for example, but they're typed. You can't just put anything in it. You type it. So we create the channel. I've typed int. Then we have an anonymous function, which is a bit like anything else you could do that. You can't do it in Python, but I guess you have lambdas,
26:41
but they don't really work anyway. You can write to a channel. So that function writes 42 to a channel, and both writes and receiving from a channel are blocking operations. And then over there we can read from that channel. So basically we print 42, which is amazing.
27:05
I'll do this bit in 30 seconds. I wish I had more time, but the ecosystem and tools in Python I think are pretty solid. The same goes for Go, but Go comes with a lot of built-in stuff. For example, for testing,
27:20
in your terminal you're typing go test, and there are certain conventions that if you follow you can just test all your Go code. Unit test is pretty good. Pytest is pretty sweet in Python. They're all really mature stuff. With Go, anything that ends with underscore test are test files. Any method that starts with test is a test method.
27:43
Any method that starts with benchmark is a benchmark test method. And something that's pretty interesting is any method that starts with example is a example function that provides machine check documentation. So that's pretty interesting too. So really there is one way to do these things
28:02
that Go defines, and it works pretty sweetly. For Go formatting, or code formatting, not Go formatting, you just, again, use the terminal, Go format your source, and it just formats it. So if you install this as a plugin to your IDE, every time you save it does that.
28:20
Every Go file looks the same. I sometimes find, you know, we use flake8 for our Python development, and it doesn't necessarily do, you know, where to put a line break if your line is too long or that kind of stuff. Well, it does, but you might not agree with it. So that doesn't really happen, because Go just does it.
28:41
There's one way to do it, and Go will take care of it. Again, for package management, there's quite a few different ways to do it in Python. You can pip install, has at least been the most common in my lifetime. Go has concept, again, from terminal, comes with it, Go get package, and it just gets it, builds it.
29:01
Another thing about package management, Virtual M is pretty well used in Python to manage different versions and pair project requirements. You use Go path environment variable when working with Go. It's, it could be annoying, but if you end up having a nice way of dealing with it,
29:20
then, you know, it's fine too. I quite like Virtual M the way it works. Ooh, that was fast. Finally, Go comes with document generation, and you just do go doc, and it generates documentation of your Go program. Now there are quite a few tools, again, but I don't think it's, you know,
29:42
in the standard way that Go does it. It's, you know, one way of doing it, and it just does it well, and everything looks the same. So, those are kind of the ecosystems and tools, and I guess the conclusion is that, well, none of us can, you know, also come and have this talk are Go programmers,
30:02
but, and I'm not saying we should all move to Go or all stay with Python, but the idea was just to get a feel for what's there in Go, and that's it. I don't think that, you know, nothing too concrete. Just get a feel for Go, and I know a lot of people have been moving to it,
30:20
whatever, you know, if that's what you want to do. Anyway, that's it. Thank you. Okay, so unfortunately we don't have any more time for the questions and answers,
30:41
but you can chase him and ask him personally, and now we enjoy the coffee break.