We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Rust for Python Developers

00:00

Formal Metadata

Title
Rust for Python Developers
Title of Series
Number of Parts
9
Author
Contributors
License
CC Attribution 4.0 International:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
"What programming language are you choosing for a new project? This talk wants to explore why we choose a programming language over another one. We will look at the languages Python and Rust to understand their strengths and weaknesses. Rust is a fairly new language and offers distinct advantages over most other programming languages when it comes to performance and security. There are however clear drawbacks. We will look at side by side comparisons of code and learn how much harder it is to write a lot of simple things in Rust." 00:00 Intro 00:05 Talk 46:27 Q&A About the speaker: Dave has been programming Python/JavaScript/TypeScript/Go at cloudscale.ch for the last seven years. He has created an Open Source autocompletion library called Jedi (420m downloads) that is available in most editors as well as IPython. To improve the performance in Jedi, Dave has spent the last two years rewriting Jedi in Rust.
TwitterDew pointDigital photographyBefehlsprozessorData storage deviceServer (computing)SpeicherkapazitätRead-only memoryPhysical systemFreewareInformation securityState transition systemSystem programmingVirtual machineElectronic meeting systemCodeService (economics)Video gameProgramming languageFirst-person shooterWhiteboardComputer programmingOpen sourceSoftwareBitText editorSemiconductor memoryProjective planeExpressionSpeicherbereinigungJava appletSystems engineeringPiComplete metric spaceRegulärer Ausdruck <Textverarbeitung>Line (geometry)Library (computing)Proof theorySlide rulePoint (geometry)Goodness of fitMultiplication signPointer (computer programming)Scaling (geometry)Point cloudDifferent (Kate Ryan album)BenchmarkMultilaterationTypsichere SpracheInformation securityArchaeological field surveyData managementIntrusion detection systemType theoryTwitterIntegrated development environmentUniverse (mathematics)Musical ensembleCuboidFigurate numberSoftware developerProgrammer (hardware)Enterprise architectureStructural loadSoftware bugJSONComputer animationXMLProgram flowchart
TwitterSummierbarkeitWorld Wide Web ConsortiumStatuteMetreMoistureProgramming languageSemiconductor memory2 (number)CASE <Informatik>Multiplication signType theoryString (computer science)Functional programmingNumberError messageMereologyBitEnumerated typeTelephone number mappingSoftware testingOverhead (computing)Goodness of fitProjective planeEnterprise architectureResultantComputer configurationData structureGeneric programmingMacro (computer science)System callPoint (geometry)PlastikkarteSet (mathematics)CodeLetterpress printingArithmetic meanMatching (graph theory)Statement (computer science)Line (geometry)Physical systemSocial classProcess (computing)Function (mathematics)DebuggerReal numberSoftwareException handlingFloating pointSummierbarkeitObject-oriented programmingComputer animation
EmailGamma functionPattern languageTwitterOptical disc driveError messageComa BerenicesRead-only memoryInterior (topology)Cheat <Computerspiel>Digital photographyProgramming languageCodePattern languageString (computer science)Multiplication signSoftware testingLetterpress printingFile format2 (number)Electronic mailing listPoint (geometry)Interactive televisionError messageInheritance (object-oriented programming)Pattern matchingInterface (computing)MereologyType theoryLibrary (computing)NP-hardResource allocationGeneric programmingAbstractionParameter (computer programming)Different (Kate Ryan album)CASE <Informatik>Macro (computer science)Pointer (computer programming)VarianceInvariant (mathematics)CuboidExpressionComputer configurationMatching (graph theory)PlastikkarteBitComputer programmingStatement (computer science)State of matterAsynchronous Transfer ModeReliefFunction (mathematics)outputCompilerJava appletJSON
TwitterCASE <Informatik>Streaming mediaOpen sourceMacro (computer science)Algebraic closureJava appletSoftware bugComplex (psychology)Shift operatorLibrary (computing)Interpreter (computing)Goodness of fitComplete metric spaceScaling (geometry)Self-organizationFitness functionToken ringTypinferenzVideo gameProcess (computing)Military baseShared memoryObservational studyMass2 (number)SoftwareMultiplication signCASE <Informatik>CodeNP-hardPlug-in (computing)Generic programmingLevel (video gaming)PiProgramming languageBitExterior algebraCompilerEnterprise architecturePrototypeAxiom of choiceText editorCovering spaceBefehlsprozessorDifferent (Kate Ryan album)LaptopSoftware testingJSONComputer animation
CASE <Informatik>TwitterDigital photographyRead-only memoryConjunctive normal formData storage deviceSpeicherkapazitätServer (computing)State transition systemPhysical systemComputer iconBefehlsprozessorSanitary sewerPermianRevision controlInformation securityPasswordResource allocationAtomic numberWechselseitiger AusschlussData typeCartesian coordinate systemAxiom of choiceProjective planeAlgorithmPhysical systemObservational studyMultiplication signType theoryCASE <Informatik>Programming languageSoftware testingCore dumpDebuggerPiMereologyAngleCode refactoringEnumerated typeSoftware bugSoftware developerGoodness of fitData structureGraph (mathematics)Endliche ModelltheorieBitFitness functionService (economics)Query languageException handlingSlide ruleAsynchronous Transfer ModeSpeicherbereinigungMoment (mathematics)Semiconductor memoryEstimatorSoftwareProcess (computing)Different (Kate Ryan album)Memory managementServer (computing)DatabaseMathematicsCuboid2 (number)CodeFood energyError messageOptical disc driveBefehlsprozessorBound stateJSON
State of matterMultiplication signMeta elementAveragePrototypeTransport Layer SecurityPoint (geometry)Java appletInformation securitySocial classCodeExtension (kinesiology)SoftwareDifferent (Kate Ryan album)Programming languageInteractive televisionPhysical systemType theoryDistribution (mathematics)BitRight angleProcess (computing)Moment (mathematics)WebsiteSpacetimeGoodness of fitSign (mathematics)Product (business)Level (video gaming)Complex (psychology)Software developerSystems engineeringBuffer overflow2 (number)Line (geometry)NumberPrice indexRevision controlOperating systemCategory of beingSupercomputerBinary codeAreaAxiom of choiceComputer fileCASE <Informatik>Hacker (term)Lecture/Conference
Fibonacci numberProgramming languageLine codePointer (computer programming)SpeicherschutzBasis <Mathematik>Complex (psychology)Level (video gaming)Enterprise architectureCodeRight angleModule (mathematics)SpacetimeCartesian coordinate systemComputer hardwareSocial classCore dumpKernel (computing)Military baseInterface (computing)Object-oriented programmingSemiconductor memoryCASE <Informatik>Java appletWritingExecution unitException handlingSoftware testingLine (geometry)MathematicsInformation securityMacro (computer science)Functional programmingPoint (geometry)Group actionThread (computing)MereologyReading (process)Software developerMultiplication signWhiteboardRun time (program lifecycle phase)Compilation albumSoftwareDifferent (Kate Ryan album)Power (physics)BitProjective planeMarginal distributionLibrary (computing)ReliefAsynchronous Transfer Mode2 (number)Lecture/Conference
Lecture/ConferenceJSON
Transcript: English(auto-generated)
So, hi, welcome also from me to Python Summit. I'm here to evangelize you all to the cult of Rust or maybe just talk a little bit about
it. I'm joking, of course, like there's a lot of good reasons to use different programming languages as well, like Python, but since this is the last Python Summit, I can pretty much say whatever I want. And also, since we're a bit early on time, I hope I get through it.
So I want to take you on a bit of a journey of my programming life. I've been programming for almost 20 years now and it's been a fun ride. I would say especially like the early years where I didn't program professionally have
been very fun because I got to do things like the Mandelbrot and like other fun things. I eventually wrote a video game. It did work.
It wasn't very pretty, but it wasn't an ego shooter with network capabilities. I then forgot all about network again and like I didn't know anymore what TCP was and UDP. And so a bit later, I started working at a company in PHP.
That's why there's no slides because I don't want to be proof that I work on PHP, but like I mean, at least Danilo is working in the back there, knows how horrible it really was.
And like my code base, especially like I think I had like a thousand lines of regular expressions that were then like put together in some ways and parsing something. Yeah, it wasn't good. No, but like then I studied and I started a project called Chedi and Chedi autocompletion
is something that you might be using or you might be using PyCharm. It's pretty much either of the two or it has been like nowadays there's also in VS code, there's kind of a different engine. I'll talk about that a bit later.
This was like 2012 and I've been doing this pretty much ever since, this is kind of an open source project. I then did like three years of like just open source work, basically I've had saved up some
money and like it was just kind of fun to do that. And as I said before, I kind of like doing things just because I like programming and so I just didn't work at that time. I then went to Afghanistan and I'm only telling you this because I needed some pretty pictures
to calm you down if there's like ugly rust stuff coming. And so during that time I would say I was pretty religious when it comes to languages. In life in general I was pretty like strong-minded but when it came to languages I thought like
Python was the greatest thing that's ever been invented and nowadays I'm like a bit more open-minded I guess. There's a lot of good languages out there, a lot of good reasons to use one over another. Then obviously at some point money started running out and I was able to get some money
for a Jedi from like companies but like it wasn't enough at all. So I joined a company called CloudScale. I'll mention this later a bit but in general this was, it's a Python Django shop with a
lot of React and Go or that's what I'm doing, we're not a Django shop, we're an infrastructure as a service company but I'm like the fifth best programmer there.
We're like four developers so go figure. Nobody, if you want to work with us in general just we also have system engineers and we have some network engineers. So feel free to contact me, we're always open to talk.
So why did I, why Rust, why did I think about that? Well for me like the main idea was to get like Jedi to a faster place because like if
you're typing in your IDE or your editor you want to get auto-completions in a really fast manner and like for some libraries like NumPy and others it was just not fast enough really or it's still not fast enough in my opinion. It's kind of it works but it's yeah it could be nicer and like Rust is considered in general
to be really fast like 10 to 100 times faster in like those micro benchmarks and I think this holds up pretty well for like larger programs as well because in other languages like Java where you have like a JIT or or go with the garbage collection like there's
issues that like stop you from getting that speed up at a certain scale but in Rust there's not really like Rust is just as fast as C basically and but like for the general world the reason why they use Rust is because it's fast and it's memory safe and for people who
don't know what that means is that like in in C if you write something you just have pointers and loads like those pointers can point anywhere and pretty much if you make a mistake as a programmer somewhere you will it will lead to memory bugs and that leads
to segmentation faults and other nasty things. In general you could also say Mozilla where that's where Rust comes from try to make this language because they had issues with in Firefox like a lot of a lot of the security bugs you
see out there are issues with unsafe unsafe programming languages and yeah so Rust doesn't have garbage collection and how it does that we'll see later. So in general the programming world loves Rust like you hear it everywhere this is also
because it has like like Python it has a democratic kind of community a good license a friendly community and Rust has a like a really nice package manager called cargo which is like
way better than tip which is way better than npm and so but like yeah and then there's these like surveys and everybody loves Rust and people don't love Python as much anymore I guess but this is mostly hype because Python is still like the primary language in universities
and like Rust is a language that's barely used by anyone in a professional environment it's mostly like people on GitHub and like missionaries so and I guess like people love
Python before they really used it and I think this is a general trend like people off Go before they used it and I kind of thought Go was a good language before I used it I don't like it or I think good reasons it's probably a good language for like big enterprise
companies and like stuff like Kubernetes with an insanely huge code base but not for like smaller projects which I like to work or like medium-sized projects which I like to work on and like even even like languages like TypeScript which to be fair is a pretty good language and
like has very nice features like those languages are also hype because nobody uses them or like like most most companies started using TypeScript but like all of the old code is still JavaScript generally speaking and then there's stuff like RipGrip which is like a really nice grip
replacement and so people just hype it up so but like what is Rust why why would you use it the Rust book describes it as a programming language that helps you write a faster more and more reliable software and I think this is mostly true like the Rust language it really like I kind of
covered the fast part but like the type system really enables you to write reliable software so but let's let's kind of dive into it I want to give you a quick overview over the language I'm
this is gonna be very broad there's lots of good tutorials out there so feel free to check those out this is just like a small introduction so as a first example I want to show you and a function
in Rust and Python that kind of looks the same in Python as you'll see there's like the the annotations I said there if you don't know those annotations as far as I know there's going to be talk about my Pylator so you'll be you will understand what what those are and but in general
like it kind of looks similar I had a few more examples that like I didn't make made it because of time reasons because I didn't have time like to show those but like there's like a lot of such small examples you can show where the languages look very very similar like there's braces there
but other than that it's like pretty much the same there's no return in Rust that's something special where you can just omit the return and like just write your code a bit more compact which is like generally a very great concept that you learn if you ever write code in it but though and
here kind of we get to the problem like this is this was the easy part and now we already get to the smart parts because there's no like there's a very small kind of set of the language that's very easy to use and that's also kind of you can write a lot of code with it but most code that
you'll see is not like that kind of easy so one of the great things about Rust is macros. Macros are those things where it looks like kind of like a function call but it has an exclamation mark
so for now just assume kind of those are functions but it's it's a macro it's kind of like like what you what you have in C but this is in Rust you have hygienic macros so there's a lot of advantages
over C and like it's a really nice concept in general and so some of those macros are like very simple like to do or unreachable which is like raise not implemented error in Python or the print ln macro which is like print in Python and then there's like fun stuff like debug which
is basically it lets you print the current line with the debug statement so eight times two and there's a plus one which like is just a a plus like it calculates eight times two plus one but
it will print eight times two and then equals four and in Python like you could also do this you could just do a print there but then you would just get four as an output and I think this is kind of nice to debug Rust sometimes especially if you don't use a debugger and you just won't have a quick output so that's really cool and there's other macros that are kind of cool and
it just enables you to like unlike a language like go for example that is very verb verb verb is you can just like write those small things which macros enables so those are like the simple
data structures of Rust there's really not more I would say and that's also kind of an easy part I would say and obviously I wouldn't type datetime exactly like that in a in a real use case but
like it does the job come on and so the the more in like a struct is basically like a C struct it's basically what you if you if you've ever programmed C it's what you would do there it kind of it kind of reminds you of a data class in Python but it has a more like it's just it's
very small in memory in Python the data class still has has a lot of overhead and then there's an enum in in Rust this is like I think like one of the most brilliant concepts it's not like Rust
invented this this is like very known in other languages as well like Swift has this as well and like I I don't know where they stole it but this is probably from the 90s or 80s somewhere and so an enum is basically you know you know enums in Python maybe so it can a value can be either a
num number a string or a null kind of like a JSON value and so if but in Python you couldn't attach a value to the number in Python it's just a number a string or a null and here it's a number and then
you have like kind of you know this number is a floating-point number and you get the number out of it and so this this kind of enum thinking enables a lot of stuff it like Rust has generics and so like these are like some of the generics you'll be using all the time it's option and
result option is basically either a null or in Python a none and in Rust as well and or a sum or something and so and this also kind of means because we have option result we just return a
result of something and this means that we don't have error like we don't have try catch or like that traditional object-oriented error handling and so maybe hands up who's using Python 3.10
already that's a that's few that's almost more than I expected so in Python 3.10 there's a new feature called match and match is something that rust also has and you'll see below that
how the syntax kind of is in Python you might be using it at some point in the future if you haven't already and in general in Rust it's kind of a bit nicer because the types like first of all
it lets you unpack enums and as you can see up there this is kind of the case where we have first we have a number we want to say and so we get that kind of value thing we say value
colon colon number and then we kind of get the number and return it or and this is like kind of the last thing this is like a wildcard match that also exists in Python by the way and or we just return none so we kind of have our option and then there's like a third thing there that I do there
and where I'm like printing it to do so why is a string coming here so this will eventually lead to a trace back and just like kind of nice to program this way and there's another like pattern
matching kind of piece of code that I wanted to show you that kind of shows why pattern matching is so nice this kind of thing also works in Python what what doesn't work in Python in Python you cannot return a felt like in Python it's an expression it's not a state in Python it's a statement of an expression so in Rust it's an it's an expression and you can return values from
inside that's why I didn't like the Python proposal very much though like I don't want to blame them because like Python just works very different as a language in very different ways as a language so that's kind of hard so what we do here is we just and we have a list of strings or values again of
those like JSON kind of type values and so the first example is just oh if it's empty just print print something then it's if it's like if the first value is a string and it's and the string
is hello and the second string is also is world then we say print hello world and then we say if there's two if there's just any two values we print we print them both values that's kind of
the syntax in print LM to like in Python you can kind of format strings as well this is also very similar or we have to do for all other cases and so this is kind of how pattern matching works if you don't know that kind of part don't worry but you can learn it for Python as well in the future
it's pretty nice and so let's get to the hard parts and here's here is where we take a deep breath and we kind of look at the more more annoying parts in Rust so the first thing that I
want to want to talk about is trait traits don't seem to be that hard it's basically an interface for anybody who's worked with like Java or C sharp or whatever and in Python there's kind of not
really like there are interfaces like it's abstract base classes but nobody really uses them so or maybe not nobody I don't want to offend you but you're probably the only person in the room and so in Rust like those look very simple at first but there's just so many things that you'll
stumble over like associated types or generics or like lifetimes with like invariant variances and there's it they are just hard and then one of the other things that are hard is creating macros
macros so if you say they have like like if you you we write the macro here say hello and then below we just executed a macro basically is like in C just a few commands that will get executed at
or like you can write pretty much anything there in print ln hello and it will get executed where the macro is like this is good if you don't want to like deal with inlining and stuff and you just
want to say here execute all this stuff and you don't have have to duplicate code but it's still pretty hard to write them I always have to look even though I wrote a lot of those macros I always have to look up the syntax like this part is pretty easy but there's like way more coming not
in this talk but like so there's lifetimes and ownership is really hard in Rust I think it's some of the hardest like concepts to grasp in general like this piece of code looks very simple it has
references which we haven't seen before and references always carry lifetimes usually like Rust is able to figure them out and like the compiler will say oh yeah this is fine you can do it but here because you have two references in the input Rust doesn't know what the output will be and like this will result in like this weird error and you're like oh what what should I do
but like Rust is pretty cool because and don't read the error but Rust will tell you oh yeah you should probably do this and most of the time it's correct it's just that if your code gets more complicated Rust will not be able to help you anymore but like error messages in Rust are
pretty good for simple things it's just that for complicated things they're horrible and like you'll want to kill yourself like sometimes I'm I'm just like four hours working on like why a lifetime is
not the way it should be and this is mostly because I work a lot with lifetimes when I program Rust but yeah it is what it is the correct example looks like this where you kind of have to specify a lifetime it's with an apostrophe and but this kind of starts to look a bit unlike Python
it's kind of annoying already and and I mean bit but this is really what Rust boils down to this is really what Rust is under the hood it always has those lifetimes it's just that most of the
time you don't really have to specify them if you only use like one lifetime and so and then you're like okay I want to understand Rust better I try to look at ownership and lifetimes and how they all interact and you land here and you're like what like this is this is just what like in Python
this is just how you pass a value around like how you pass a parameter around and but there's like different kinds of ownership with threats and allocations and then there's also libraries that have even different way so we don't know even look at this I just want I just want to I just
wanted to show you how complicated it is and again now we're going to the insane parts of Rust again Afghanistan a deep breath and because it's not gonna get better and for parts here I I don't
even have code examples because it's like it's hard to show like the madness in its full glory and in general I would say like and I think this is something that most Rust devs would say
avoid unsafe if I had time I would let you recite a prayer thou shall not use unsafe because unsafe makes like everything possible it's pretty much like you can just write C now you can like use pointers and whatever and and this is also part why the language is so powerful because you can
basically do anything but it's also really hard so I warned you and then there's like certain box and especially like around newer language features and like like this piece of code I don't think
anyone understands like in a quick way how what that is what it is basically just passing in
a closure and getting it out again and avoiding certain bugs and and this is like but this is what what Rust is at a very very high level like low level and it's just lifetimes and generics and
and hard to understand and this is just one of the bugs I created and I think I have like I've created like one or maybe two Python bugs in like 10 years and it was more in libraries and not in the compiler and here because the Rust compiler is so complex and can do so many things you'll just
see issues though I have to say if you use mypy which is also kind of a compiler for Python there's also like a ton of bugs and this kind of issue which is like around closures and lifetimes
enclosures also means that async is pretty hard because it works a lot with closures and so that's that kind of thing another thing I found was like trade lifetimes that bounds that are bugged we're not going to look into this but it's like it just showed me
that it's it's hard and then there's like kind of the fun stuff I just wanted to show you this because it's really insane that you could do this because this executes Python inside of Rust and this is probably not the best idea there's better way to ways to interact with Python in Rust
like there's really good libraries just fine tutorials about them but so this basically what it does is it has a Python interpreter inside of the macro and how it does that is kind of
complicated to explain but basically everything inside a macro is a token stream and you can execute that in an external process so inside of those braces you can do pretty much whatever
except that the syntax like the syntax tokens have to kind of resemble Rust or have to be Rust tokens which is crazy to be honest and like but since Rust and Python share like a lot of the tokens you can just write Python in it but this is I think it also
uses unstable Rust so and I'm definitely not recommending this I'm just showing it to you because you can do it so but this leads me to like talking about is Rust buggier than Python I personally don't think so it's just for like those like very kind of crazy features that most
people don't use I've like one of the organizers here Dennis works with me he has he has written some some Rust code that's pretty easy to understand it doesn't use lifetimes it doesn't use macros it doesn't use traits as far as I know so he's avoided pretty much all of what I just
showed you so you can write pretty simple and like very readable code in Rust it's just if your code base grows to a certain size it's kind of hard. Python and Rust to me feel very stable like most languages I've used except I think when I started writing some stuff in JavaScript like
like eight years ago like in Node it just would segfault but like that's the only time I've ever had issues with with languages in a big way so now I want to talk a bit about certain case studies and I it's mostly my experience this was my alarm clock this is when I normally get up
so this is kind of my experience and why I chose Rust and Python in certain cases and I mean to be
honest I couldn't choose Rust like 10 years ago because it just wasn't really a language at that time but now it is and I just want to talk about when to use which one and no none of those case studies is gonna cover the video game I wrote when I was like 18 years old because that was
that one is out of questions though then I also want to mention I'm not kind of in the enterprise world at all if you do enterprise software or anything like large scale kind of things shift
and suddenly like Go and Java become like kind of good languages because you can manage the complexity with a lot of devs in an organizational way and the code bases don't become like those huge messes that they can become if you're not cautious with Python and Rust so but let's in
let's get into it as a first case study I want to talk about Jedi and MyPy in Rust this is a kind of or Jedi in Rust sorry this is what I wrote like 10 years ago I have been working
on this for a long time it's probably like four to five many years now of my time it's it's an open source alternative to PyCharm it's there's plugins for all major editors and
I think VS Code has used it for a long time when they weren't able to to write their own stuff now they use a different kind of thing for it but it's called PyWrite by the way and that's pretty good but I'm rewriting Jedi in Rust now so that will be better and it's also used in
ipython and jupyter notebook so if you if you use that you I'm pretty sure you're you are using it and it's kind of pretty big and at the time when I started it just I just wanted to get it out as soon as possible and that's also why Python was a great choice because like Python is a great
prototyping languages language you can just get something done really quick the long tail is different there were a lot of issues I was like after three months I had an auto completion libraries and then I spent like eight years reworking and refactoring it but it's still
kind of amazing that you can like do kind of a complex piece of software in Python and just write that I don't think that would have been possible in Rust and if I if it took me like two years to have a first kind of user open source user I don't think I would have done it
so in general Python is however a bad fit for Jedi or anything that looks like uh looks like Jedi because like Jedi is a CPU bound
process like it it just has to parse things quick and has to use type inference and it's just it's just a bad fit Python is is good when when it's like IO bound problems in general so but it's that's kind of what I want to say here so if you want to get it out if you want
to ship it early it's kind of still good but it wasn't good for this case and that's what gets me into why I'm rewrite rewriting it I want to rewrite Jedi and my pi and Rust I'm like passing like a fifth of the my pi tests now and this is not that much it doesn't look that good but
um it will get better and it's really fast it's like 20 times faster than my pi at the moment in debug mode and if you use it in release mode I'm have I have like a 650 times speed up and
my pi is still kind of optimized so and that's that's like the tests are 650 times faster I don't think like the the whole thing will be 650 times faster it's probably more like 10 to 100 but that's still like good because if you run my pi over a code base and it takes you a minute
and now it takes you like five seconds that's like a huge difference and so that's my hope it's not finished it's not public but do not underestimate me I'll get there eventually it's been like two years now and it will take me at least like two or three more years
maybe and that's like software estimations so it'll take probably longer you all know what I'm talking about and then I um I want to have a third case study uh of the company I work at um which is we wrote our control panel to start servers
um in python and jango originally and then we kind of did a refactor and wrote the the front end in react which is like are both great choices I think for for what we're at um like people
sometimes say oh this is slow and maybe it's python and like it always turns out it's not really python because it's all io bound it's always the database it's queries that are slow and like it's yeah we're always limited by by our services because python is not that fast but it turns out for anything that's io bound um it's just it's just good and like latencies could be
a bit better probably without python it would probably not be like 120 milliseconds for a request but it would be 100 but who cares really and like if we have to scale it we just we can
just spin up another server so that's and that's like the cost of that is not that big and I'm very much a proponent of saving energy but yeah like spinning up a server is like a few watts because I'm not talking about like a I'm just talking about a few processes
and so and like one of the reasons why python was pretty much a great choice as well was because initially we had like three months to rewrite the whole thing in python it was written in lua before which is a very odd choice for for kind of a bigger project I think um but and I I would
probably choose rust now if I was there but that would probably be a bad idea because I I don't think I would get it done in three months in rust because in rust like you just write all those all that code and then there's like todos in there and it's yeah it's kind of
it's it's just I don't think it would be a good choice even though I would probably choose rust but that's more because I'm like I think python's a great language but I want to learn new stuff and it's more coming from that angle and not from oh rust would be a better fit
so yeah um now I want to summarize the whole thing um I want to say that rust in general is an extremely well-designed language with an extremely well-designed type
system one of the advantages rust has over a lot of other languages is they didn't go and make a language in like six days like javascript or even other languages that have been designed like by basically like python was designed by gido and like it's it's very well designed in a lot of
ways but rust had like the advantage that they iterated over a lot of this syntax and like core features and I think that's great and there's no garbage collection memory safety and performance
is all great we've talked about that I think one of the big pluses for me personally is that when I think in rust I think about data structures when I think in python I think about basically algorithms I think in general like good engineers should should think more about data structures
and less about algorithms because algorithms are just like the choose in between and data structures are how you should structure your application and python I think that and this is really what what I was talking about enums as well kind of makes that hard and I've always tried
to urge certain core devs to say to to introduce enums but I don't think that will happen in the near future so one of the things that's kind of neutral for me is that rust is very strict
that's kind of in a type system and it's very hard to test like smaller stuff this cannot be oh this is again the alarm clock I'm not kidding so rust is very strict and it's hard to test certain things if you just want to say oh yeah how about this and like in python you
would just like rewrite it a bit and like change the data structure and it might crash in some places but like you don't mind because you just you just want to test it and for like that one niche case and in the rust it's like oh you have 200 errors now and before you fix those you don't
get anywhere and at the same time you have those 200 errors and you know exactly where the issues are and in python you don't so that's just I guess an advantage and a disadvantage at times I think rust is very hard to read and learn which is clearly a disadvantage especially the hard to
read part I think it's it's kind of hard to read even if you're pretty good at it because there's so much you can do with it um lifetimes and ownerships I covered this lead to unproductive
days I think there's like at least 10 days where I haven't done anything except like debugging lifetimes in the last three months and but I also have to say I do like crazy lifetime stuff I do like lifetime bounds with dependencies and stuff so yeah the mental model needed for stack and heap
is pretty crazy yeah you you just kind of want to keep kind of this stuff in mind this is a cheat cheat I don't want to explain it now but like this is what I always did in the beginning there's
like the other cheat sheet that I showed you as well here so kind of memorized that stuff and I hope you'll be fine but it's not easy like it but at the same time we're all here to learn and like if you like software development like more complex stuff this is really fun
this is really fun it's just not the best business case all the time but I don't really care about business cases so yeah so this is I promise this is the last slide
in general pig raft for high performance CPU memory bound problems it's good for when you want to avoid bugs especially memory bugs and in general I think you should have a team of very capable devs if you don't I don't think you should be using it because you'll get nowhere
that's a good thing about rust you'll just get nowhere it's it won't be shit it's just you get you don't you won't ship software and you basically one of the advantages as well is you just get one binary and in python it's just a lot of dependencies and files that are
like like the python release process is pretty annoying python on the opposite hand is for data science AI it's an extremely good choice I think still rust doesn't isn't not anywhere in those
areas and I don't think it will be because most people that use data science are people that want to like hack something together quickly and that's just not what rust is I think and they don't want to understand a complex language that's also not why C++ didn't win at all in that kind of category
like high performance computing is a different kind of beast but yeah so for prototypes python's great if you have a team of average devs if you have like bad deaths it's I don't think python's a great language because there's like if you have like a lot of juniors and like people that don't
understand the language they'll do horrible things and they they'll use meta classes and like weird global state and I think at that point just use java and you'll be fine and I think like one of the big advantages of python as well is it's very hackable and deep debugable you can just
at any point like start pdpe or hack something together you can modify any global state which is a very big danger sign if you've ever if you ever do it but it's very valuable if you want to ship something and with really good in the rust case I mean like really good type system experience as
well not just a very capable dev in another language so I think this has been my talk are there maybe any questions I don't know if we do questions we can but and I want to say one
more thing since this is the last python summit I want to say a huge shout out to the people organizing this it's been a blast all these years it's kind of sad that it ends but it's also it's we we've had a good run I especially want to thank Danilo who started this thing I think
Dennis and Samuel for organized like for doing the huge amount of work and yeah maybe let's clap for them
thank you thank you Dave questions any questions we have a mic runner it's gonna get to you eventually it's right behind
thank you so a few years ago I tried to play a little bit with rust because all the security people seem to love it because it's a safe language and you avoid all those buffer overflows and stuff like that I tried to install it and there was no package for it
there was there was no package in in whatever distribution I was using at the time so I went to the rasp website and looked for the recommended way of installing rasp yeah and it's a car pipe bash yes and I was like those security people really love this
yeah I'm not a system engineer I'm an engineer so that's what system engineers hate I don't hate that I'm like used to it now no but you're right like this is pretty like it's obviously pretty bad but like I think it's where we are at the moment because rust is also pretty new and
I think once things stabilize we'll get better right that was the question I wanted to ask do you think it I hope it will get better but I also think like it's the same issue like I we are also in our company kind of in a process process of not always using upstream uh python
of like the operating system and like using docker instead because you can just use newer versions because we're on an older system and we're using python 3 3.6 and I would like to use the newer python features as well so it's kind of that issue as well thank you
are there questions since you did a chat in python and in rust now could you sort of give an indication of the number
of lines of code would it grow massively or stay more or less the same um that's interesting actually I think it's more or less the same it's probably a bit more in in rust but also because of the of the braces that you have so that just kind of creates a lot of space but it's not it's not
like a java or something where you have a lot of kind of dead code that doesn't do anything uh it's very expressive still but sometimes the kind of if I would say it's kind of the same if you do python with annotations because in python if you write annotations you also use
a bit more space and it's kind of at that level I would say thank you maybe be more but not it's it's not like I have a question back here and I have the mic so I can
ask it um here so um you said that you would recommend uh python for average devs and rust for experienced developers my experience is a bit different because if um if you have a complex code base and you write rust and it compiles you can kind of trust it if you have a python code that
that you can start it may might fail in a special way um so if the jedi is pretty complex so if someone does a contribution in python or in rust uh from someone that you don't know which one can you trust more yeah I mean I see the trap coming um well I mean I would say in general I don't
trust contributions anyway so it doesn't it doesn't really matter but like uh I think you have a point that you can trust rust contributions but I think I also have a point that in rust
it's kind of hard to ship a product with average or bad devs that have no experience in rust because they'll just get nowhere and in python I mean it might be buggy and it might be bad software and like but at least it will work somewhat and maybe it crashes from time to time but
people don't care it's software you know yeah there's one yeah so how easy is to use rust as an extension from python you showed the other way
around but it will be more interesting it's probably pretty easy I haven't used it personally that's why I didn't show it like what's definitely possible since rust works great with like interacts great with c you can just use cffi and just use kind of the c stuff but then there's also
is it called pi03 or pyodide I'm not sure it's like there's there's a pretty good way to interact with it I think but what like one of the issues is going to be that like python's reference counted
and rust has like lifetimes at its core so you'll have to structure your code kind of in that manner but you usually you'll just wrap rust objects and you write a small interface so that's very possible I don't think it's harder than c it's kind of the same difficulty
maybe maybe one more thing and I think that's also kind of a great application that I where I will see rust coming in as well like like libraries like numpy or scipy they're all written in c and like they could just be written in rust so I think that's kind of the way how the languages
will interact together so in recent years I've read a lot about both python and rust kind of pushing into the embedded space like I'd say arduino class hardware if I don't really know
either one of them for embedded development do you have like a suggestion with which one to start or is is there like a clear winner or I would say there's a clear winner there and that's that's rust and not for for the reason that I don't like python there but the issue is that
like python needs a runtime and you cannot compile python and so like python will be running on like certain boards but not on all boards and rust will run on pretty much anything that he runs on
it just sometimes it's kind of annoying to get to work to get it to work but like and then but I mean if you use it like most of those projects are like for fun anyway so just use whatever you like like it doesn't really matter but like rust is the winner in cent in the sense of it will be
part of the industry python really I don't think python will be part of the industry in that space there's a lot of power and like it's just too slow and too memory hungry yeah there's one more there
okay so actually no question but the comment to this question how easy it is to um interface with python so I have a little bit experience with this py03 thingy yeah and um so as you said it's it's very easy in some cases you even have a macro where you just can turn
um a rust function directly into a python function inside the module okay so that sounds like it's great it's really great in my in my experience um okay that to that then before there
was another question about the security so I'd say rust is not a secure language it is a memory secure safe and thread safe language but it suffers all the other risks other programming languages have as well but um with respect to this I read that um I think one month ago
the rust foundation got funding for a security group so they're really addressing this issue now well I don't know anything about this particular case I don't really follow
rough the language in like I follow the the release notes but I don't like read that kind of news I would just say like when you say rust is not a secure language I would I would kind of counter that with yes it's memory secure and obviously
that's kind of part of it but it's also more secure than a lot of other languages because it doesn't suffer certain problems like null pointer exceptions or um um this is not my alarm clock
yeah I mean but also null pointer is memory so this is oh no exceptions I mean like like like uh like in python where it it is memory safe but it will just fail at a random point and like or it will kind of inject the weird well value that you in java you can just push a non
like a null somewhere and it's still memory safe but like it can lead to weird behaviors and yeah good one more question
thank you um when you mentioned that rust might be harder to to test compared to python I guess you won't agree but does that mean that it's less appropriate for bigger code bases where you might need to rely more on unit tests what what did you like I'm not sure you
like I I know what you're referring to can you maybe clarify that like well you mentioned that it's harder to test I haven't worked with rust oh with like I don't I don't think it's harder to test in an automated sense it's it's not it's not hard like you can write tests and it's it's
great like cargo is great for testing and everything it's just that uh if you want to like try something and like just like change this line of code and like see what it does that kind of stuff is like kind of annoying rust okay yeah got it yeah
okay if I may ask one last question yeah um then um continue on that topic I've heard recently a lot of talk about um linux kernel modules being written in rust yeah right so it's going towards like the more larger complex code bases and you also mentioned they're like hey like maybe when
you get to enterprise level large code bases and so on it can get complicated to organize code how do you see that future going well I mean like it's I think the kernel is a bit different than enterprise level software because it's kind of different people doing that kind of stuff and
I think kernel devs are like usually like the most capable dev so they'll find a way in general one thing I didn't mention is compile times compile times are like kind of okay I guess in rust but they're nowhere near go or whatever or see um and so there's good incremental
compilation so you can work with it I as a dev I don't have really I don't have issues but um like I think if you have like a million line code base and especially if it's just one crate which is like the package that's where things I think will start to slow down
and you'll have compile times of like a minute or even higher whereas in C or C++ it's just better or like language is like go like go is a good example in go the compile time will probably like be 10 times or 20 times faster and that's just something it might not be 10 times but like
it will be faster by a significant margin and for for devs that's just very nice one thing I didn't mention is like what's what's cool about rust though especially compared to python tests
will run really quick so I will compile like especially in relief mode I will I will run like a thousand tests in like 0.1 seconds and but it will like compile for like five seconds so it's like as fast as python at that time at that point but I can I can run all the time all the
tests all the time which I usually don't do I use pytest and then I I run like five tests or one test and that's it yeah okay thank you thank you very much Dave thank you