It look very cool and fun to use, but I've always been of the persuasion of "if you think you should use a switch-case, you should probably refractor your code". I'm thus very in the fence
@@arturgasparyan2523 switch-cases mean your function decides between many different code paths, already something you'd preferably minimize per function. More so, those paths are not extensible without changing the function and it's difficult to test many paths. For the last reason (and readability), it's often already cleaner to move the code per case into a separate handler functions. An even cleaner method is to use a factory(-like) pattern where you have a map of functions/handlers where the key is the switch-case variable. Instead of a long switch-case statement, you now have a single line of "map[key](args, ...)" and some error-checking. The handlers can then be registered somewhere else. @Ian I know, but the reasoning kind of remains the same. Only for pattern matching, you'd have the guard in your handler itself and that guard would probably be uglier code than the elegant match-case
@@mCoding I followed Martin Odersky's Functional Programming class during my BSc, and your style kinda reminds me his MOOC videos which I greatly appreciated back then (we had both classroom and video teaching with him).
Sadly, type checking will still fail on functools dot partial, as typing dot ParamSpec and typing dot Concatenate* in Python 3.10 does not support variable number of replacements (like from a varargs argument to a wrapper function). Check PEP 612 You'll have to wait longer for that. ☹️ * have to use "dot" instead of "." as otherwise RUclips thinks I am trying to make a link and thus the anti-spam bot zaps it.
Language Creators in the 90's: "Dynamic is awesome & so easy. Lets make everything dynamic" Programmers nowadays: "who made this language sh*t dynamic. *Static types to the rescue"
I am relatively new to programming, but I think unless the code author names the variables in an obvious manner like number_of_chairs or interest_rate (which as I've noticed most people often don't), having static types is better than having dynamic types, because it makes it easier for the reader of the code to understand exactly what kinds of objects they are dealing with, which helps them avoid type-specific problems, such as the result of divisions being inaccurate or expecting one behavior from a container but getting a different one. Edit: Though I might just be more used to ALGOL-like C and Java, since in Python, you can often simply go to the declarations of arguments or variables to determine their type.
Great summary. I hate when I miss a good PEP. I almost missed the rise of pydantic for that reason, even though I had been trying to solve the same problem for years! In this case, I’m most excited for language features that improve our communication to the reader of our code. It gives confidence to us all when things feel the most deterministic. Even dynamic stack/pipeline analysis is deterministic, but it doesn’t FEEL that way because the rules are somewhat magick spells
@@Kitulous No they are not. There are advantages to strongly and statically typed languages, just as there are advantages to weakly and dynamically typed ones. And there are plenty of languages to pick from if you prefer the former. Just because you don't understand duck typing doesn't mean you suddenly get to declare the diametrical opposite of that as The One True Way (TM). It just means you don't understand duck typing.
Pattern matching in python? What's next, sum types? Those two are the features I miss the most when using python, though better scoping is very high on that list too
It's interesting how weakly typed languages like python, php and javscript are evolving more and more to be more strongly typed in the recent years. For javascript at the very least, typescript has become a game challenger, and no one wants to go back now
Python was always a strongly typed language. Strong typing is not the same as dynamic typing. But yeah, it's interesting how these languages are adding static typing features
This is what I'm referring to at 4:10 through 4:40. Python is dynamically typed, so it's impossible to refer to a type within the code that runs when you define type itself (this does not include the bodies of methods because methods they do not run at definition time of the class). Python allows you to use the string representation of the type name in place of the actual type name for this reason.
3.8 here, but yeah, I get what you mean. Not to mention all the already existing projects that now run on older versions of the language, framework, libraries, ... Just keeping up with the changes and keeping everything updated is becoming harder and harder. I'm starting to feel like languages and frameworks nowadays are targeted towards an audience that writes small applications that will only run for a short while, before being decommissioned or replaced with something new. Because by the time you're done building a somewhat large'ish project, your framework and libraries will be out of date, and you're looking at a couple days work to bring everything up to date and make it work again.
@@EvenTheDogAgrees program in C... program in C.. program in C manage your memory with malloc and freeeeeeeee don't sink your app with runtime bloat software in C will stay afloat no hot libraries everyday do all your work there close to the hardware program in C
I think devs should wait until Debian updates to use a Python version before releasing a version of a program that needs it. Debian is the slowest updating mainstream Linux distro, as far as I know.
As typing will be mandatory from python 4 and it is always a huge benifits, Can you please create a detailed video series on python typing, which also covers advanced typing as well beginner level typing? Your videos are so much informative. Awaiting your video series on typing. Regards.
Conversely, I never liked coming across a new function Foo(..) with unknown parameter types, only for my program to die at runtime because I passed in a dog, but Foo called Meow() on it, and there was sadly no hint of what was allowed.
I’m just learning programming and when I see Python's built-in asynchronous functionality (I had to google what a sync means) it makes me cry. I will never be able to learn all of this. I am self taught 😢
It just takes time and practice. Don't bother about asynchronous programming for now. Focus on fundamentals and you will be surprised how much can be done without diving into complicated stuff. I work with programmers who have been successfully using Python for years and yet they don't know about and/or use async or other Python nuances.
Every programmer is self taught, in fact everyone who has learned something is self taught. Take things slow, I have been doing programming since I was 8 or something and I am still learning. Don't believe people on stack overflow, nobody knows shit we are all experimenting. Async stuff is honestly really useful and easy. I don't know if this will helpful but I understand this stuff like this --> Think of async as having multiple people in at burger stand where they order go somewhere and when their order is ready you call them, you can sell to more customers with less resources and they will have to wait less. Now, think of people as functions, their requests are asynchronous and the when you call them don't forget to await to make sure their orders are ready. You might hear "event loop" and its complicated, but event loop is just the process in which you are serving -- like burger stand here could be a event loop. And, yes if you wanted you could have multiple burger stands, or sandwich stands or whatever. This will be useful when you will try to make your sync code, (( the old system where you took an order and made people wait there)) into new one without changing much.
@@mateusz7590 Yup definitely very true. I literally didn't know if some stuff could be done in Python until few years back. Runtime type and data validations.. and so much more I am oblivious about.
Am I the only one who's got the impression the Python steering committee (or whatever they're called) is desperately trying to catch up with other languages by adding useless and syntactically complex features, and in the process forgetting one of the core goals of Python: to be a language that is easy for humans to learn and read?
Much of the typing related stuff is due to a lot of pressure from companies. Duck typing without any static analysis becomes a nightmare once a codebase hits a certain size in terms of code size as well as number of developers (who all have varied skill and background). At that size, type hints become a huge win, and that's why we see large companies, who have a lot of influence on the council, pushing for these changes. The good news is that it's all optional, so developers can work perfectly contently without ever dealing with typing if they don't want to.
@@mCoding Thanks for the clarification. Hope what follows doesn't come across as combative, it's not my intention to shoot one of the various messengers or anything, just expressing my feelings... To me, though, that makes about as much sense as outfitting your crew with hammers. But not before forcing the manufacturer to change the blueprints so that it has a bitholder on the side. Because the projects you work on require the use of screws rather than nails. Why not just get some decent screwdrivers instead? They'll be a lot more ergonomical and reliable than a hammer with a bit holder welded on sideways. Don't even mind the type hinting, really, but this latest iteration seems to turn it into an unreadable syntactically charged mess a cat couldn't find her young in. And on the subject of "it's purely optional"... Yes, it is. In your own projects. But in team projects? As soon as one yokel on the team introduces this junk into the codebase, the rest of the team better learn how the hell it works if they want to make sense of the codebase. Anyway, as I said, thanks for the clarification. Gives me some insight into what goes into these decisions, and I appreciate you taking the time to elaborate on the subject. Take care, and thanks for all the work you put into these videos.
am i the only one who doesn't like python's type hints? in my opinion all they do in practice is make the code lengthy, ugly, and unreadable, oh and confusing as well. why did they introduce type hints to python? it used to be such a beautiful and concise language... don't make python into java
Compared to languages with strict type checking in the language itself and type inference to help keep the code succinct and readable (F#, SML, Ocaml, Rust, ...), Python gets it backward. In Python the human specifies all the types explicitly, and the Python interpreter doesn't enforce anything without extra tools.
Good video, though. I was hoping the news would be that the Python interpreter itself would start enforcing type consistency, so my disappointment is with the message, not the messenger!
I feel like they’re building to a strongly typed python 4 and I’m not here for it. I also wonder wtf this is. Debugger and docstrings were all I ever needed for typing python. It feels like they’re going “you can type it, but we won’t require it to artificially lower the barrier to entry”
@@fdwr because the markdown syntaxes used to do it are goofy looking yet still verbose, and have weird issues complying with linter and checkers, which are supposedly part of the value. Such clarification and typing notes were already being done in docstrings, which already had an ecosystem of goofy support. I don't see the upgrade over it besides arbitrarily declaring it to be the standard via PEP.
This channel is my only hope of staying up to date with recent Python updates. Fortunately it’s working.
*Me, preparing new in 3.11 videos already*
@@mCoding please keep up this awesome, good work.
@@mCoding you da man James Murphy
Structural Pattern Matching is definitely the highlight of this patch. Awaiting eagerly.
Can't wait!
It look very cool and fun to use, but I've always been of the persuasion of "if you think you should use a switch-case, you should probably refractor your code". I'm thus very in the fence
@@vinno97 But it isn't a switch-case statement. It is a pattern matching statement.
@@vinno97 why
@@arturgasparyan2523 switch-cases mean your function decides between many different code paths, already something you'd preferably minimize per function. More so, those paths are not extensible without changing the function and it's difficult to test many paths. For the last reason (and readability), it's often already cleaner to move the code per case into a separate handler functions.
An even cleaner method is to use a factory(-like) pattern where you have a map of functions/handlers where the key is the switch-case variable. Instead of a long switch-case statement, you now have a single line of "map[key](args, ...)" and some error-checking. The handlers can then be registered somewhere else.
@Ian I know, but the reasoning kind of remains the same. Only for pattern matching, you'd have the guard in your handler itself and that guard would probably be uglier code than the elegant match-case
I really appreciate your new audio. Your audio and video are great.
Yay, thank you!
The quality of your videos is truly something. I could watch this all day.
Wow, thanks!
@@mCoding I followed Martin Odersky's Functional Programming class during my BSc, and your style kinda reminds me his MOOC videos which I greatly appreciated back then (we had both classroom and video teaching with him).
I love these short and concise videos.
Glad to hear!
Being able to type higher order functions is definitely going to make my life much easier. *typed partial application here we go*
Do you have some references to examples?
Sadly, type checking will still fail on functools dot partial, as typing dot ParamSpec and typing dot Concatenate* in Python 3.10 does not support variable number of replacements (like from a varargs argument to a wrapper function). Check PEP 612
You'll have to wait longer for that. ☹️
* have to use "dot" instead of "." as otherwise RUclips thinks I am trying to make a link and thus the anti-spam bot zaps it.
The new typing features are indeed interesting. Thanks for the great video, James!
Thanks 😊
I’m loving this channel so much
Learn new things every video. Keep it coming
That's the plan!
I really love your content! thank you for making more!
Glad you like them!
Most of these type features are taken straight from typescript. Not that I mind, it's a good example and does a lot of things the right way.
Yes. I was thinking the same
Language Creators in the 90's: "Dynamic is awesome & so easy. Lets make everything dynamic"
Programmers nowadays: "who made this language sh*t dynamic. *Static types to the rescue"
I am relatively new to programming, but I think unless the code author names the variables in an obvious manner like number_of_chairs or interest_rate (which as I've noticed most people often don't), having static types is better than having dynamic types, because it makes it easier for the reader of the code to understand exactly what kinds of objects they are dealing with, which helps them avoid type-specific problems, such as the result of divisions being inaccurate or expecting one behavior from a container but getting a different one.
Edit: Though I might just be more used to ALGOL-like C and Java, since in Python, you can often simply go to the declarations of arguments or variables to determine their type.
4:35 can also use:
from __ future __ import annotations
edit: pretend that the underscores are not separated from the "future"
Great summary. I hate when I miss a good PEP. I almost missed the rise of pydantic for that reason, even though I had been trying to solve the same problem for years!
In this case, I’m most excited for language features that improve our communication to the reader of our code. It gives confidence to us all when things feel the most deterministic.
Even dynamic stack/pipeline analysis is deterministic, but it doesn’t FEEL that way because the rules are somewhat magick spells
Thanks; I never heard of PEP or pydantic.
It's going to be a joy learning TypeScript alongside Python with this feature
Another release like this one and you'll be able to unironically describe python as a member of the ML family. I love it!
My favorite kinda content from this channel 😌
Do you have any video on args and kwargs?
Oh Man, it's getting convoluted as hell.
but types are better than no types, hopefully even Python developers understand that
@@Kitulous No they are not. There are advantages to strongly and statically typed languages, just as there are advantages to weakly and dynamically typed ones. And there are plenty of languages to pick from if you prefer the former. Just because you don't understand duck typing doesn't mean you suddenly get to declare the diametrical opposite of that as The One True Way (TM). It just means you don't understand duck typing.
wow this ability to manipulate the stuff going on under the hood is really convincing me to start using python
Wait till you hear about decorators. That's were I entered the matrix
@@NabekenProG87 do python decorators do special things compared to how they work in other languages?
i no longer code python yet this is VERY entertaining for me
edit: ursina really got me back to python
Wonderful video, I love the new Python 3.10 release 😍, it's AWESOME!!!
It really is!
@@mCoding Yes, I love the new match statement and the new typing improvements 😍
Pattern matching in python? What's next, sum types?
Those two are the features I miss the most when using python, though better scoping is very high on that list too
One day maybe...
This is brilliant, I wish I understood how to effectively use any of this
Try it out!
It's interesting how weakly typed languages like python, php and javscript are evolving more and more to be more strongly typed in the recent years. For javascript at the very least, typescript has become a game challenger, and no one wants to go back now
while dynamic typing is good for prototyping, you really don't want to create big apps with it, because it's very prone to bugs
Python was always a strongly typed language. Strong typing is not the same as dynamic typing. But yeah, it's interesting how these languages are adding static typing features
Python is not a weakly typed language!
Thank you James
Thank you too!
As a C++ developer, I heartily welcome the typing improvements.
Why are we using type hints in Python in the first place?? These changes are throwing me for a loop
i had an issue where i couldn’t use an object as a return type inside it’s class definition, does anyone know if that’s intended behaviour?
This is what I'm referring to at 4:10 through 4:40. Python is dynamically typed, so it's impossible to refer to a type within the code that runs when you define type itself (this does not include the bodies of methods because methods they do not run at definition time of the class). Python allows you to use the string representation of the type name in place of the actual type name for this reason.
I'm convinced that Python 3.20 will be Rust.
That could be pretty cool.
This is not another April's fools right? 😂
Haha it's real this time!
I'm still using 3.7 waiting for a time to go through updating everything
3.8 here, but yeah, I get what you mean. Not to mention all the already existing projects that now run on older versions of the language, framework, libraries, ... Just keeping up with the changes and keeping everything updated is becoming harder and harder.
I'm starting to feel like languages and frameworks nowadays are targeted towards an audience that writes small applications that will only run for a short while, before being decommissioned or replaced with something new. Because by the time you're done building a somewhat large'ish project, your framework and libraries will be out of date, and you're looking at a couple days work to bring everything up to date and make it work again.
@@EvenTheDogAgrees program in C... program in C.. program in C manage your memory with malloc and freeeeeeeee don't sink your app with runtime bloat software in C will stay afloat no hot libraries everyday do all your work there close to the hardware program in C
How do you people like Python's new typing? Still seems weird to me, but most of my scripts / projects are pretty small.
I think it's great and really helps working on large codebases where you simply cannot know every single piece of code
Great!
py3.10s new typing hints look great
too bad LTS I code for is still on 3.8 ;-;
the struggle
meanwhile me and half the libs I use are 3.4-3.6
@@pogclippers4098 Wow, that's ancient. Even CentOS moved since then.
New syntax for union looks like Haskell ;-)
And here I was thinking I knew most of current Python by now...
Wait isn't 3.10 < 3.9 ?
en.wikipedia.org/wiki/Software_versioning CTRL+F for "Semantic versioning"
I'm waiting for the day py3.10 becomes common so I can use the new typehints for my projects, I hate having to type # type: ignore comments
We already have type hints
Your videos are great, topics are great, but sound quality can be improved!
Still no ++.
0:48 *My brain screeches to a halt*
Explicit type Aliases?
I think devs should wait until Debian updates to use a Python version before releasing a version of a program that needs it. Debian is the slowest updating mainstream Linux distro, as far as I know.
What better way to entice people to upgrade sooner than to have a cool library that actually uses new features? 😀
As typing will be mandatory from python 4 and it is always a huge benifits, Can you please create a detailed video series on python typing, which also covers advanced typing as well beginner level typing?
Your videos are so much informative.
Awaiting your video series on typing.
Regards.
what ? python 4 isn't confirmed, the devs said it might not even happen
this param types and typesvars are dope.
I understand the need to get better type checking but people are turning python into cpp
As long as it's not required!
god damn it i just got used to 3.9
4:29 yawn :D
:O
@@mCoding cool video btw, thank you!!
I never liked type hints... :\
Conversely, I never liked coming across a new function Foo(..) with unknown parameter types, only for my program to die at runtime because I passed in a dog, but Foo called Meow() on it, and there was sadly no hint of what was allowed.
@@fdwr Fair point, thank you so much! Greetings from Sweden!
I’m just learning programming and when I see Python's built-in asynchronous functionality (I had to google what a sync means) it makes me cry. I will never be able to learn all of this. I am self taught 😢
It just takes time and practice. Don't bother about asynchronous programming for now. Focus on fundamentals and you will be surprised how much can be done without diving into complicated stuff. I work with programmers who have been successfully using Python for years and yet they don't know about and/or use async or other Python nuances.
Every programmer is self taught, in fact everyone who has learned something is self taught. Take things slow, I have been doing programming since I was 8 or something and I am still learning. Don't believe people on stack overflow, nobody knows shit we are all experimenting.
Async stuff is honestly really useful and easy. I don't know if this will helpful but I understand this stuff like this --> Think of async as having multiple people in at burger stand where they order go somewhere and when their order is ready you call them, you can sell to more customers with less resources and they will have to wait less. Now, think of people as functions, their requests are asynchronous and the when you call them don't forget to await to make sure their orders are ready. You might hear "event loop" and its complicated, but event loop is just the process in which you are serving -- like burger stand here could be a event loop. And, yes if you wanted you could have multiple burger stands, or sandwich stands or whatever.
This will be useful when you will try to make your sync code, (( the old system where you took an order and made people wait there)) into new one without changing much.
@@mateusz7590 Yup definitely very true. I literally didn't know if some stuff could be done in Python until few years back. Runtime type and data validations.. and so much more I am oblivious about.
nice
Thanks
Am I the only one who's got the impression the Python steering committee (or whatever they're called) is desperately trying to catch up with other languages by adding useless and syntactically complex features, and in the process forgetting one of the core goals of Python: to be a language that is easy for humans to learn and read?
Much of the typing related stuff is due to a lot of pressure from companies. Duck typing without any static analysis becomes a nightmare once a codebase hits a certain size in terms of code size as well as number of developers (who all have varied skill and background). At that size, type hints become a huge win, and that's why we see large companies, who have a lot of influence on the council, pushing for these changes. The good news is that it's all optional, so developers can work perfectly contently without ever dealing with typing if they don't want to.
@@mCoding Thanks for the clarification. Hope what follows doesn't come across as combative, it's not my intention to shoot one of the various messengers or anything, just expressing my feelings...
To me, though, that makes about as much sense as outfitting your crew with hammers. But not before forcing the manufacturer to change the blueprints so that it has a bitholder on the side. Because the projects you work on require the use of screws rather than nails. Why not just get some decent screwdrivers instead? They'll be a lot more ergonomical and reliable than a hammer with a bit holder welded on sideways.
Don't even mind the type hinting, really, but this latest iteration seems to turn it into an unreadable syntactically charged mess a cat couldn't find her young in.
And on the subject of "it's purely optional"... Yes, it is. In your own projects. But in team projects? As soon as one yokel on the team introduces this junk into the codebase, the rest of the team better learn how the hell it works if they want to make sense of the codebase.
Anyway, as I said, thanks for the clarification. Gives me some insight into what goes into these decisions, and I appreciate you taking the time to elaborate on the subject. Take care, and thanks for all the work you put into these videos.
Help me
am i the only one who doesn't like python's type hints? in my opinion all they do in practice is make the code lengthy, ugly, and unreadable, oh and confusing as well. why did they introduce type hints to python? it used to be such a beautiful and concise language...
don't make python into java
Compared to languages with strict type checking in the language itself and type inference to help keep the code succinct and readable (F#, SML, Ocaml, Rust, ...), Python gets it backward. In Python the human specifies all the types explicitly, and the Python interpreter doesn't enforce anything without extra tools.
Good video, though. I was hoping the news would be that the Python interpreter itself would start enforcing type consistency, so my disappointment is with the message, not the messenger!
I feel like they’re building to a strongly typed python 4 and I’m not here for it.
I also wonder wtf this is. Debugger and docstrings were all I ever needed for typing python. It feels like they’re going “you can type it, but we won’t require it to artificially lower the barrier to entry”
How does clarifying the contract to a reader of your function on what kind of parameter is expected add confusion? If anything, it reduces confusion.
@@fdwr because the markdown syntaxes used to do it are goofy looking yet still verbose, and have weird issues complying with linter and checkers, which are supposedly part of the value. Such clarification and typing notes were already being done in docstrings, which already had an ecosystem of goofy support. I don't see the upgrade over it besides arbitrarily declaring it to be the standard via PEP.
Why such focus on types in python? If im not wrong python wont correct types
What an awful idea
IM FIRSt