Python 3.12 is HERE!

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ • 287

  • @NotAUtubeCeleb
    @NotAUtubeCeleb Рік тому +598

    The comprehension change is a 10/10. Literally no change to your code required but comprehensions become twice as fast.

    • @LambOfDemyelination
      @LambOfDemyelination Рік тому +26

      twice?

    • @BrianWoodruff-Jr
      @BrianWoodruff-Jr Рік тому +94

      Looking forward to my coworkers comprehending twice as fast!

    • @ianliu88
      @ianliu88 Рік тому +2

      I guess this also allows comprehensions to be evaluated in pdb session? Dunno, must test

    • @nigh_anxiety
      @nigh_anxiety Рік тому +4

      Haven't checked it yet, but does this also mean that a list comprehension for a class variable can now reference are pre-defined class variables? Previously it would fail as class definitions are not an enclosing scope.

  • @Konomi_io
    @Konomi_io Рік тому +37

    the f string change is so helpful, ive run into that one quite a few times

    • @王沛升
      @王沛升 Рік тому +6

      I usually use f"""{"somthing"}"""" if the double quote cannot be avoided.
      But usually f"{' something '}" would get the job done.
      Also use f"{{ {something} }}" when dealing with some command prompt requires {} as parameters.

    • @NoNameAtAll2
      @NoNameAtAll2 Рік тому

      you've run into using quotes inside quotes and deciding not to escape them?

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Рік тому +25

    6:30 Just a note that, as with any function, generation of the code happens only once, at compile time, but creation of the function _object_ (ref to code + environment binding) happens every time that statement is executed.

  • @jamesflames6987
    @jamesflames6987 Рік тому +108

    Great to see Python taking some inspiration from C++ such as typing and incomprehensible syntax.

    • @headlikeahole6548
      @headlikeahole6548 Рік тому +14

      Types in C++ affect your programs, in python they are just for IDE hints.

    • @jamesflames6987
      @jamesflames6987 Рік тому +48

      @@headlikeahole6548All of the complexity, none of the functionality.

    • @tuberroot1112
      @tuberroot1112 Рік тому

      @@headlikeahole6548 " in python they are just for IDE hints." Even hints would be better than the instanity of gender fluid variables and non binary booleans !!! Python is a mess on every level.

    • @nagoranerides3150
      @nagoranerides3150 Рік тому

      @@jamesflames6987 But they've really internalised the lesson from C++ that you can say you're OO without having to actually enforce it, so you can still have functions floating around any old place and of course none of the flow-control is OO at all. But, you know - whitespace!

    • @squarerootof2
      @squarerootof2 Рік тому +2

      @@jamesflames6987 LOL,🤣

  • @rx97_mc
    @rx97_mc Рік тому +33

    I think with `kwargs`, it's not that having the same type for each `kwarg` is a natural solution but it's more like it's consistent with the typing of `args` where it *does* make more sense to have the same type for each arg.

  • @con-f-use
    @con-f-use Рік тому +6

    1:52 and it used to be that you coudln't use backslashes in f-strings. Which bit a lot of people in the backside.

  • @Kruglord
    @Kruglord Рік тому +13

    11:51 There's exactly one problem with `itertools.batched`, it's passed tense. All the other itertools are present tense, i.e. `groupby` rather than `groupedby`.

    • @negativeseven
      @negativeseven Рік тому +9

      I read it as an adjective, rather than a verb. Like functools.partial.

    • @simp-
      @simp- Рік тому +2

      never thought of that before, but It's pretty much same as in build-in python functions sorted() and reversed(). I mean we have ex. not mapped() but map(); not enumerated() but enumerate() tho I have never see anyone complain about it, even tho it's kinda not consistent

    • @piaIy
      @piaIy Рік тому +2

      ​@@simp- Sorted and reversed are different, they suggest that the collection is not modified in place, but a copy/iterator is returned, whereas you can't really map or enumerate in place. As for batched, I think they chose that name because batch can also be interpreted as a singular noun. Kotlin also uses the name chunked for a similar method, and their naming conventions are pretty consistent.

    • @simp-
      @simp- Рік тому +1

      @@piaIy oh, okey I get it, thanks a lot

  • @SuperGrimmy
    @SuperGrimmy Рік тому +232

    As someone who maintains a lot of packages.. 3.7 disappearing is definitely the best. Can we fast track it to 3.10? :D

    • @nigeltan7766
      @nigeltan7766 Рік тому +7

      is python 3.7 bad? im no expert but am curious so pls elaborate

    • @sid6645
      @sid6645 Рік тому +3

      Losing 3.8 might be bad because of nvidia, as someone pointed out below.

    • @SuperGrimmy
      @SuperGrimmy Рік тому

      @@nigeltan7766 It would be "bad" to use it now since that version is no longer getting any updates including security fixes. Newer versions have the new language features and much better performance anyway.

    • @SuperGrimmy
      @SuperGrimmy Рік тому

      @@sid6645 yes, I the real world it would definitely be premature to fast track deprecation. It's just something some python package maintaners dream about because it can greatly reduce their work.

    • @aintaintaword666
      @aintaintaword666 Рік тому +4

      And I'm still using 3.6 for an old custom-build tensorflow version that was specifically compiled to run on an ancient GPU

  • @rursus8354
    @rursus8354 9 місяців тому

    10:26: C++ typing is a good thing! Typing has the two purposes of 1. helping the programmer catch errors, 2. creating an efficient compiler producing lightning fast machine code (if the programmer chooses to). If the answer on purpose 2. is "use another language" then Python isn't that language.

  • @codegeek98
    @codegeek98 Рік тому +1

    2:05 spooky, I literally just got bit by that this morning; I had no idea that's being/been addressed

  • @wChris_
    @wChris_ Рік тому +77

    im already excited for python pi (or just python 3.14) as it is now very very close

    • @Liam3851
      @Liam3851 Рік тому +25

      Ever since python 2 went out with python e (2.7.18), I've been thinking it would be aesthetically pleasing for the python 3 line to end with 3.14.15. Perhaps if GIL removal by default gets released as Python 4...

    • @obed818
      @obed818 Рік тому

      @@Liam3851cant wait for it’s end really..

    • @matthias916
      @matthias916 Рік тому +7

      pithon

    • @jan-lukas
      @jan-lukas Рік тому +2

      Did python 1 stop with 1.414?

    • @Liam3851
      @Liam3851 Рік тому +9

      @@jan-lukas 1.6.1. Golden ratio!

  • @Ballrock30
    @Ballrock30 Рік тому +5

    Hi James,
    if you are gathering points for a new "Nooby Python habits" video, I might have one. Not sure if I missed it in the list or it is just so stupid that you did not think about it. In most of my codes I initialized instance attributes as class attributes instead of initializing them in the __init__() method. Mainly to make the code shorter and more readable. I mean, sure... Those are shared by all instances of a class, but if they are immutable objects they work like instance attributes. I realized my very stupid nooby habit when I created mutable objects (list and dict in my case) which is then shared between all instances. I think for newcomer this behavior is not quite obvious and can lead to silent misbehavior. I thought it is worth mentioning.
    Thank you for your great videos. Even considering the statement above, I'd say they made me a quite good Python dev :)

  • @Terra_135
    @Terra_135 Рік тому +1

    10:15 PUBLIC STATIC VOID MAIN STRING ARGS 🗣‼

  • @stonemannerie
    @stonemannerie Рік тому +57

    As an NVIDIA Jetson which shipped Ubuntu 20.04 (i.e. python38) and lots of proprietary NVIDIA libraries which only have python binding for 3.8, I start sweating at the thought of 3.8 being dropped next year.

    • @cleverclover7
      @cleverclover7 Рік тому

      you're not alone

    • @volbla
      @volbla Рік тому +1

      Let's update them 🙂

    • @Squeemos
      @Squeemos Рік тому

      I know exactly what you mean. As much as I love the new features of updates to python I get really worried the closer 3.8 gets to being dropped haha. Too many things would stop working for me :(

    • @SuperGrimmy
      @SuperGrimmy Рік тому +1

      You'd probably be fine for a couple more years until 2025 when ubuntu 20.04 LTS standard security maintenance also runs out. Probably Nvidia calculated it based on that. That's definitely within reason. Most consider a newly deprecated python version to have year or two more in them in enviroments like that.

    • @tuberroot1112
      @tuberroot1112 Рік тому +1

      @@volbla "Let's update them ". Let us .... ? That will be you and who else picking up the burden of the massive work load imposed by the lamers at Python constantly doing non compatible "upgrades" and breaking everything in sight?

  • @cougar2013
    @cougar2013 Рік тому +19

    Please let the 3.14 release be called “Pi-thon” 😂

  • @Danyaaaaaaaaaaaaaaaaaa
    @Danyaaaaaaaaaaaaaaaaaa Рік тому +18

    The new generic type syntax is sooo welcome

  • @southernsunreviews5932
    @southernsunreviews5932 6 місяців тому

    On types or dictionary question you asked about. In c# we have enums that you r able to cast the value or str. And values could change depending on what the enum is used for. Then you want to use kwargs because you don't know how the structure changed. Like in reflection scenarios. Thanks great update
    And you explanation about square and override is a nice explanation of polytechnic methods if they were wondering how polymorphism relate back to real life scenarios instead of foo

  • @danmar007
    @danmar007 Рік тому

    Finally!!! I've been waiting for this to start learning Python.

  • @sethdhanson
    @sethdhanson Рік тому

    Been waiting for a 3.12 take from mCoding. Awesome!

  • @nocturnomedieval
    @nocturnomedieval Рік тому +20

    Would like to hear more about your other preferred utils. How is batched implemented over an unindexed object, does it cast to a list or uses a generator ?

    • @pranavbhamidipati8609
      @pranavbhamidipati8609 Рік тому +1

      Generator. Unlike batched_even which needs the iterator length, batched does not

  • @Tomyb15
    @Tomyb15 Рік тому +13

    The buffer protocol is nice. Many times I've come across functions in the standard library that say they work with anything that implements the buffer protocol, when it's C api only and only bytes and bytearray implement it.
    Not that useful but kinda nice.

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Рік тому +11

    10:14 That would need a “@final” decorator on the base class method. No doubt that will be coming ...

    • @peco_17
      @peco_17 Рік тому +2

      Actually, @final is already in the `typing` module since python 3.8 ;)

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 Рік тому +3

      @@peco_17 Ha!

  • @foobar8894
    @foobar8894 Рік тому +35

    Only two more to go until we can start calling it πthon...

  • @cleverclover7
    @cleverclover7 Рік тому +25

    8/10 video. im gonna start using itertools batched. f string stuff was annoying having to use different quotes, etc. kinda wish single-quotes in python weren't a thing.

    • @michaelflynn6952
      @michaelflynn6952 Рік тому +11

      I just wish they did something different than double quotes, feels like wasted opportunity to make two characters do the same thing

    • @RokeJulianLockhart.s13ouq
      @RokeJulianLockhart.s13ouq Рік тому

      ​@@michaelflynn6952Yeah. Almost every other scripting language has different handling for the two characters.

  • @calum.macleod
    @calum.macleod Рік тому +10

    "and python 3.8 has a year to go so I can start pushing clients to upgrade to 3.9" :D

  • @volbla
    @volbla Рік тому +2

    I also have had to write my own batched function. Since itertools has pairwise you might think it should also have an n-wise, but not so until now.

  • @notplancha131
    @notplancha131 Рік тому

    0:47 is (float, int) here mean that T will be a tuple, or will it be either a float or int?

  • @NithinJune
    @NithinJune Рік тому

    Love this form of video with the ratings! Very engaging...

  • @thomasbates9189
    @thomasbates9189 Рік тому +1

    How did you learn about all the python language features you currently know how to use and what motivated you to learn them? Many times I watch your videos and I see you use something that I wasn't aware of before like __slots__ and other items like that.

  • @trag1czny
    @trag1czny Рік тому +2

    Great vid as always 🎉

    • @bswck
      @bswck Рік тому

      discord gang 🤙

  • @hglbrg
    @hglbrg Рік тому

    Finally a youtuber who knows how to pronounce et cetera properly. You deserve a like just for that.

  • @tomasbernardo5972
    @tomasbernardo5972 Рік тому +1

    Can't wait for python 3.14, python π

  • @Creadeyh
    @Creadeyh Рік тому +4

    Is the debugger improvement applied to the integrated vscode debugger or do you have to use the sys.monitoring yourself ?
    Sorry I don't really know how debuggers work internally

  • @IterativeTheoryRocks
    @IterativeTheoryRocks Рік тому

    Marvellous. Loved it.

  • @l3gacyb3ta21
    @l3gacyb3ta21 Рік тому +1

    woa! I love the static typing stuff

  • @norude
    @norude Рік тому +8

    Static type gang here
    👇

  • @joshuaraciti
    @joshuaraciti Рік тому

    Can’t wait for Py 3.14

  • @prawnydagrate
    @prawnydagrate Рік тому

    man you are literally the best python programmer i've ever seen

  • @plagosus
    @plagosus Рік тому

    I'll be waiting for 3.14

  • @bearwolffish
    @bearwolffish Рік тому

    wonderful update

  • @sehaless
    @sehaless Рік тому +2

    Not that I have a use case for it, but I am curious. How do immortal objects actually work? Is there a way from within python to mark an object as immortal or is that fully up to the C implementation to handle - so only code that is partially C can benefit from it atm?

  • @recoder706
    @recoder706 Рік тому +1

    Looking forward to 3.14 version. I hope they gonna call it Pi-thon

  • @LambdaCreates
    @LambdaCreates 6 місяців тому +1

    Python 3.14 will be the Pi update.

  • @sabihass5361
    @sabihass5361 Рік тому

    Thank you!

  • @nikhildaram3354
    @nikhildaram3354 Рік тому +1

    Streamlit is not available in python 3.12

  • @curtmcd
    @curtmcd Рік тому +1

    Good stuff. Generics have come a long way. Now we need currying.
    Nits: is that min_max generic at 0:13 supposed to return triples? And at 0:49 shouldn't it return self.seq[item] or something?

    • @FrederikSchumacher
      @FrederikSchumacher Рік тому

      Currying has long been in Python: functools.partial or functools.lru_cache

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 Рік тому

      We already have function factories and class factories. What more do you need?

  • @bswck
    @bswck Рік тому +2

    one of the best updates ever

  • @rasputunga
    @rasputunga Рік тому

    `batched` function is GOAT

  • @betterinbooks
    @betterinbooks Рік тому

    new way of creating types is a huge change.

  • @MrAlanCristhian
    @MrAlanCristhian Рік тому +1

    Override is my favorite. I love it.

  • @wizpig64
    @wizpig64 Рік тому

    Love your music by the way

  • @Vivraan
    @Vivraan Рік тому +1

    10:25 you forgot noexcept(noexcept(L)) lol

  • @georgplaz
    @georgplaz Рік тому +4

    as someone who learned programming with java, the new generics make me so happy 😊

    • @gautam-narula
      @gautam-narula Рік тому

      Getting ready for the next billionaire to be someone who made “don’t Java my Python” bumper stickers

  • @my_master55
    @my_master55 Рік тому +1

    My crazy mind though mathematicians just dropped a new Pi value 😭😂

  • @SniperMayer
    @SniperMayer Рік тому +1

    I really hope 3.14 will be named Pithon

  • @maxgtheone
    @maxgtheone Рік тому

    Missed a great opportunity to put the Twitter logo at 9:00 haha

  • @k98killer
    @k98killer Рік тому

    I don't get why you would type hint kwargs that way instead of just type hinting the named kwargs after the "/, *," in the function signature, e.g. "def thing(self, /, *, kwarg1: int, kwarg2: str)"

  • @JellyFoxYT
    @JellyFoxYT Рік тому

    I don't really understand the type params section. Can someone explain it?

  • @felixfourcolor
    @felixfourcolor Рік тому +4

    The generic typing is the best!
    I'm disappointed of the performance though. 3.11 vs 3.10 was a clear upgrade, while 3.12 barely changes, some programs run even slower.

  • @_-_--_
    @_-_--_ Рік тому

    great video. thank you

  • @danielgysi5729
    @danielgysi5729 Рік тому +19

    I can't decide if a smaller update like this with less new syntax is refreshing or boring

  • @CppExpedition
    @CppExpedition Рік тому

    Best reviewer 🎉 :)

  • @seifenspender
    @seifenspender Рік тому

    These changes all sound amazing.

  • @lollol-ih7pb
    @lollol-ih7pb Рік тому

    Hey question how do u get this app like the same ui and stuff because i have to use windows terminal

  • @Jeyekomon
    @Jeyekomon Рік тому

    It would be awesome if you made a video about generic functions!

  • @carnap355
    @carnap355 Рік тому

    What's "type variable"?

  • @hellohabibi1
    @hellohabibi1 Рік тому +1

    They are basically copying TypeScript and changing the design a bit.

  • @fieldtm1able
    @fieldtm1able Рік тому

    When can we get 3.14thon?

  • @mattlau04
    @mattlau04 Рік тому +2

    I was waiting for release really patiently, the new type syntax and f-string syntax are such amazing changes

  • @MephistoDerPudel
    @MephistoDerPudel Рік тому

    Immortal objects may be useless to most projects, but for those, for which it is a problem, it may resolve a bit PITA.

  • @BosonCollider
    @BosonCollider Рік тому +1

    Immortal objects would be a no-op in pypy. Refcounting is just inherently ugly if you care about performance at all. I wish that python3 had just dropped refcounting and used a proper GC in python.

  • @NoNameAtAll2
    @NoNameAtAll2 Рік тому

    2:03 I don't understand, what's wrong with that?
    if you want to use same quotes, you have to escape them - seems very reasonable
    why was this changed?
    it feels more confuaing now that before

  • @dailynarative
    @dailynarative Рік тому

    im strugle to find pyaudio for this version of python3.12

  • @avasam06
    @avasam06 Рік тому

    You mentionned setuptools. But not that *distutils* is completely removed from 3.12!
    setuptool still monkey-patches in its special vendored version. But that means if you never imported setuptools, then imports of distutils will fail.

  • @fyellin
    @fyellin Рік тому +1

    Does immortality mean I can get rid of all the Py_INCREF(Py_None) that are in my code because I'm returning None from a function?

    • @Spencer-wc6ew
      @Spencer-wc6ew Рік тому

      Do you have to change the reference count for None anyway?
      I wrote a C python module a few years ago. And for numbers, I was told to not change the reference count when returning an integer from 0-255, because those are special objects that are never deallocated. It may be the same for None.

    • @fyellin
      @fyellin Рік тому

      @@Spencer-wc6ew If you use PyLong_FromLong(x), then you don't need to increment the reference count, because the object you've just received has had its count incremented. But you can definitely crash Python by calling a function that returns `Py_None` without incrementing it. Call sys.getrefcount(None), find None's refcount, and call your function that many times.
      I assume the same holds true for the small integers, True, False, etc if you save the Python object in a global and repeatedly return it, rather than calling a getter.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 Рік тому

      I always set reference counts properly, for None as for everything else.
      I once wrote a test program that did nothing but decrement the refcount for Py_None until it crashed. I got up to about 512 decrements or so, maybe slightly more.

  • @lukekurlandski7653
    @lukekurlandski7653 Рік тому +1

    I love python type hints, but not gonna lie, without rigorous type checking, I’m skeptical whether this kind of “advanced” typing is actually useful…

  • @therealjannis12
    @therealjannis12 Рік тому

    Do they rename Python to PIthon at Version 3.14?

  • @DecimasoN
    @DecimasoN Рік тому

    3:14 you mention PEP 648 when it's PEP 684 :P

  • @Balaji-qq9lc
    @Balaji-qq9lc Рік тому

    I really hope python will be called as Pie-thon when 3.14 is released

  • @ivancota9762
    @ivancota9762 Рік тому

    Can't wait for 3.14 - Python Pi 😊

  • @twentytwentyeight
    @twentytwentyeight Рік тому

    Feeling like the error message update has been a long time coming, wonder if rust launching with readable traceback added to the push

  • @JohnFallot
    @JohnFallot Рік тому

    Let's gooooo!!!

  • @19DonCorleone87
    @19DonCorleone87 Рік тому +5

    Thank you for the summary. It was super useful. The rating at the end of ever ysection feels kind of subjective and arbitrary.

  • @jadencorr6897
    @jadencorr6897 Рік тому

    kwargs typing is useful for framework-like code. Because it is not obvious which parameters are accepted by **kwargs.

  • @danielschmider5069
    @danielschmider5069 Рік тому

    3:13
    its PEP six- eighty-four, not fourty-eight!

  • @kirilplatonov4423
    @kirilplatonov4423 Рік тому

    Batched finally here! I no longer have to produce weird magic tricks with iterator multiplication

  • @Jake9066
    @Jake9066 Рік тому

    Python 3.7? Was that the one that made me continue using 3.6 well into its "security updates only" stage?

  • @SourabhBhat
    @SourabhBhat Рік тому +1

    For me the new Generic syntax and @override is 10/10. The generic syntax would have made it easier for me to read though!

    • @FrederikSchumacher
      @FrederikSchumacher Рік тому

      You are aware that anything in Python is a generic? "def foo(bar)" means bar is generic (as is the return value). It's not untyped either, because of "object" being the base for all Python values? There's only limited amount of usefulness in something like "[X where Parent]" as documentation.

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 Рік тому

      I think the C++ syntax was stupid. And it still doesn’t let C++ (or Java, for that matter) expression Python concepts like function factories and class factories.

    • @SourabhBhat
      @SourabhBhat Рік тому

      @@FrederikSchumacher Yes. Python is too generic, which doesn't allow to express the intent of the programmer. The generic specification is just a hint for IDEs to check the sanity of the code. For example, a class of type T, has methods that adhere to the same type T.

  • @HoangoKidZero
    @HoangoKidZero 8 місяців тому

    Hmm... A video on Python 3.12 with a slightly over 12-minute runtime :D

  • @RichardHamnett
    @RichardHamnett Рік тому

    Can't wait for 3.14 - then we'll have Piithon

  • @minecraftermad
    @minecraftermad Рік тому

    Will it be renamed to pithon in 3.14?

  • @IamusTheFox
    @IamusTheFox Рік тому

    Wow, python has changed a lot. I learned 3.1 and haven't had a reason to keep in the last few years

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Рік тому +1

    3:04 Having recently converted an application away from WSGI to ASGI instead, I could care less about things that might improve WSGI behaviour.
    WSGI is Python’s answer to PHP. ASGI goes beyond that, to let Python do things (like handle WebSocket connections) that PHP cannot.

  • @rutabega306
    @rutabega306 Рік тому

    Yo the next version is 3.14 thats dope

  • @kareemmika6210
    @kareemmika6210 Рік тому

    The new generic type syntax looks like GO. and i love it actually

  • @marcinpohl3264
    @marcinpohl3264 Рік тому

    What about Linux perf support? I'd love to see a good example of it

  • @konpet4248
    @konpet4248 Рік тому

    Python 3.7 is now deprecated, huh? Feels weird, since that's the version I started coding on. But ofc it needed to go eventually. Other than it having a special place in my heart, there's no point in holding onto it

  • @tuberroot1112
    @tuberroot1112 Рік тому

    Can't wait for Python v 3.14159 running on Raspberry pi.

  • @rodrigof.5956
    @rodrigof.5956 Рік тому +1

    Just two versions left

  • @glorytoarstotzka330
    @glorytoarstotzka330 Рік тому

    can someone explain to me how generics work? I've re-watched the entire 2 mins about 3 times and I don't quite understand what's going on. it really triggers me a big impostor syndrome because I work as a python dev, yet I've never dealt with this

    • @dave_jones
      @dave_jones Рік тому +3

      I see generics get used a lot in languages like Java/Kotlin, C++, Typescript, and probably others. The idea is that the "Type" of the parameter is determined when the object is actually implemented/created. So when you're creating the structure of the object, you can't define what the type is, but you want to tell the type checker that "whatever is used during implementation, that type is also used (wherever you want it in your logic)" - this most often gets used when you're dealing with custom types, not really the built-ins. This allows you to build tools that accept any arbitrary types, but still tell the type checker that the type matters and reference it elsewhere.
      A basic abstract example might be: you want to track what movies, tv shows, and books you have in your "Library" - one of your methods on the library allows you to easily link sequels and prequels. In this case, you don't really care what the type of the object is (be it a movie or book or any other entertainment concept), but you want to ensure that whatever you link as the sequel is the same type. So you define the generic (commonly specified as "T" for "Type") and then you can now reference that in the rest of your code by saying "The parameter is a generic T and the sequel is the same type T"
      More commonly I see it used in situations where you are building packages or tooling, so your function/class can be typed even if you never know what might be used for it, all you know is that the type must match elsewhere in the logic.

    • @algiffaryriony
      @algiffaryriony Рік тому +2

      from my understanding, in short, when you use generics with a function, whatever type you use as input for it, it also outputs that type. i guess it's useful for functions that are meant to process objects that behave similarly and have implemented similar methods or dunders.
      in the example in the video at 0:37, using generics in that function makes it clear that whatever numeric objects (or any object for that matter. it may also be objects like datetime where you can compare them) are used as input, the function will output object of that type, marking that specific type with 'T' , with a note that that object implements the greater than, less than, and equal dunders to allow comparison.

    • @SolarLiner
      @SolarLiner Рік тому +4

      To me the easiest way to understand generics is to see how useful they are when typing lists, and more generally "container" classes.
      If you have to write your own list implementation, and you want to type your code, you'll soon face an impossible question to answer: what type do you use for the elements of your list?
      The answer is, well, you can't know. You can have lists of ints, of booleans, strings, etc. Clearly, the type of the elements of the list depends on each use that will be made of it -- therefore you have to tell the type checker that you have data whose type will change depending on how it is used. This is what type parameters are for, they're placeholders for the type checker to fill whenever your class is used.

    • @PhthaloJohnson
      @PhthaloJohnson Рік тому +3

      Lists in python are generic. For example we can have a list of integers, or a list of strings, unfortunately, we can have a list of ints and strings ([1, "1"] is valid), which is often not what we actually want. To solve this, languages introduce a generic type T, that can be anything, int, string, double, myType, etc, but importantly, it can only be of that type only, not multiple types. So a generic list of type T[ ] can admit something like: [1, 2] and ["1", "2"] but not [1, "2"] .

    • @sarevofaona
      @sarevofaona Рік тому

      Back in the day, at the dawn of object orientation, we'd call this parametric polymorphism@@dave_jones