Python: An Amazing Second Language for .NET Developers
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 | ||
Number of Parts | 96 | |
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/51835 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
NDC Oslo 201682 / 96
2
7
8
9
12
14
19
20
26
28
31
33
38
40
43
45
48
50
51
61
63
65
76
79
80
83
87
88
90
93
94
96
00:00
Software developerFormal languageWeightRevision controlJust-in-Time-CompilerComputer programmingSemantics (computer science)Semantics (computer science)WindowPhysical systemGroup actionFormal languageHigh-level programming languageParallel portComputer networkRun time (program lifecycle phase)Type theoryMultiplication signNetwork topologyBeta functionSoftware frameworkAssembly languageRight angleObject (grammar)MereologyPointer (computer programming)TouchscreenForm (programming)DataflowQuicksortInheritance (object-oriented programming)Compilation albumCodeAnalogyMoment (mathematics)Software maintenanceComputer programmingInternet service providerCartesian coordinate systemComputer configurationPoint cloudVisualization (computer graphics)WeightBytecodeOrder (biology)Just-in-Time-CompilerWriting
04:29
Shape (magazine)Suite (music)Block (periodic table)CodeLetterpress printingVisual systemJust-in-Time-CompilerCompilation albumGraphical user interfaceType theoryData managementSocial classAlgebraic closureSoftware frameworkIntegrated development environmentProgrammschleifeApplication service providerFormal languageSoftware frameworkLibrary (computing)Web 2.0Inheritance (object-oriented programming)QuicksortTerm (mathematics)Social classException handlingSubject indexingEndliche ModelltheorieRevision controlBlock (periodic table)Type theoryText editorWeightCodeSpacetimeRun time (program lifecycle phase)Electric generatorSynchronizationVisualization (computer graphics)Object-relational mappingApplication service providerIntegrated development environmentMultiplication signAdditionDifferent (Kate Ryan album)Functional (mathematics)2 (number)Line (geometry)Category of beingOpen setDebuggerDeclarative programmingSuite (music)Control flowStatement (computer science)CuboidCore dumpJava appletC sharpElectronic mailing listSet (mathematics)Encapsulation (object-oriented programming)Validity (statistics)NumberGroup actionGame controllerCompilation albumPairwise comparisonRight angleCross-platformPrice indexVideo gameProcess (computing)WordSpeech synthesisInternetworkingLetterpress printingLink (knot theory)FreewareUsabilityObject (grammar)Military basePerspective (visual)Drag (physics)Computer networkProgramming paradigmOpen sourceEquivalence relationComputer animation
10:45
Information and communications technologyExtension (kinesiology)Game theoryType theorySample (statistics)Scripting languageSanitary sewerCodeTemplate (C++)Installation artPoint cloudSoftware frameworkDefault (computer science)QuicksortWeightData typeVisualBASICDemo (music)Formal languageServer (computing)BitRun time (program lifecycle phase)QuicksortCartesian coordinate systemVisualization (computer graphics)Integrated development environmentProjective planeCodeMultiplication signTerm (mathematics)Internet service providerSystem identificationWindowSource codeComputer animation
12:51
Game theorySource codeBookmark (World Wide Web)CodeDiagramConcurrency (computer science)Random numberNavigationDivisorComputer fileWindowView (database)String (computer science)Moment (mathematics)Computer fontNumberSocial classInterior (topology)Active contour modelRandom number generationGame theoryCASE <Informatik>Formal languageProper mapException handlingNeuroinformatikLetterpress printingLine (geometry)Message passingCodeText editorQuicksortSpacetimeSystem callMultiplication signType theoryProfil (magazine)Concurrency (computer science)Error messageCode refactoringWeightContext awarenessInsertion lossCodeMultilaterationDeterminismDot productPairwise comparisonBlock (periodic table)outputStatement (computer science)Inclusion mapControl flowMilitary baseRight angleFactory (trading post)Cycle (graph theory)File formatSoftware repositoryPlastikkarteOcean currentTablet computerComputer fileSoftware bugRepository (publishing)Goodness of fitForcing (mathematics)AnalogySource code
19:35
OvalClient (computing)DebuggerString (computer science)Object (grammar)Interior (topology)NumberWritingProgrammschleifeLetterpress printingDecision tree learningGlass floatTupleRight angleDefault (computer science)Enumerated typeType theoryQuicksortBitRevision controlCASE <Informatik>Array data structureObject (grammar)Pairwise comparisonExpected valueElectronic mailing listC sharpSocial classSet (mathematics)ImplementationSoftware testingComputer fileOperator (mathematics)String (computer science)Subject indexingDemo (music)WordGeneric programmingVisualization (computer graphics)Expandierender GraphData modelFormal languageData structureNumeral (linguistics)DampingImmersion (album)40 (number)SpacetimeComputer animation
23:17
Thermal expansionReal numberWordDecision tree learningIterationElectronic mailing listField (computer science)Social classFormal languageDecision tree learningWordEqualiser (mathematics)Parameter (computer programming)Different (Kate Ryan album)QuicksortConstructor (object-oriented programming)Loop (music)Set (mathematics)Right angleType theoryRevision controlPresentation of a groupSpeicheradresseCompilerKeyboard shortcutPlastikkarteResource allocationFile formatNumeral (linguistics)ImplementationObject (grammar)State of matterSystem callLetterpress printingMultiplication signData conversionEnumerated typeC sharpError messageIterationSource code
28:08
Menu (computing)Execution unitDecision tree learningProgrammschleifeVideo game consoleTotal S.A.Letterpress printingCategory of beingCategory of beingTotal S.A.WebsitePlastikkarteRight angleDifferent (Kate Ryan album)Formal languageNeuroinformatikGreatest elementSineSurjective functionDecision tree learningComputer animation
29:11
Total S.A.MereologyDecision tree learningLetterpress printingSource code
29:59
Total S.A.Video game consoleLetterpress printingPredicate (grammar)CodeSoftware frameworkRevision controlLibrary (computing)Lambda calculusRegular expressionWeb pageData managementRegular expressionFilter <Stochastik>Software testingRight anglePopulation densityElectronic mailing listLimit (category theory)NumberFunctional (mathematics)Inheritance (object-oriented programming)Loop (music)Annihilator (ring theory)Computer clusterFormal languageTouchscreenMultiplication signEndliche ModelltheorieQuicksortProjective planeObject (grammar)Type theorySystem callProcess (computing)Link (knot theory)Open sourceDatabaseLetterpress printingEquivalence relationMoment (mathematics)Mobile WebSet (mathematics)CodeMessage passingDevice driverCategory of beingPerformance appraisalRange (statistics)Food energySocial classWebsiteOrder (biology)Flow separationIterationEnumerated typeLambda calculusExistenceDivision (mathematics)Case moddingData dictionaryIntegerComputer animation
35:49
Installation artData managementLink (knot theory)Price indexRepository (publishing)SoftwareElectronic mailing listFormal languageElectric currentCodeFibonacci numberCodeDevice driverNumberMultiplication signFibonacci numberVirtual machineRun time (program lifecycle phase)2 (number)Protein foldingPasswordVariable (mathematics)TupleInstallation artFinite-state machineLine (geometry)PredictabilityComplex (psychology)Limit (category theory)Data storage deviceDebuggerWeightSummierbarkeitSymbol tableBeschränktheit <Mathematik>Electronic mailing listProjective planeForestLetterpress printingOcean currentSeries (mathematics)Machine learningException handlingSemiconductor memoryWordRight angleVideoconferencingSoftware bugComputer clusterCoefficient of determinationPoint (geometry)Formal languageCrash (computing)Water vaporDreizehnForcing (mathematics)MathematicsControl flowNatural numberSource codeComputer animation
41:37
Software frameworkComputer networkWeb 2.0Social classTable (information)QuicksortRelational databaseElement (mathematics)Drop (liquid)WebsiteSoftware frameworkSequelMultiplication signCuboidWebcamComputer iconGoogolSpacetimeGoodness of fitDemo (music)Application service providerRevision controlFormal languageCodeWeight
43:42
DreizehnScaling (geometry)Overhead (computing)Row (database)Computer networkTable (information)Metropolitan area networkWeb pageKey (cryptography)Device driverVolumenvisualisierungFormal languageWeb 2.02 (number)FrequencyTemplate (C++)Pairwise comparisonSocial classMachine codeMappingWeb browserPoint (geometry)Query languageWebsiteDatabaseLink (knot theory)Endliche ModelltheoriePhysical systemSpeech synthesisSoftware frameworkExtension (kinesiology)Right angleSoftware testingView (database)Application service providerRepository (publishing)Default (computer science)Virtual machineC sharpSubject indexingComputer animationSource code
47:31
Just-in-Time-CompilerCompilation albumGraphical user interfaceCompilation albumMixed realityCross-platformMereologyJust-in-Time-CompilerVirtual machineProjective planeRun time (program lifecycle phase)Library (computing)WeightCore dumpMultiplication signQuicksortLoop (music)Bounded variationGraphical user interfaceComputer configurationImplementationDefault (computer science)Extension (kinesiology)ArmDrop (liquid)CuboidSystem callComputer animation
49:52
Software testingFunction (mathematics)Presentation of a groupGraphical user interfaceDebuggerMereologyWeightFormal languageEquivalence relationSource codeConvex hullRoboticsComputer fileStructural loadJava appletRight angleBookmark (World Wide Web)Repository (publishing)Visualization (computer graphics)AdditionSocial classQuicksortOnline helpCodeBuildingFreewareCore dumpFormal languageWeb 2.0Point (geometry)MereologyPatch (Unix)FreezingWindowSequelElectronic mailing listMobile appCAN busSoftware frameworkComa BerenicesLibrary (computing)Source codeE-learning1 (number)Plug-in (computing)Higgs mechanismForm (programming)Group actionComputer networkComputer animation
53:47
Web 2.0Virtual realityProjective planePoint (geometry)AreaServer (computing)Right angleInjektivitätProcess (computing)Mobile appDatabaseSoftware repositoryState of matterSoftware testingExecution unitUnit testingWeb serviceDirected graphPiSequelThread (computing)QuicksortIntegrated development environmentMultiplicationRun time (program lifecycle phase)Library (computing)Physical system1 (number)MereologyInstallation artElectronic mailing listEndliche ModelltheorieHost Identity ProtocolType theoryComputer fileSystem callSoftware frameworkMultiplication signMoment (mathematics)Goodness of fitCartesian coordinate systemComputer networkParallel portInheritance (object-oriented programming)Module (mathematics)Computer animationSource code
Transcript: English(auto-generated)
00:05
Hello, everyone. Thanks for coming. I have some cool stuff to share with you. Let's just maybe take one more minute, let people get situated, and then we'll get started. And the screen watch, too.
00:26
All right, looks like the flow has stopped. Well, almost. So, welcome to my talk. I want to ask you guys, how many of you would consider yourself C-sharp, .NET developers? Just show your hands. All right, so for the camera, that's everyone. Basically everyone here said, more or less, you're doing .NET.
00:43
And I'm like you in this regard. I've done C-sharp and .NET for a very long time. I was doing .NET programming back in 2001, when .NET was still in beta before it was even a thing. So I really like C-sharp. I like the ecosystem. And I'd like to take you on this journey.
01:02
I guess that, what is that, 15 years or so, I've been doing .NET. And .NET is great, but there's a lot of drawbacks to it as well. There are not many options for doing .NET outside of Windows. If you want to work on Mac, what's the story?
01:23
For a long time we had Mono, and it kind of sort of worked somewhat. If you're writing server-side applications, and you want to deploy to the cloud, deploying to Linux has a much better DevOps story, a much better deployment and maintenance story, as well as it's over half the price cheaper.
01:42
There's lots of reasons you might want to look beyond Windows. And one of them may just be to diversify your careers. So about four years ago or so, I really started looking around. This is the Steven Sinofsky, Silverlight is Dead, time frame. I'm thinking, all right, well, if they screw this up enough, what would I go do, other than, say, C-sharp?
02:03
And I came across Python, and the more I looked at it, I'm like, wow, this is a really wonderful ecosystem, wonderful language, and it's actually a really comfortable place to transition to. So what I'd like to do today is go through and sort of start out by introducing some of the basics of the Python language,
02:23
and I think I'm actually going to switch the order. We'll talk about C-sharp a little bit first. What about C-sharp is awesome in .NET and its ecosystem? What about Visual Studio? What are the things that you would really miss if you weren't doing C-sharp in .NET? And then we're going to go and just quickly look at the Python language enough that you guys who maybe have not seen it are able to follow along.
02:44
You'll see that's really, really simple. It takes like, I don't know, ten minutes, tops, maybe five. And then we'll go through all the things that we decided were cool about C-sharp, and we'll look at their parallel or their analogous feature in Python. And I think you'll be surprised when we do this comparison.
03:03
All right, so what is Python? Well, first of all, it's a language. It's a high-level programming language just like C-sharp. It's also an ecosystem. It's also a runtime. It's interpreted, so it has byte code much like C-sharp has IL,
03:22
but instead of taking that last step and doing JIT compilation on it, it just takes that byte code and interprets it in a C runtime. However, it also can be JIT compiled, as we'll see. It's very object-oriented. It's strongly typed. People think of Python as a dynamic language.
03:42
There are parts of it that are strongly typed. Everything that is a variable is a pointer in Python. Everything that it points to has a type, has an object of some form, as an inheritance tree, potentially. But the actual semantics of the language are dynamic.
04:00
You don't say the type, but out there, there really are types. And the history of this language was to create a very readable language. And that turns out to be super important, because most of the time, we are reading code, not writing code. So you'll see Python's a joy to read once you get comfortable with it.
04:21
And finally, it has a very similar idea to what you guys have in .NET with assemblies with these things called packages. You often hear the term that, Python comes with batteries included. And this is sort of a theme in the language. The standard library comes with batteries included.
04:40
This web framework, say, Django, is the web framework with batteries included. And what that means is, it really has a lot of rich features baked into it. Very much like the base class library in .NET, there's a rich class library, and of course, there's the broader ecosystem as well. All right. So that stuff's all really nice and good.
05:02
The one thing that you're going to have to get used to, if you've not seen this before, is how Python defines code blocks and sort of control flow and functions and so on. Now, if you work with this for just a few days, you'll find it is super comfortable. It's actually, I think, nicer than what C Sharp does,
05:21
from a typing perspective at least, probably reading as well. But the first hour or two that you work with it, you have to sort of suspend your belief that this seems weird or something. I suspect it would if you're coming from C Sharp. So the way Python defines blocks of code is with white space.
05:41
So here we have two methods. They're in these blue boxes. And then we have an if and else statement in each one. Now, there are no curly braces. The way that we know that these are code blocks or what Python are called code suites are indentations. So here we have a method. There's no indentation. And then we indent four spaces. And everything indented four spaces is within this method.
06:03
When you stop indenting, now you're in another block defining a class or a method or something. Similarly, we have an if. Here we have some comparison. Notice there's no parentheses around it. Do we really have to type the parentheses all the time? It feels like you do because you do it every day. But in fact, there's really no benefit.
06:21
You can type them in Python if they add some value, but they're not required. So we'll see that there's no semicolons at the end of the line. The code blocks at the end of the method, at the end of the first line of the method, the end of the first line of the if statement, always start with colon to say, now here comes a block, indent.
06:41
White space really matters in this language. Everything should be indented four spaces, not a tab that's equivalent to four spaces, not three spaces, things like that. Now that sounds like a challenging requirement, a tedious requirement, but you'll see the editors make this entirely transparent to you. So no curly braces, no parentheses, tabs are not your friend.
07:02
Tabs are so much disliked in Python that there's an exception type that says I found a tab. All right. So remember I said, what about .NET? Is it that if you were to go work on some other language, like somebody said, hey, you have to go back and work in C, you'd be like, oh, no. What would you miss?
07:21
So here's my list. I'm sure you guys have a list as well, and it probably has a pretty strong intersection here. So one of the things that's cool about C Sharp is everything derives from a common object, so you can treat everything as an object if nothing else. The ability to not care about indexes
07:41
when you're looping around stuff, like for i equals 0, i++, you don't have to do that in C Sharp. You can just go through a collection. Anything that is inumerable, you can just for each over. That's really awesome, right? So if you didn't have that, you would miss it. I'm entirely over the concept of writing get age, set age as two functions
08:02
in like C++ or Java or something like that. And so the properties that let you do that encapsulation and validation like you need to, but don't make the consumers of the class pretend it's a method. That's really nice with class properties. Anonymous types, NuGet. I mean, how old is NuGet now?
08:21
Four, five years, something like this? It really changed the way that we interact with open source, with external libraries. Basically, you have the ability to say add reference to something on the internet, and it stays in sync. That's fantastic. ORMs, entity framework. You can debate whether ORMs are a good idea, but if you like them, you would really like
08:41
to keep using them, I think. Debugging. Visual Studio is definitely one of the better debugging tools out there. It's an idea. It's a really great tool, so that wouldn't be something you want to give up. ASP.NET MVC, fine web framework. Lync. Remember back, I think it was 2008
09:00
when Lync came out, C sharp three? That was a fantastic addition to the language, right? This declarative programming model. Really nice. Some kind of rich IDE. Often, you'll see people working in Python and VIM or Emacs or some very sort of shell-based editor.
09:21
That's probably something you would not want to go to if you're used to Visual Studio, I'm guessing. Some kind of isolation. This multiple versions of the runtime. This whole thing with .NET Core and basically installing the runtime as a really large NuGet package. That's a really cool feature, but also the previous.
09:42
Just be able to have the different versions of runtime there. That's great. Yield. I don't know if you guys use the yield keyword. It's probably the coolest feature that is least known as some kind of ratio there in .NET, but yield is amazing for building generators and sort of lazily evaluated methods. Lambdas, base class libraries,
10:02
JIT compilation, ReSharper. You guys use ReSharper? Yeah, of course. Otherwise, you have to type. It's bad. And then finally, some kind of designer, draggy-droppy stuff. This is all cool. What I'm going to show you is every single one of these has a feature that is as good and many times better in Python
10:20
than you have in .NET. If you could say, I'm going to go in to check out some other language that has a whole bunch of other cool advantages, cross-platform, free, easy deployment, lots of things, and it had all these features, that would be really compelling. My goal is not to get you to stop writing C-sharp, but just to sort of diversify, think about what's out there.
10:42
First of all, Visual Studio. You would not want to go without this thing and use the community edition, because if I can, it's free. Why not? Come over here and we'll fire up Visual Studio. It has ReSharper and all those sorts of things installed in it, but wait for it to come to life here.
11:02
It does have ReSharper after all, right? We don't really need the Server Explorer here. So you could say, look, there's no way I'm going to give this thing up. It's beautiful. All right, so you come over here and say, all right, I want to create File, New Project, and if I zoom in, notice, you can get Python Tools for Visual Studio
11:20
created by Steve Dower and some other guys at Microsoft, who are not just people who decided to add some kind of feature about Python to Visual Studio, but these guys are literally core developers on the CPython runtime. These are the people that contribute to Python itself,
11:41
and I can just come over here and create a Python application. And this has debugging, it has IntelliSense, it has all the cool stuff, you know, watch windows, whatever that you would expect in Visual Studio. So that's pretty sweet. So if you're like, I couldn't give up Visual Studio, cool, don't. All right?
12:00
The other one is, though, getting closer to this ReSharper idea, there's actually, in my opinion, a little bit better IDE that comes from the JetBrains guys. So if you're going to use Visual Studio, you might want to check out something called PyCharm. So I was really excited to hear that the JetBrains guys created Project Writer,
12:22
which is their own sort of dedicated C Sharp IDE without Visual Studio, just like, what if it was ReSharper all the way down, right? That would be cool. Well, that's basically what PyCharm is, right? It's like the IDE that JetBrains created for Python, and it's really, really slick. All right, so let's go and actually write a little bit of code
12:42
using PyCharm. Just enough, we'll spend maybe five minutes, maybe a few more, looking at it. All right, so let's go here. Hopefully the fonts are big enough. I know that this is small, but the main editor fonts are larger. All right, so we're going to go and create a new file,
13:02
create a Python file, and I'll just call it, let's see, game. Who doesn't want to create a game, right? Now, all this stuff is going to be available to you in a GitHub repo, and ReSharper just asked, hey, it looks like you're working within this GitHub repository, or just a Git repository, it doesn't matter, it's GitHub. Do you want to add this file?
13:21
So yes, we do want to add this file. All right, so what we're going to do is we're going to play guess this number game. Really, really simple, right? You know, the computer will think of a number between, let's say, 0 and 100, and it'll say, what number do you think I'm thinking of? Is it too high, is it too low? Something like this. This will give us just enough of playing around with the syntax to be comfortable.
13:41
So we can start out, and we don't have a console.write line, we don't have that. Rather, we have print, okay? Very similar otherwise. So we'll print, this is the guessing. Spelling is hard. The guessing game. By the way, PyCharm will fix spelling errors in both your method names, type names, and in strings.
14:04
All right, so we can just print an empty line here to go like this. And then let's say we want to get a number from the user. So instead of saying console.read line, we can just say input. So we'll say guess equals input, what number am I thinking of?
14:24
We'll say 0 to 100, inclusive. Let's put it like so. All right, so we also need to have a number that we are thinking of. So maybe just conceptually having that first makes a lot of sense. We'll say, call it the number.
14:43
In C Sharp, you would probably write the number, like this. But here we have what's called snake casing. Lots of underscores in Python, as you'll see. So we want to create a random number. So we can use this thing called random, just like in .NET. And ReSharper knows that we actually have to sort of add reference to this.
15:03
So we can say import this name up at the top. This is like using plus add reference in one shot. Then we say rand int from 0 to 100. That may not be inclusive on 100, but good enough. All right, so then we have this guess. And we could say, we could try to compare the guess,
15:21
but right now it's a string. We could actually test that by printing out this. So let me run this. If I zoom up here really quick so you can see, you can see there's a button. Like I should be able to click it or debug it, but nothing happens. So if I go over here and I right click, I can say run debug, run with code coverage, profile it,
15:41
run concurrent. Good stuff. But let's just run it. And now I can just press up here from so on. All right. Sorry. So I can say, let's say 50. It's a good guess. Maybe I'll print this, not just execute it.
16:00
All right. Let's try 50 again. So this is the class of string. And we want str, but that's string in Python. We want integer, so we have to convert it to an integer. That's easy enough. So let's call this something like guess text. And I'll just use a refactor rename like that. And we'll come down here and we'll say, now the guess is actually going to convert this by calling
16:25
this constructor for int. And then we can just do our little if block. Then we'll be done with our game. So we'll say something like this. While guess is not equal to the number, we're going to do something. I kind of want to leave an empty space here for a moment
16:42
while I print out the last line. Now normally you would just do curly curly, right? But there's no curly, so what do you put? There's a keyword called pass that says, here's a block, but it's empty for a moment. So hold on. So in the end, we'll print done like that. Here we can just say if.
17:03
I guess we want to run this a few times, don't we? So we can come down here and put that in there. So if we go in here, then of course they didn't win. We can say something like print. We guess we got to do an if statement, right? So say if the guess is greater than the number.
17:24
Now remember I told you about the white space. You haven't seen me like fiddling with a space bar or anything. Watch this. So if I hit colon and hit enter, PyCharm automatically knows I'm defining a code suite, and so it has to indent four spaces. But if I want to go back, the chances I want to go back one space, well, I would never want to do that in this context.
17:41
So if I hit the backspace, it goes back. If I hit tab, it goes forward. And it looks like there's tabs. I told you Python hates tabs so much there's an exception type for it. These are actually spaces, but the editor just knows four spaces. Okay, so I can say print too high, and down here I can say else print too low.
18:03
Well, I guess I need to do an else if. Guess is lower than the number. We can do else break. Notice what I'm calling. All right. Let's just do this down here.
18:23
When we're done, we'll say something like print. Right, it was. In C Sharp, you could just print out the guess. It won't implicitly convert things to strings. So in C Sharp, you could write this. You could say curly brace dot format, and then you could say guess.
18:41
And you can say that in Python too. All right, so let's go down here and let's play this game one time. Hopefully this is working. 50. It's too high. 40. Too high. 30. 20. It's getting suspicious. 10. Oh, five.
19:02
Eight. Nine. Yes, it was nine. Okay, so that's the Python language. It has classes and other stuff that we'll look at here in a minute, but it's pretty straightforward. It's quite familiar. You have this sort of dot syntax, random dots, such and such.
19:20
It's quite like C Sharp and the other C languages except for these code suites, but you see if you use a proper editor, it's basically transparent to you. If you use Notepad, you're going to be having a bad time. Don't do that. Okay, so let's carry on. All right, so now we know a little bit about the language.
19:40
Let's do some comparisons of some features. All right, so I won't take the time and go run it, but I can tell you. Maybe I'll do this in a later demo. In PyCharm and in the Visual Studio, we have very, very similar debugging experience to what you guys have in C Sharp. I don't think we have edit continue, and I think that's probably good. All right.
20:01
Okay, so we also saw that in C Sharp, everything is an object, and in Python 3, everything is an object. Both of these languages, if you omit object from the right in that inheritance, then guess what? It's still an object, right? So they're very, very similar in that sense,
20:21
and that means that they have a common set of methods that you can override and replace. So here you can see in our C Sharp document, we're overriding the toString method, and when you call the toString, it says, I am a document. Yeah? In Python, we have something called the Python data model, and it involves a lot of underscores,
20:42
but it means basically the same thing. Instead of having this concept of like an operator or this base method, you have about 40-ish methods that are what are called either dunder methods for double underscore on both ends or magic methods. So here you can see we're using the dunder str.
21:01
Remember, you saw that's the class name for string. So this is like the toString for it, right? We could define a dunder bool, and we could do a true, false test. We could do a quality and all these sorts of things on here, right? But notice which one has more typing and more surrounding, supporting structure
21:22
that doesn't necessarily have to be there, right? So this is kind of an edge case. It's a little bit, the Python looks a little cleaner once you get used to it. The dunder underscore, double underscore thing maybe knocks it down a bit, but you'll see this is the thing that repeats. All right. For each, remember, for each, very nice.
21:42
You don't have to worry about indexes and off by one errors, these kinds of things. Well, Python has something very similar. They don't use the word for each. They use for thing in, but it means exactly the same thing, right? So if we have a list on the left in C sharp,
22:02
we have an array. In the right in Python, arrays are lists, basically. They're dynamic, expandable things. You can create arrays, but they're actually harder to instantiate. So the default thing is these expandable arrays called lists, like you'd expect. And then anything that is a collection,
22:22
there's all sorts of collections, you can just like in C sharp, for each over them. But we call it for n, yeah? Now, one of the things that's awesome in C sharp is you can actually add this to your own type, right? If I have a type here we call of a shopping cart, I can just implement inumerable, of tuple,
22:41
of string, of comma float, and then implement both the generic version and then for historic reasons, because generics was not added to dot net to C sharp, or to dot net to. We also implement the older object-based version of get enumerator, right? And in this case, notice we're like just leveraging
23:02
the get enumerator feature of our underlying type, right? So we have a list, the list itself is enumerable, so we're just basically saying, well, when you enumerate my type, just do whatever the list does for enumeration. Let's do this for Python. So let's go over here, make a new file.
23:22
No, sorry. So we'll go over here and let me rerun this one. There we go. So what we want to do is we want to create a class, and our class was a shopping cart, so we'll say class shopping cart. And it had a constructor.
23:42
Now, the constructor in Python is a two-phase thing. There's a allocation constructor, and then there's the sort of initializer. So we have this dunder init method. Now, the way you define fields in Python is a little different. So you sort of dynamically, within this initializer,
24:04
add the types to the class. So if we wanted to have a set of items, let's make it really clear, call them cart items, something like that, and we could initialize that to an empty list, this is what you would write. Now, let's actually define some items as well, so a cart item.
24:22
And it's going to have a knit. PyCharm has a cool little shortcut for that. Let's say this has a name and a price, something like that. So PyCharm knows that this is how you add fields, so I can just hit Alt-Enter and it says, would you like to add name as a field to this class? Of course I would. Maybe I'll do that for price as well.
24:41
OK. So down here, I can say let's create a cart equals shopping cart, like so. You don't say new, you just say the name and call it. It's what's called a callable. And then to the cart, we can, let's give it a method for add here. We could just directly work against the cart items, but let's say def add.
25:00
Whoops. Now, in many languages, we have a keyword, this. In Python, we have a keyword called self. The difference is, you explicitly state that as a parameter when you define the type, whereas in C Sharp and C++, this is, it's also passed in the execution when you call the method, but it's implicit, you don't state it,
25:22
so anyway. So we'll say down here, self.cartitems.append item. So now we can come down here and say, go to my cart and say add. Notice even though it says self, you don't actually say self. It's basically implicit. So let's add a cart item,
25:41
and our cart item is going to take two things. You can see the name and a price. Let's call this a Tesla, and what does a Tesla run? I'm going to have to do this in dollars. I'm not good enough at converting. How about that? Okay, and let's add also a leaf, another electric car, and I think that's more like 30,000 US dollars.
26:02
Okay, so this is great. We've got our shopping cart, and it's got some items in here. We could try to print it out. You won't see much, but if you look carefully, it says, oh, there's a shopping cart object at this memory address. So let's try to loop through it and print them out. So I come down here and say for item in cart,
26:23
and say print the, just do like this. We'll do the price. Is that going to work? Yeah? I think that will work. And then one of these, okay?
26:41
We'll do a format, and we can say item.price, item.name. Okay, now if I run this, it's not going to be super happy. It's going to say, cart is not iterable. If I tried that in C sharp, I would get a compiler error saying, cannot convert shopping cart to inumerable or something like this, right? Cannot use it in for each loop.
27:02
But the way that I add it is actually going to be less effort here. So I can come over here to my shopping cart class, and I can define a dunder iter method. And then I just do, I could either implement my own version,
27:22
or I could like in C sharp, lean on the list implementation. So for now, I'll do this. I'll say self.cartitems.dunder iter. Just like get enumerator on the list in C sharp. Now if I run this, you can see somewhere I screwed up something.
27:44
Oh yeah, it's supposed to go like this. No? I'll just do the comma. There we go. All right. Thank you, whoever said that. Cool. So all we have to do is implement this method up here,
28:01
and we add iteration into our for in loop, just like you would in C sharp. All right? So if we look back over here, you can see same feature, less work. Takes some getting used to. I realize that this is totally new, right? But if you were equally comfortable in both languages,
28:23
which one would you rather read and maintain, right? All right, cool. Properties, like I said, I'm totally over get thing, set thing, but the need for them is really important, and it's cool that C sharp has it. It's cool that Python has it as well.
28:41
So you basically define a basic method, and you put what's called a decorator, a property decorator onto it, and that transforms it into, if you look at the bottom down here, total price is curly zero cart dot total price. Total price is curly zero cart dot total price. Only difference is the naming syntax,
29:01
naming convention on the type, right? Pretty awesome, right? So this is cool for like a computed property. We could add this to our cart up here. We could go def total, just call it total, and we could return, we could do something like this.
29:20
Total, I'll just say t for now, equals zero, four, i in self dot cart items, t plus equals i dot price. Return t, yeah? Now this is a method, but if I do this,
29:42
then I come down here at the end, and I can say print the total is cart dot, and you see total, just beginning property, right? Total is $130,000. Cool.
30:02
So we have the same basic idea. Anonymous objects, remember anonymous objects are most important in C Sharp for projections in link expressions, right? But they're generally useful in a few ways, right?
30:20
So we could write code like this. We could say new and just define two properties on it. Now Python doesn't have this feature, but Python is super flexible, so we could define a class that says when anybody tries to get an item off of you, actually derive from dictionary and pretend you're calling the get method on dictionary. And when somebody tries to set an item on you, actually set an item in your underlying dictionary method.
30:41
And then we can basically write the same code. Cool, yeah? And we'll see that this would be potentially useful for exactly the same reason as it is in C Sharp around projections to linked objects and databases and stuff like that. All right, lambda expressions. When I learned about lambda expressions, of course these came with C Sharp 3 as well.
31:02
I was like, oh, these things are amazing. I've got to rewrite some code, right? All right, so let's go and work on this, actually. Let's switch over here. And let's do another example. Python file, yeah? So we'll call this,
31:20
I'll just call it methods and filter, something like that. So let's write a quick method. And this will be filter numbers. And it's going to have some kind of function that you pass called test. And it's going to have, let's say, a limit so we can tell it how many we want. I guess we'll just hard code it.
31:41
We don't really care. So define the method, hit colon, enter, thing automatically indents. Say for. What's interesting is I can't write this. I equals 0, I less than 10, I plus plus. That literally doesn't exist. There is no numerical for loop in Python.
32:01
I mean, you want to talk about embracing the I enumerable sort of concept, right? That's all you can do. But what we can do is we can say for n in range and create an enumerable type, iterable type that goes from 0 to 100 and then loop over that. And this uses lazy evaluation, much like link to objects or something like this would.
32:22
So I can say down here, if, let's say, now test, if this is a method that takes an integer and returns a bool, I could say if this number is in the set, whatever your test you're going to give me is, I'll call this data numbers whatever, make that a list.
32:42
We could say data dot append n and in the end, we'll say return data, yeah? Whoops. So I could have another method, even, something like that, that takes a num, something like that, and it returns num mod 2 is 0, yeah?
33:01
So then I could do something like my d equals filter numbers, yeah? And I could give it the even, not calling it, but pass it as a function and then I could print those numbers. Am I running the right one? No, let's run this. Here you can see, you can actually see even numbers, yeah?
33:23
But of course in C sharp, you don't have to write this even thing. Like that's, whoops. No, I don't want to compress you. You don't want to do that. You want to just write some sort of thing here. C sharp, you would say like num goes to num.
33:40
Let's say we want all things divisible by 11. Mod 11 equals 0, right? But you can see that Python is not happy because we can't do this. Instead what we do is we say lambda and we put a colon separator. Yeah?
34:02
Oh, I probably should print d still, yeah? Cool, yeah? Super familiar, super clean. Okay. All right. So, yeah, we can write the same code.
34:22
And again, look at the size of the code. Look how much junk is on the screen. If you're equally comfortable in both languages, which one would you rather look at and read? This is the theme. All right, link. Now, hat tip to C sharp here. Link in C sharp is better than the equivalent in Python. So let's review.
34:42
We have a collection called people. We want to go through that collection, find all the people who are over 30. We want to order by their age, descending, and we want to do a projection to just peel back two of their values as an anonymous type. So in Python we have something called a list comprehension, which is very, very similar.
35:01
And you can also create something called a generator expression as well. And you've got to kind of remap these things. So like the from goes to a for. The where goes to an if. The select goes to my anonymous object. The ordering is different. It's not quite as nice, but it's actually surprisingly similar. There's no sort built in, sadly.
35:22
All right. Okay. This one is really powerful, and this is maybe one of the main reasons you guys should consider Python. Okay? In C sharp, you can go and use NuGet. And like I said, NuGet changed the way that we in C sharp work with packages, work with open source. The open source adoption grew massively
35:42
after NuGet became a thing. So in Python we have something called pip. Yeah, something called pip. Forget what it stands for. And we can do basically the same thing. So here I'm installing the MongoDB driver for C sharp. Here I'm installing the MongoDB driver for Python.
36:02
So you can say, well, NuGet is amazing. In Python, NuGet has so many packages. It's incredible. There are almost 57,000 projects on NuGet that I can go and just add reference to. It is amazing. In Python we have this thing called PyPI, and it has 81,000, 82,000 packages.
36:22
So if you want to do machine learning, pip install scikit-learn. Four lines of code, you are now doing predictive machine learning. You want to do proper storage and hashing and salting of passwords. pip install passlib. Run this with enough complexity
36:41
it takes 0.2 seconds to test a password. So something like 100,000 folds on it. Three lines of code. Beautiful. Now, one of the things that's really cool about C sharp, I think it's probably less used. Maybe I'll do a poll on you guys. How many of you people understand that C sharp code there?
37:03
Like, are familiar with that? Yeah, okay. So for the video, let's say third. A third of the audience. So let's write this in Python. So just let's do it really quick. This is the Fibonacci sequence. This will generate an infinite series.
37:23
The Fibonacci numbers are an infinite series of numbers. This method will generate an infinite collection that you can for each over. And yet it does it instantly without killing a machine or locking up or things like that. So could this be done in Python? The answer is yes.
37:40
Call it Fib. So let's go over here and we'll define a method called Fib. We could say something like this. Nums equals such and such. And then we could say, set a limit. Let's just say 100 for a minute. There's two numbers involved. The Fibonacci sequence goes like 1, 1, 2, 3, 5, 8, 13, where the following number is the sum of the previous two.
38:02
So 1 plus 1 is 2. 1 plus 2 is 3. 2 plus 3 is 5, and so on. Important in nature, math, that kind of stuff. So we need two numbers, current and next. Now I'm going to say nxt because next is a proper word, is a thing, a defined symbol. Now check this out. In Python we have this concept of tuples.
38:22
.NET does as well, but it's not nearly as integrated in the language. So I can say, I would like these two numbers to start out with 1 and 1, and I can unpack these like so. You'll see this is a lot of really cool uses, not just defining variables like this. So I could say this, while current, let's say next,
38:44
is less than, let's say 200. It's going to be infinite, so it doesn't matter. We'll say, let's start this out like so. We'll say current. You know when you swap numbers in C Sharp?
39:02
It always requires three steps, right? Temporary variable, set one to the other, set the other to the temporary variable. Here we can just say this is going to be next, and next plus current. And then we'll say numbers.append, I think I got that right. And then in the end, say return num.
39:26
So let's just print fib, and maybe we want to run it. What do you guys think? Those look like them, right? But this is a bounded set. This is just algorithms.
39:40
This is not super interesting. It has a lot of parentheses that makes it important. No, not really. So let's actually say I want all the numbers. Now what's going to happen if I run it like this? How long will it take to run? Answer, not long. How long will it take to crash?
40:01
Not long, because it's going to run out of memory, right? It's just going to jam it into that list until it's done. Well, we can come down here and we can actually say this. I can say yield, just like in C Sharp, current. And what that means is, I'm going to go through here and every time I find an item, say here's an item in my set, the runtime will basically create a state machine
40:21
that is iterable that then runs through this forest. Now this is going to run forever. This is bad. But I could say for n and fib, and then consume it until I, as a consumer, have decided if n is greater than 300, break. Otherwise, print n, and I want to not do a bunch of new lines.
40:41
I'll say I want to separate my lines with that. Now if I run it, look at this. Cool, yeah? But it's not just cool like that. Watch this. If I hit the little debuggy thing, no, not code coverage debug.
41:01
So we come down here. Let's go step in. Now here I am stepping, stepping, stepping, yield. First item, it's back here. I work with it. And then when it jumps back, it's going to go back probably to line four. But certainly not rerun this method.
41:21
And check out the debugger. This is really sweet. It just automatically shows you all the variables that are in scope, like inline. Yeah, that's pretty awesome. OK, so the same thing happens in C sharp, except look what you have to write.
41:42
Which one do you rather read? Which one do you rather maintain? All right, don't have a ton of time, but I can still give you guys a bunch of good demos. All right, let's keep moving though. ASP.NET is a fine web framework. I've written lots and lots of popular, heavily used websites, let's say, and really enjoy working with ASP.NET MVC.
42:06
Python, we also have a bunch of web frameworks. Turns out the web is the most, I've got to be careful, probably the most prominent place for Python. You see it a lot in data science, you see it a lot in DevOps, you see it a lot in many places,
42:20
but in the web it really shines. There's a few sites that have been built with Python. Let's see, Discuss, YouTube, early version of Google, Pinterest, sites that are not little minor things, right? Like, serious sites.
42:43
Reddit, for example. Dropbox, almost all the infrastructure, including the little tray icon and the website, is written in Python. Another thing that's really nice, really important, is a good data access story.
43:01
On both languages we have MongoDB, which is already a really good story. Traditional relational database stuff, Entity Framework, well respected in the .NET space. Here we have something called SQLAlchemy, at least it's good, it's very nice. Lazy loading, eager loading,
43:22
navigation relationships, it has something like Entity Framework code first, that will actually generate the tables from classes, things like that. So let me just pull up a quick website that I built with a web framework in Python called Pyramid, and SQLAlchemy, and just show you guys really quickly.
43:41
So I run a podcast called Talk Python to Me, and if I pull it up there, I can just show you a few of the moving pieces. So just to show you that it looks like something at all, let me run it. So notice one thing, this is a really large website actually,
44:02
if that was ASP.NET, there would be like a 10 to 20 second compiling the ASPX pages, there's always this long startup period. It's like this, right? Yet you'll see the performance is really cool. So let's look at a particular page.
44:22
If I come over here, I've got a bunch of episodes, I click on one of them, here's an example, and I come over here to this page, where are you episodes, like so. You can see over here we have a template page,
44:42
this is like our Razor, this is the method, it's mapped, there's some data like an ID of the episode, as well as a page name that is also mapped over. We create this view model that goes to the database, we'll talk about that in a second,
45:00
and then we just return a dictionary to our template page, and very much like Razor, you say things like at episode.name, but you use curly braces instead. Now if we look at this view model thing, you can see it actually goes to this repository
45:20
and gets the episode, does a few other things. Down here it says, go and create me a database session, create a query based on this episode class, and find where the show ID is, the past and show ID, get me the first one. Pretty similar to Entity Framework, it's not identical because it doesn't leverage this link thing, it's more like the extension method style of link.
45:44
If you look at this, this is one of these database entities, you can see this is its table name, it derives from SQLAlchemyBase, here's the primary key, which I set to be auto increment when it created it, here is the whether or not it's published, its default value is false, and go ahead and add an index on that.
46:01
It's really nice. And just by typing out this class and hitting go, it will basically create the tables if they don't exist. Really nice system. Now you might wonder, well, sure this is fine Michael for a silly little website, but what if it requires performance? .Net is compiled, it's compiled to the machine instructions,
46:21
it's got to be faster, right? I don't know. So I did a test at a talk I did at another conference where I created something like this, but it used MongoDB, used PyMongo and the C Sharp Mongo driver in comparison, and it talked to a Mongo database with 1.2 million records,
46:41
and it did a web request, same basic stuff you saw, query against the database, take the record, send it over to the template, render it in Razor and Chameleon, which is what it's called here, and then return it to the browser. In C Sharp, it was pretty fast, it could do that in like 9 to 10 milliseconds.
47:00
Python did it in 6 milliseconds, right? So it's hard to compare the performance, but it's easy to think, oh, this is like a scripting language, so it must be slow and inefficient. Actually, this site is probably faster this way than if I'd written it in ASP.net. Not necessarily because Python is faster,
47:22
but because the overhead of ASP.net is bigger than the overhead that you typically get in the what are called microframeworks in Python. All right. So hopefully that look inside was cool. Like I said, JIT compilation, right? This actually really is important, and there are certain,
47:40
especially around like computational work, this is really important, right? So in Python, what can you do? Well, it's by default interpreted, the runtime you get called C Python. That means it's implemented in C, but it's actually interpreted. But there's this project called PyPy, a Python runtime written in Python,
48:02
hence the PyPy, and it does JIT compilation just like C sharp. And this is much, much faster than regular Python, like 5 to 10 times faster. However, it's not as compatible with certain libraries. The performance story in Python is really different than it is in .NET because like that SQLAlchemy library I showed you,
48:23
much of it's written in Python, but there's like an inner part where it does like serialization, and there's like a really hot loop. That is actually written in C and then imported as a C extension, right? So there's a lot of mixing of like, this little part is slow, so let's write that loop in C,
48:41
that all of a sudden like really dramatically changes the performance story. So it's not super easy to say interpreted, not interpreted, because there's some variations there. But this is one option. There's also Iron Python in Jython, which let you run Python on the CLR and JVM, respectively. Iron Python is kind of fading away, but it's still pretty interesting.
49:01
Dropbox, like I said, basically everything they do is in Python, so they're very interested in performance. They're working on this thing called Python. And the Azure machine learning guys are working on something called Pidgin to add JIT compilation to the C Python runtime as an option, and they're using the .NET core CLR
49:20
as the first sort of implementation of this, which is pretty interesting. And that's cross-platform, so that's cool. Now, again, hat tip to C sharp on the GUI story. It's by far and away a better story than it is in Python, okay? GUIs are probably the least common thing that you write in Python, but you can write them, and there's some options that are not bad.
49:42
So you can use this thing called Qt, and it has like a draggy-droppy designer. And what's cool about Qt is it's cross-platform. So to give you guys an example of one of these, I do a lot with Mongo, and my favorite tool from MongoDB is this thing called RoboMongo.
50:01
Let's just go here, and I'll just pull up some stuff, and I'll zoom in. All right, so this UI, I think this is a pretty slick-looking UI. This thing is, which I think looks quite native. One of the problems with these cross-platform things is they look fake. Remember all the early Java file dialogues?
50:21
You're like, whoa, this is something weird, right? This is not like that, and this is written in Qt, okay? Technically, it's written in C++ in Qt, but it just as well could have been written in Python in Qt, yeah? So in .NET, we have WPF, still Windows form. I'm sure people are doing that as well.
50:41
In Python, you can take Qt and this thing called PySide, or PyQ, depending on their sort of competing libraries. You can build something like RoboMongo, and it's cross-platform. Then you can use something called CxFreeze to package it as an EXE, or Py2App to package it as a .app file so it looks like a native app. Nobody would even know it's Python.
51:02
But you can also use WPF with Iron Python. You can even do MVVM with your Python classes. And you can also, on OS X, use Cocoa, PyOBJC, which plugs into the Cocoa APIs, okay? All right, so that's Python. It's a simple, readable language
51:22
that is very full-featured. We saw the parts of C Sharp that, or I think at least, are really important. Hopefully that largely intersected with your list. And we saw that, point by point, the Python ones are pretty comparable. Sometimes a little less good.
51:41
Fairly often, maybe even better. All right. So we even have a really nice debugger, IDE, and PyCharm, as well as the Python tools for Visual Studio. You saw I was using Visual Studio Community Edition, and the Python tools are free, so that's like 100% free
52:00
as long as you're running Windows, right? That's pretty cool. Also, I didn't mention before, we have Visual Studio Code. They now have a Python plug-in for Visual Studio Code as well, so if you want to do that on OS X, right? Okay, if you want to get the source code from this talk, you can go to my GitHub,
52:20
and if I just do a check-in through PyCharm, you will have it, all right? So github.com slash Mike C. Kennedy, and then you can just look at my repositories there. It should be near the top if you go soon, but it's python dash four dash dot net dash dev dash ndc dash oslo dash 2016. So much for conciseness, huh?
52:40
Oh, well. All right. So if you want to go deeper, and this is like really interesting to you, like I said, I have a podcast called Talk Python to Me, and I have some classes and stuff, online classes for these kind of things, but check out the podcast. I've got 62 episodes now, and got a lot of interviews with people.
53:00
Like, for example, I talked about Pidgin and the Microsoft guys with CLR, the dot net core stuff. I interviewed those guys for a while. I talked to Steve Dower, who did the Python Tools for Visual Studio. I talked to the guys at the Large Hadron Collider, how they use Python to help find the Higgs boson. Right, that was awesome. There's lots of really cool stories of what people are doing,
53:20
and they're mostly on the podcast, so check that out at talkpython.fm. All right, anything else? No, that's the end. Okay. All right, so do you guys have any questions? Anything you'd like to look at? No, this is kind of a separated group here. Yes, question.
53:42
How do you do the deployment? So the deployment story... So good question. How do you do the deployment? Well, basically, there's no compiling, right? So you can just copy the files, but you still... That's basically true until you get to the point where you have some kind of dependencies.
54:02
For example, if you're using, like, SQLAlchemy and a web framework, you have to also deploy those in all of their dependencies, which turns out to be many, many things. So let's take a quick look at how that might go. That is not what I was looking to press. There we go. All right, so you might start by having a project
54:25
you're going to work on, and you'd probably create what's called a virtual environment. So let's go... So I can say something like this. I can say, python3 run the module, venv into ndc deploy.
54:44
Let's just say ndc, okay? Wait a moment. You see now there's an ndc folder. All right, so there's this little activate thing. So let me just ask this question. Which Python would I get if I type Python?
55:02
It says you're going to get the system one, right? And like NuGet, I can say pip list. I kind of said three, so let's be like so. And this is like the NuGet CLI. So here's all the stuff I've got installed. Right, but what of these do I need to deploy, right? So this is not helpful.
55:20
So I can say dot activate and run this. And now if I say pip list, it actually just has this. And if I say, okay, well, which Python are we using? Not running this. So I've created like a copy of my runtime, as if you could like somehow copy the CLR
55:41
into like a little isolated thing. And then I would say something like pip install, what did I say, SQLAlchemy? Let me use, hey, okay. SQLAlchemy. So that's going to go and download it and then install it. And then I can say, okay, what's here?
56:01
This, all right, so you would do this probably on your deployment server. And you can actually create a file called requirements.txt that lists out all the things your app depends upon. You say install my requirements, activate this environment, and run. That works for the server. For desktop-type things,
56:20
you use something called cxfreeze or py2app to create an exe or a .app file that basically does this and stashes it internally. Does that help? Yeah. Other questions? Yes. Dependency injection, unit testing, mocking. No, yes, yes. Dependency injection, there is this concept,
56:42
but it is leveraged less because it's easier to just like stick stuff together. So there are dependency injection libraries on PyPI. People use them less. There are definitely mocking frameworks, and there are three or four good unit testing frameworks. There's one built into the base class library
57:02
called UnitTest, but probably the most popular one is something called PyTest. And, yeah, you can use them both. It's very JUnit style for the UnitTest style. You basically create a class. It derives from a test fixture, and then you name your methods test something,
57:21
and it runs them. You have assert methods like you have in JUnit. Async of async? Sorry? Async. Async, yeah, okay. So good question. That probably should have gone on my list, right? Async and await and the threading and stuff. As of Python 3.4,
57:42
I think we're on 3.5 now, Python 3.4, they added literally the keywords async and await. Now, that does not work exactly the same way as it does for C-Sharp. In C-Sharp, async and await work generally over all sorts of threading, and async and await work better,
58:03
well, let's rephrase this. Threading in Python generally works better when it's blocking I.O. When you're waiting on a database call, on a network call, web service call, something like that. Computationally, the parallelism in Python is not great. There's a module called
58:22
multi-threading or multi-process? I'm not sure. I think multi-process, where you multi-processing, where you basically fork other processes and run them in parallel instead of doing threading inside the app. Right, but they do have an async and await and it works well for blocking I.O.
58:43
I have one more minute. Any other questions? Sorry, you've got to be a little louder. This is really... What about the dynamic layer, sorry? How do you maintain large applications?
59:01
That's a good question. I would say unit testing is certainly part of it. One part is you can break... You saw how I did pip install SQLAlchemy. I could pay pip install requests. These are the external libraries. You can build your application
59:20
out of your own broken-down libraries like this and then you can state them as a dependency in your app. So some people do this. You can actually... I think you can do this with NuGet as well. You can host your own private PyPI server within your company, and so I could come over here and say, I don't know what it is, but...
59:46
I could give it another repo that has access to my private things and state those as requirements and then install them and things like that. So unit testing, packaging, isolation, things like that.
01:00:00
All right, looks like time is up. I'd be happy to answer more questions afterward, but I'll let you guys go. Thank you, everyone, for coming. Hope you enjoyed it.