Is This Language Replacing Python?!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you watch my videos then you know that I love python it's one of my favorite programming languages I use it all the time and I have literally hundreds of hours of content teaching it on this channel with that said though I'll be the first to admit that there's a lot of issues with python it's notoriously Slow It suffers from the global interpreter lock and that means that a lot of programmers start out learning Python and then move on to some more capable languages like C plus plus go rust Java Etc they might not want to do that they might love the syntax of python but they have to due to a lot of its limitations now fortunately for all of us python users there may be a solution coming very quickly called Mojo now Mojo is a new programming language designed by a company called modular it's not even available yet you can't even download the compiler but from what it's promising on its website in The Limited documentation that I've read it seems like it can be a great solution for anyone who wants to use Python but get the performance of a language like C C plus plus or rust in fact Mojo even claims to be 35 000 times faster than Python and if that's even remotely true then this is going to be a pretty big deal so with that said let's have a look at Mojo and just go through some of the features that it's promising after I share with you another really cool tool that's going to rapidly speed up your workflow which is the sponsor of this video Docker Docker is a suite of software development tools for creating sharing and running containers and can dramatically accelerate and simplify your workflow for millions of developers a Docker is the de facto standard to build and share containerized apps from the desktop to the cloud now fortunately it's got even easier to work with Docker with their new release of Docker init the new Docker init CLI generates assets for your projects making it even easier and faster to create Docker images and containers running Docker knit walks you through the entire creation of necessary files with sensible defaults these files include Docker file dot Docker ignore and dockercompose.yaml Docker in its simplifies project creation saves you time and effort and best of all is completely free now if you're like me and you value time and speed this tool is an absolute Game Changer and you can download it by just downloading the latest version of Docker desktop from the link in the description not to mention Docker is also running a giveaway where they're going to be giving away 50 sets of Docker swag all you have to do to enter that is join my Discord server at discord.gg twt that link will be in the description as well thanks again to Docker for sponsoring this video now let's get into it so let's start with what we know about Mojo first of all this is aiming to be a super set of python that means that all of the Python features you know and love eventually you'll be able to use directly inside of the Mojo language that also means that Mojo will provide additional features that you can use that should speed up the execution of your program and allow for things like strong type checking so think typescript for JavaScript that's kind of how Mojo is positioning itself except it's prom promising massive benefits in terms of speed so if I scroll through the website here Mojo is really focused on AI and systems level developers where what you need is actually raw performance you're trying to manipulate maybe memory or some lower level features that you don't typically have access to in Python and by doing that you're able to speed up the compilation and interpretation of your code so I'll just scroll through some of the main points that they have here first of all usability and programming write everything in one language so write python or scale all the way down to the metal program the multitude of low-level AI Hardware no C plus plus or Cuda required so it goes through a few of the different features it has here I'm sure to many of you this means nothing but for people that are low level developers that typically would have to write libraries in C plus plus Mojo can be a pretty big deal allowing you now to do this in Python and use these additional features to get closer to the metal continuing unlock python performance so utilize the full power of Hardware including multiple process course Vector units Etc so the basic example here pretty much illustrates this in your standard Python programming language you have a global interpreter lock meaning even if you have a multi-threaded application it's only going to run on one CPU core at a time really limiting its performance with Mojo that's not an issue you have access to multi-threaded and parallel processing which means you can actually run your different threads on multiple CPU cores at the same time continuing Mojo is promising up to 35 000 times faster execution times than native python obviously I can't verify this this is just what they have on the website and I'm sure this is only the case for very specific tasks however you get the idea here it's kind of giving the comparison with the different compilers languages Etc now one of the great things about Mojo at least again according to their website is that you will be able to import any existing python libraries or modules that means that anything you would have used in Python say like the numpy package you can just import directly inside of your mojo code and use it just like it was normal python going through here there's a bunch of other stuff that's kind of focused on AI I won't get into that right now and just as a reminder to you this is not currently available right you can't download the compiler and mess with it what you can do is go into this playground that I just got access to and kind of run your code in a Jupiter notebook which we'll do in just a second so we're going to dive into that notebook in a minute but I just want to give you a high level overview of some of the problems with python so python obviously has This Global interpreter lock what that really means is that if you have a multi-threaded program where you've split your program up into different pieces that can be executing independently since we have this lock only one of these threads can execute at a time now there's a way to get by that using something known as multi-processing but this becomes much more complicated and gives you all kinds of problems when it comes to accessing shared memory and resources that I don't want to dive into here so first of all Mojo essentially removes that Global interpreter lock with the compiler and interpreter that it uses again we don't need to dive into the weeds there the next problem with python is that although it does provide a lot of bindings for C and C plus plus code this means that if you want to write any performant application in Python what you're really doing is writing some C or C plus code building some kind of wrapper around that and then importing that or using that from python now this can make it extremely complicated to debug that code to find the errors that are occurring and just to write that code in the first place now all of a sudden you want to do something very performed in Python like systems programming and you need to go and become a c plus developer and then learn all of the intricacies between the different Python compilers and how you're going to actually be kind of injecting or importing this code into python very very high level overview it might not be entirely accurate but you get the point here if I want to do something performance now I'm outside of the Python ecosystem I'm learning something like C or C plus plus and that's probably not the best use of my time or something I really want to be doing if all I'm trying to do is just squeeze performance out of this language now there's various other problems with python as well a lot of them coming from how python code is compiled and interpreted and the fact that python is a dynamically typed language meaning there's a lot of inferences that cannot be made during the compilation phase of your python code which really reduces the performance so again Mojo is aiming to solve most of these problems with this new superset of python alright so I've just jumped into the Mojo playground here we'll have a look at some of the features that is promising and you can kind of see the advantages of this language by the way I'm not at all endorsing Mojo I've not been paid by them or contacted by them I just wanted to talk to you about this language and see what you guys thought so let me know in the comments down below so first of all a cool thing about Mojo is that the file extension for Mojo can actually be this fire Emoji you heard me right you can literally do like Pi or script Dot and then this fire Emoji or you can use dot Mojo So I thought that was kind of an interesting feature when you're going to be compiling or running your mojo code you use the Mojo compiler which doesn't yet exist where you're typing Mojo and then whatever the name is okay so going through here you can see that just like in regular python we can print hello world or in this case Hello Mojo and that's going to work entirely fine now the first feature that Mojo is adding here is something known as let and VAR declarations now if you're familiar with Java JavaScript Etc you may have seen these before they're actually not necessarily intuitive compared to something like JavaScript but they allow you to Define constants or immutable values as well as mutable values so if you use the let this is actually going to Define an immutable value and if you define a VAR this is going to be mutable so if we have a look down here you can see that if I Define my variable C using this let declaration it now is immutable meaning if I try to do this it's not going to work it's going to tell me this immutable and I can't change it so actually a useful feature that currently does not exist inside of python without using some pretty complicated classes and kind of properties and all these things that I'm not going to discuss so you can do that now you can also just Define a regular variable right so if I just say actually not a equals two let's go like x equals six this would be perfectly valid good I'm now just using the dynamically declared variable from python coming down here we have the ability to do things like late initialization which again we can't do in Python so I can initialize a variable to find the type of that variable this would be int this would be float64 float32 Etc and then later on I can initialize that value continuing go has structs now structs are similar to classes but they work a little bit different when it comes to Performance and the way that they are created and handled and if you're familiar with C plus plus or go you've probably seen these before now a struct is statically initialized which means that you cannot add instance methods or properties to it during run time so in Python if I create a class I can go ahead and add a property I can add an attribute I can add another method I can do all kinds of very weird and dynamic changes with structs I can't do that however in a lot of cases that's what you want and this allows the compiler to actually make a ton of inferences about the code which allows you during interpretation to speed up the code execution quite significantly essentially when you use a struct what you're doing is trading flexibility for performance and speed so if we go through here there's a bunch of kind of different features of the struct so first of all we need to declare all of the instance methods we want to have so I declare those as mutable values using VAR and I have to declare those right away so again I can't declare the string run time I have to declare them before or I guess during compile time now another cool features of our structs is just like in Python we can overload different methods so here I can overload my LT Which is less than and then Implement that less than operation on this struct type now notice here that we're using FN instead of Def now this is a new type of function that you can Define inside of Mojo that has some performance optimizations to it and allows you to define the different values or types of the different parameters that you have so in this case I'm using in out what that actually means is I have a mutable parameter here where I can modify what's being passed in there's another thing which is called Boro if I use Boro that allows me to Define this as an immutable parameter again we don't need to dive into it we can kind of see some of the flexibility that's being provided here continuing we also have strong type checking if you know what that is great if you don't I'm not going to explain all of that continuing we have overloaded functions and methods so this is actually quite cool and something that you can typically do in like C plus Java Etc but that you can't currently do in Python so here I've actually defined two versions of the init Constructor one version that takes an additional parameter here takes actually different parameters here R and I where this one only takes X that means that based on how I call the Constructor of this complex struct I'll actually enter into a different function or a different method here based on the one that I called so quite useful thing that's being added next we have these FN definitions which as we've kind of seen are new ways to Define functions that differ from def now first of all Def and FN are always interchangeable from an interface level that means that I can change a function to use FN or Def and that doesn't affect the behavior or the way in which I would call this function so if I'm viewing some function I don't need to know if it's defined with FN or def I just call it how I would call any other function that's good to know but there is a few important changes here or differences between the functions now I'm just going to actually read from my notes here because I don't want to mess this up so one of these changes is the following all values passed into a Mojo function use value semantics by default compared to python this is an important difference as a Mojo function receives a copy of all arguments it can modify those arguments inside of the function but those changes are not visible outside of the function that's the default with an FN function whereas in Python when you have a def function if I pass a mutable argument to the function I can mutate the value of that argument and it will be seen and affected outside of the function this is something I've talked about in quite a few videos and is a mistake that quite a lot of beginner python programmers make so in Mojo it disables that behavior by default and you have to explicitly enable that which allows you to avoid a lot of errors that you might typically have now that leads me into the last part of this video where I'm just going to quickly share with you my thoughts about this language so first of all this is extremely early if everything they're saying is true then this is really cool this is a powerful language I'm definitely going to check it out and I'd probably do a tutorial series on it however it's really too early for us to know I have no idea if this is going to live up to all of the expectations if this is going to be as good as it says it actually is and if this is going to be something that even really matters for your typical python developers it seems like they're really positioning themselves here for AI Developers for low-level programmers not for your typical Python devs and that might mean for you and me who don't do that every single day the Mojo isn't really something that we need to learn or something we need to be concerned about we can just keep going about our day using typical Python and not worry about this however maybe a lot of people will be using Mojo it'll become more popular and that'll be something that you kind of just expected to learn I have no idea but I just wanted to make this video to introduce this to you in case you haven't heard of it yet and give you the opportunity to check it out for yourself before it's released and before it becomes kind of a big hype thing which I think is a potential regardless I hope you guys enjoyed this video If You did leave a like subscribe to the channel and I will see you in the next one [Music] foreign
Info
Channel: Tech With Tim
Views: 106,346
Rating: undefined out of 5
Keywords: tech with tim, programming, python, mojo, modular, modular mojo, the best programming languages, coding, best coding languages, best coding language, programmer, mojo vs python, python v mojo, tim ruscia, why coding matters, coding languages, learn to code, learn about programming, best language for programming, programming languages, computer science, comparing mojo to python
Id: 21WFgScvrdg
Channel Id: undefined
Length: 14min 11sec (851 seconds)
Published: Wed May 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.