5 Reasons Why You Should Use Type Hints In Python

  Рет қаралды 106,879

ArjanCodes

ArjanCodes

Күн бұрын

Пікірлер: 252
@ArjanCodes
@ArjanCodes 2 жыл бұрын
LEGO people *were* hurt in this video.
@aflous
@aflous 2 жыл бұрын
Reported to KZbin 👮 🚨
@Simon-yf7fo
@Simon-yf7fo 2 жыл бұрын
If you don’t use type hints you fucking deserve it lmao
@AndreaDalseno
@AndreaDalseno 2 жыл бұрын
I liked the joke. Actually, KZbin subtitles translated your sentence as "be an Arian" and it sounds a little bit scary, doesn't it? 😵‍💫​
@cdhit
@cdhit 2 жыл бұрын
Hi Arian, love your videos definitely. Could you make an episode about how to use Python package and to structure Python code to make project nice and clear ? @Arian
@RBBlackstone
@RBBlackstone 2 жыл бұрын
My condolences for Bernard ( AKA Wilhelm).
@HexenzirkelZuluhed
@HexenzirkelZuluhed 2 жыл бұрын
"I don't want to push you in any specific direction" he said, while dismembering Person B.
@terencetsang9518
@terencetsang9518 2 жыл бұрын
Dumbledore asked calmly
@derGerlach
@derGerlach 2 жыл бұрын
When I started with Python, TypeHints were not available. Then I had to work with Springboot wich uses Java. I really loved the statical typed style. It just forced me to write better code. Nowadays I use type hinting in every piece of Python code and i love it. It helps so much, especially with bigger projects. Great video, keep it up 👍👍
@roelmathys
@roelmathys 2 жыл бұрын
But it's a game of hints in Python. No statistical analysis is done, in Java it would not compile and would not run. And it's getting better, but it's making code much more verbose.
@redcrafterlppa303
@redcrafterlppa303 2 жыл бұрын
@@roelmathys a good rule of thumb is when your types get out of hand and look verbose and cluttered, rethink your design decisions.
@roelmathys
@roelmathys 2 жыл бұрын
@@redcrafterlppa303 Python existed for two decades without this. Python doesn't do anything to improve type safety based on type hints. You still can run the code if the type hints indicate it should not run (mypy). It's bolted on and feels more like documentation than something else.
@redcrafterlppa303
@redcrafterlppa303 2 жыл бұрын
@@roelmathys only because it runs doesn't guarantee its good code. The level of control a strongly typed language provides python can never achieve. Overall in my opinion python is a really ugly language with to much dynamic and "it works somehow" in it. I don't get what to even use python for.
@roelmathys
@roelmathys 2 жыл бұрын
@@redcrafterlppa303 statically compiled languages give type guarantees but do not guarantee correctness or good code. But I do not understand what you are commenting about. If you don't want Python, what are your remarks adding?
@wesselbindt
@wesselbindt 2 жыл бұрын
My main gripe with type hints is that they have a tendency to give a false sense of security. I've lost count of the times where I and my colleagues thought some piece of code was type safe only to later find out that something was inferred to be of type Any because of a poorly typed 3rd party library or some forgotten subscripts on a generic (the idea usually being that surely mypy should be able to infer this). Sure, many of these instances could've been avoided by configuring mypy to be as strict as possible, but in projects which started out untyped and are in the process of migrating to using types, this is simply not realistic. Still, in spite of this, it is absolutely beyond me that someone would choose to write a large production system in completely untyped code. The horror
@andyblue953
@andyblue953 2 жыл бұрын
I'm always wondering why developers would switch at all to Python for larger productions? It's not like there aren't good alternatives.
@tkerkvliet
@tkerkvliet 2 жыл бұрын
isn't that just the perfect description of development reality: fixing shit of people that made choices that are absolutely beyond us
@alex952
@alex952 2 жыл бұрын
@@andyblue953 because of its extremely fast turn around for development and easy of use/learn. It’s also got many libraries that help you deliver code. As a company you can enforce documentation, testing, etc. which helps overcome the drawbacks of the language.
@newperspective5918
@newperspective5918 2 жыл бұрын
​@@alex952 Tbh I don't really see easy of use/learn to be a mayor point. For me it is all about libraries and the ability of the language to solve the problem. Python is a bad choice if type safety or high performance is key, so just pick something else, e.g. C++. I think Python, C++, HTML, CSS and JS is all the languages you need to know in most cases. Then add som SQL, bash and UNIX knowledge on that and you can basically solve any problem.
@stephens3909
@stephens3909 2 жыл бұрын
Where third party libraries are involved, this is where type casting comes in, especially if you are taking advantage of abstract interfaces and some OO patterns when using some third party libraries.
@cemsity
@cemsity 2 жыл бұрын
My use case for type hints is mostly for the IDE Intellicode. If i have a larger application then using type hints with mypy keeps me sane and prevents a lot of dumb bugs. Also the fact that type hints aren't required enable the developer to omit type hints where they aren't need or obvious.
@simmonslucas
@simmonslucas 2 жыл бұрын
I guess that this benefit should have been apparent to me, but I didn't realize. A great time saver to find errors before you debug.
@rban123
@rban123 2 жыл бұрын
yeah especially on a big project I'll typically have a CI job which runs mypy automatically on every PR and fails the PR if there are any type errors
@xor2003
@xor2003 Жыл бұрын
* Type hints in Python are optional * They can aid with debugging and avoiding outdated documentation * They also assist with autocomplete options in IDEs and make code easier to read and write * Python 3.10 allows for lowercase type hints for certain data types * Using type hints improves code quality and catches errors early on * It promotes explicit data structure design and simplifies code-writing * Type-driven development clarifies how data will interact and detects issues with complex functions * Pydantic and type hints improve data understanding, focus unit tests, and offer faster and accurate accuracy checking.
@TomTrval
@TomTrval 2 жыл бұрын
Agreed👍. Type hints are especially helpful for me in 2 cases> -when I return to my code after long time or study code from someone else🤯 -early detect problems with code architecture. I learned when I am thinking to my self "Hmm typing this code is hard" it means there is something wrong with architecture (usually I missed abstraction to decouple modules)
@roelmathys
@roelmathys 2 жыл бұрын
Type hints are just hints, if somebody puts them in, and the next person does not respect the "contract", the application still runs.
@Aldraz
@Aldraz Жыл бұрын
My personal strongest arguments for using or not using type hints are these: Pros - Using type hints will actually make your code much faster one day, because libraries like mypy, etc will use it to compile to much faster code. Cons - It clutters the screen and the more type hints you have the less immidiate information you have in some sense, so maybe using it for every function isn't the best idea.
@Ludwighaffen1
@Ludwighaffen1 9 ай бұрын
Another "con" is that, at least in data science, many bugs come from the wrong dimensionality of a data structure, or the wrong formatting of a specific table column, or a column not existing. These bugs can only be properly handled by managing exceptions inside functions and type hints is not really helping.
@CornishMiner
@CornishMiner 2 жыл бұрын
I've picked up the habit, and I like it. It helps me a lot with keeping track of what I'm doing, it reduces documentation and it helps make the most of the ide.
@SophieJMore
@SophieJMore 2 жыл бұрын
3:06 minor correction, before 3.9 I remember I had to change all my type hints in one of my projects to make it compatible with python 3.8 so that it could run on windows 7
@lunarmagpie4305
@lunarmagpie4305 2 жыл бұрын
3.9+ style type hints work in 3.8 if you do `from __future__ import annotations` at the top of the file
@SophieJMore
@SophieJMore 2 жыл бұрын
@@lunarmagpie4305 Interesting. Thank you, I didn't know that
@mamazu1995
@mamazu1995 2 жыл бұрын
It's a great video and I completely agree that types are a great way to ensure correctness and proper scope of functions. One thing that I would also like to add to point 4 is that, if your program is sufficiently typed then you can do "type assisted refactoring". For example you want to replace a property of an object with a method call or something. Just remove the property from the object and then run a static analyzer like mypy and see where the code fails. Then you know which places to fix. This is much easier than trying out all possible paths that could crash the program.
@ErnestGWilsonII
@ErnestGWilsonII 8 ай бұрын
I just want to say thank you very much for making these videos and sharing them with all of us. I only recently found your channel and I am now subscribed with notifications enabled and thumbs up! Thank you, Ernie in Pennsylvania
@ArjanCodes
@ArjanCodes 8 ай бұрын
Thank you for the kind comment, Ernie!
@NStripleseven
@NStripleseven 2 жыл бұрын
Another nice ide-related thing that type hints improve is autocomplete. If your ide knows that a variable is supposed to be an int, it can give you suggestions that make sense for an int value.
@tronicit
@tronicit 10 ай бұрын
I think that's probably the best reason to use them. That and the methods which work as soon as you apply the hints. It's often easier to pick a method or related function from the list than trying to remember the exact syntax which doesn't work if you haven't got it correct.
@liquidpebbles
@liquidpebbles 2 жыл бұрын
I recently moved from a C# job to Python... Man, I can't stand dynamically typed languages. The development experience with a typed language is far superior in my opinion as it opens up so many possibilities for the IDE.
@Michal_Peterka
@Michal_Peterka 2 жыл бұрын
I prefer the way F# works. You don't have to specify the type at most of time but it is still strongly typed. And there is VS Code extension Ionide that displays the types annotation for you.
2 жыл бұрын
@@Michal_Peterka type inference of ML-like languages are awesome, F# is underrated
@Pirake123
@Pirake123 2 жыл бұрын
Type hints actually make python more enjoyable. Putting them in the language means we don't get a Tython language down the track (like Typescript for JavaScript)
@roelmathys
@roelmathys 2 жыл бұрын
I don't know, it's a lot of extra typing, a lot of extra verbosity. And it's not that it's statically typed at that moment, it will just run fine, wel :) Statically typed languages result in not being able to execute the application. Type hinting is just that: hints. It - currently - does not make code magically safer, it depends on running mypy ... , or makes the generated application faster..
@Shivnaren
@Shivnaren 2 жыл бұрын
Thanks a lot, Arjan-learned all about typing and types from you. One downside is I can't stand to read untyped python anymore...unfortunately there's a lot of it about :D
@dougalscott4896
@dougalscott4896 2 жыл бұрын
I teach people coding (i.e. programming, not just python) and I find type hints very useful. It gets the student to think about the code that they are writing before they start bashing away at the keyboard, and if they need to change the types it probably means that they need to change the code.
@joningram
@joningram 2 жыл бұрын
You briefly mention 'duck typing' in the beginning, and I think this is the issue I have with the mass importation of type hints into Python - they miss that what I want to specify in a function header is not the type I require of an input variable, but instead what capabilities that variable should have. For example, if I am writing a 'max' function, then I don't want to restrict it to a list, or a tuple, or any inbuilt type - I want to accept anything which can be iterated through. There are various guises of this idea - interfaces, templates, contracts - in other languages and I am hoping that this is the direction that typing will go in Python. The other issue I have with typing is that it can make quite simple ideas (like passing a function into another function) complicated purely through awkward syntax. I have been able to explain and demonstrate ideas such as callback functions very easily in Python which I would have struggled to write in a language which required types.
@DajesOfficial
@DajesOfficial 2 жыл бұрын
You have types such as Iterable and Callable for that specific purposes
@wyst69
@wyst69 Жыл бұрын
Your recorded the whole video in one single shot ! That's clean.
@arnold9103
@arnold9103 2 жыл бұрын
We started using those at work! Improved readability and quality somehow !
@andyblue953
@andyblue953 2 жыл бұрын
I use Python for data science purposes and am perfectly happy with dynamic types for rapid prototyping. I use type hints only very rarely and prefer default values instead. But it seems that more and more serious programmers move to Python as well, to write larger projects with a stronger need for type control. Since there's plenty of excellent alternatives with static types, I always wonder about their motivation to switch... ?
@ArjanCodes
@ArjanCodes 2 жыл бұрын
What I often see in the companies I’m working with is that they start with a simple data science project in Python, but then things become more complex. They want to keep using all the useful libraries in the Python ecosystem, but they want to add an API layer to the data processing system. Or what about doing complex computations in parallel? Or how about running all those things in the cloud? Or what if you want to make the code generic so you can use it for multiple clients? Or add authentication to control access to the data? Etc etc. It’s at this stage where you can really benefit from a more strict approach to writing Python code to keep things manageable.
@Witpaardt
@Witpaardt 2 жыл бұрын
​@@ArjanCodes that is more a cultural problem and by definition not generalizable. I think you make good points in your video, but @Andreas Groth does as well. Also microservices. In many companies those data science scripts might turn into a small service where typing can be useful, but not necessary. There your final point about short scripts remains valid. Furthermore, naming things clearly can also help with documentation (as you can see in your video). The thing about Python is, the language is flexible and that is a good feature imho.
@Ziggity
@Ziggity 2 жыл бұрын
I started a job at a young startup last year, backend was written in python and was completely untyped. I was losing my mind. These days after pushing hard in that direction everything is typed and I am a happy dev
@kayakMike1000
@kayakMike1000 2 жыл бұрын
Type hints are sorta like stronger typing which is pretty good... Wasn't available when I started with python, but I can see great value.
@roelmathys
@roelmathys 2 жыл бұрын
Python was already strongly typed - has always been told. You do not get a statically type checked language with these type hints. It's more for documentation purposes.
@anyyyel
@anyyyel Жыл бұрын
Dude, your channel is really good. Congratulations! Simple, objective.
@ArjanCodes
@ArjanCodes Жыл бұрын
Glad you like the videos!
@quaxBK
@quaxBK 2 жыл бұрын
The strongest argument for type hints are for the LSP imo, you get much better diagnostics and completions that way.
@nargileh1
@nargileh1 2 жыл бұрын
yeah code completion is the best thing I get out of type hints; with CTRL-click to jump to definition code in second place
@sorvex9
@sorvex9 10 ай бұрын
Literally the primary reason I use them lol
@andrewglick6279
@andrewglick6279 2 жыл бұрын
I love type hints in Python and I always try to use them. For people wanting safe validation from type hints, checkout the Beartype library (it is a decorator you can add to functions that verifies your arguments with your type hints). I do think type hints have ways to go, and part of that may be Python's refusal to enforce them even as part of convention. For example, there is something so much more elegant about `foo?: int` in TypeScript than `foo: Optional[int]` (I hate having to import Optional). The lack of type hinting enforcement in libraries also makes it difficult for IDEs to work at their full potential. And don't even get me started on how hideous the `Callable` type hint is. Though generally speaking, I think Python is headed on the right track for improving type hints.
@cn-ml
@cn-ml Жыл бұрын
I just cannot grasp why people dislike using type annotations. The amount of coding errors type hints prevent is just insane. Even with statically typed languages people usually code bugs, but without type checking even it's almost impossible to write code that works the first try. I absoltely hate python without types.
@ЮрійАндрашко-у8я
@ЮрійАндрашко-у8я Жыл бұрын
For complex tasks where we need types there are Java or C#... Python and JS does not need types, they are for rapid development. Type hints are ok until you need to use multiple generics with restrictions. And then you need more time to write type definitions than the actual code.
@wylde780
@wylde780 2 жыл бұрын
This video is prefectly timed as i recently came across some type hints in some airflow code and didn't understand it. Thanks
@robertbrummayer4908
@robertbrummayer4908 2 жыл бұрын
Great video Arjan. I also use type hints a lot in my code. I recommend mypy as type checher. It can easily be integrated into VS code.
@bonquaviusdingle5720
@bonquaviusdingle5720 Ай бұрын
Using type hints actually enables your editor to function similarly to a compiler, which helps a lot in developing quality code.
@sync9827
@sync9827 2 жыл бұрын
The PyCharm IDE checks if the types of the arguments and of the return value match with the types specified in the docsring. So while you're writing the code the IDE checks if all the types are correct even though you aren't using any type hints. So you can do type-driven development without type hints. But since type hints are pretty elegant and less work than writing docstrings, I might also start using type hints...
@hansdietrich1496
@hansdietrich1496 11 ай бұрын
Also, PyCharm hints become much better, when you're generous with adding type hints to your code.
@postmodernist1848
@postmodernist1848 Жыл бұрын
After learning a lot of Python I tried C and it really changed my perspective. At first, I thought that static typed languages are inferior (are dumb??) and then I realised that it's much, much easier to understand and maintain typed code. Static typing is a great feature, not a disadvantage. When I came back to Python, I knew I needed to use (optional) typing
@ThatOpinionIsWrong
@ThatOpinionIsWrong Жыл бұрын
You mean Optional[typing] ? lol
@bluzter
@bluzter 2 жыл бұрын
Type hints are kinda satisfying which is why I love them.
@nisheetpatel2654
@nisheetpatel2654 2 жыл бұрын
I often forget to hit the like button until the time you mention it, but this time, with the lego people in the first 20 seconds, I knew this video was legendary!
@Betacak3
@Betacak3 2 жыл бұрын
Source code is meant to be read by humans. You only ever write a piece of code once, but you will read it many times. So, whenever you ask yourself "Is it worth it to spend this extra time to write this?", think of the time it could save when you have to deal with that bit of code 6 months or more later. That's my response to the "It's more work" argument and - in my experience - a good way to approach code in general. Don't write code for your computer. Write it for yourself and your collleagues.
@banatibor83
@banatibor83 2 жыл бұрын
Very very good point. The most important attribute of code that it should be easily readable. That's why I like to use small functions with self explanatory names, and spend time on naming my variables. When things are well named it is easy to read and understand the code. Type hints start to get extremely helpful when multiple scrum teams are working on the same software. Unavoidable that these teams will develop a common library for certain tasks for that software, type hints in that common library can save many hours.
@victormungai
@victormungai Жыл бұрын
In one of the latest updates(at the time of writing this comment) to the python extension on vscode, one can instruct vscode to activate the type checker. I have mine set to strict and I'm glad I did.
@aashayamballi
@aashayamballi 2 жыл бұрын
Just wanna say.. thank you, Arjan! Have learned a lot from you on Python 🙏
@ArjanCodes
@ArjanCodes 2 жыл бұрын
You’re welcome - glad to hear that the content is helpful to you!
@fexofenadinaGenerica
@fexofenadinaGenerica 2 жыл бұрын
I agree. Type hints help to better understand the code.
@rachinini
@rachinini 2 жыл бұрын
Python as a simple scripting language that is used for writing small to medium-sized programs is beautiful. Adding type hints, redundant features (how many string interpolation methods do you need?), and other excess features has turned Python into an ugly, unstable mess.
@bluesdog88
@bluesdog88 2 жыл бұрын
Arjan you are a strange man, that's mostly why I subscribed....keep up the good work and code!
@הודגמרסני-ת5ל
@הודגמרסני-ת5ל 2 жыл бұрын
A team for the win!! Once again, great video. notes are taken!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thank you, glad you liked it!
@ivhea
@ivhea 2 жыл бұрын
Density of jokes per minute is augmenting with each new video. At some point this will become a comedy channel. Just a fact, not a judgement. :)
@ArjanCodes
@ArjanCodes 2 жыл бұрын
You got me!
@Pawl0solidus
@Pawl0solidus 2 жыл бұрын
After working for years with Typescript I’m learning Python for some months and I can see extreme value in these type hints, they are really useful for the reasons mentioned in this video.
@maksimon519
@maksimon519 Жыл бұрын
in short, type hints make development much faster. it also help editor to auto-complete the name of attributes, which makes writing codes much faster and satisfying.
@josewilhelm2717
@josewilhelm2717 2 жыл бұрын
Great video! Can we have a discussion video about Object Oriented Programming and why it is being criticized so much lately?
@HelloWorlds__JTS
@HelloWorlds__JTS 2 жыл бұрын
@ArjanCodes already has a handful of videos discussing tradeoffs between functional and object oriented programming. Just search for object oriented in the search bar on his main page, and the first 5-6 videos are probably exactly what you're looking for.
@josewilhelm2717
@josewilhelm2717 2 жыл бұрын
@@HelloWorlds__JTS oh thanks, I didn't know. I will search it out!
@distant6606
@distant6606 2 жыл бұрын
I also recommend using mypy to check for these type hints.if u type hint a variable to str and then assign to it an integer mypy will throw you an error.
@riptorforever2
@riptorforever2 2 жыл бұрын
Psico introduction with Dexter's serial killer flavor.. loved!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Tonight’s the night…
@ea3gug
@ea3gug 2 жыл бұрын
Hey!, excellent video as always, very educational. Thanks!. I am oriented into app security, and I have found a paralelism about this technique and a tool called 42Crunch that does unit testing against an API definition (Swagger, OpenAPI), doing unit tests against the type definition to check the specification against the real input/outuput, messing with parameters, so it is the same concept, to check that development meets specification.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks for sharing!
@sanketower
@sanketower 2 жыл бұрын
Doing OOP without type annotations is practically against the basic design patterns that define that paradigm. Typing in Python may not be the default behavior and is technically just sugar coating, but adding it to your already structured project can help you discover a lot of vulnerabilities and bad practices hidden behind your Python trickery. Like they always say; make it work, then make it right.
@airatvaliullin8420
@airatvaliullin8420 2 жыл бұрын
I don't want to push you in any particular direction *beheads a lego man who is against typehinting*
@willemvdk4886
@willemvdk4886 2 жыл бұрын
The Wilhelmscream had me, haha. And the fact that you used Uncle Bob's book lol
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks :)
@TheSzybas
@TheSzybas Жыл бұрын
That "luhnatic" joke was perfect!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you Tomasz, glad you liked the video!
@FabioKasper
@FabioKasper 2 жыл бұрын
Ohh, "type hint" is how it is called then. All I know is that I started using them after seeing it in your videos. Thanks again. 😂
@JorgeEscobarMX
@JorgeEscobarMX 2 жыл бұрын
I have to agree that removing type checks on unit tests is removing a lot of boring repeating work. As long as we are all consenting adults, I'm removing type checks from my own unit tests.
@thomassmail6896
@thomassmail6896 2 жыл бұрын
This is really cool, I wasn’t even aware of them. I feel they are something I might add at the end of writing a function when I go back and comment my code.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Thomas, glad it was helpful!
@NicholasShanks
@NicholasShanks 2 жыл бұрын
Try adding them right at the start when you don't even know how the function is going to work yet.
@JuampyRabino
@JuampyRabino 2 жыл бұрын
Love that you used Wilhelm's scream at the beginning 🤣🤣🤣🤣
@ArjanCodes
@ArjanCodes 2 жыл бұрын
It's my favorite sound effect :)
@handle_and_gretel
@handle_and_gretel 2 жыл бұрын
use type hints and then vscode extension AutoDocString to create the small snippet for documentation
@tugrulpinar16
@tugrulpinar16 2 жыл бұрын
Thanks a lot for expanding on this
@ArjanCodes
@ArjanCodes 2 жыл бұрын
You’re welcome!
@LewisCowles
@LewisCowles 2 жыл бұрын
I Liked this. Another reason to use them (I wrote you an email about not liking type-hints) is that it can make it easier for compliant tools to assist a coder in refactoring in certain code-bases. I Still don't type-hint everything, but have found myself using type-hints more and more. Do you think Guido comments have proven to be unhelpful in use of this language feature, or perhaps are misinterpreted?
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks Lewis! Your email was one of the reasons I created the video 😊. I can’t speak for Guido, but programming languages are always changing, leading to new insights into how to make things better which in turn changes our opinions about things. I’m in favor of a stricter Python, while at the same time not losing the flexibility and simplicity of the language in its current form. But let’s see, that might also change in the future 😁.
@sillytechy
@sillytechy 2 жыл бұрын
Hi could you recommend a book on software design. Like how to design a large scale software with multiple elements like database, cloud elements(AWS/AZURE), break into smaller components, make Class relationship diagrams to use OOPs properly. Any book that talks on this.
@Ludwighaffen1
@Ludwighaffen1 9 ай бұрын
Thanks for this great video. In your neat example on the luhn_checksum function (I liked your lunatic joke btw 🙂), I'd argue that "number" is a pretty bad variable or argument name in the first place. But we all Bernards got your point. ;-)
@snippletrap
@snippletrap 2 жыл бұрын
Arjan you have the best programming content and the high production values are impressive. But if you're going to show your arms, you ought to tone them up!
@JeffreyChadwell
@JeffreyChadwell 2 жыл бұрын
Nice use of the Wilhelm Scream!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Ha, thanks! 😁
@k98killer
@k98killer 2 жыл бұрын
Might be preaching to the choir with this one, but I imagine some people haven't experienced the difference between coding with type hints and coding without them.
@matrixtoogood5601
@matrixtoogood5601 2 жыл бұрын
How to use type hints in frameworks like Django?
@parisqs
@parisqs Жыл бұрын
Beware: If you don't write type hint, you LEGO body will be torn apart!
@zackadam2598
@zackadam2598 2 жыл бұрын
I liked this video explicitly for the LUNA dig. Spicy! 🌶
@cdhit
@cdhit 2 жыл бұрын
Hi Arian, love your videos definitely. Could you make an episode about how to use Python package and to structure Python code to make project nice and clear ? @Arian
@Andrumen01
@Andrumen01 2 жыл бұрын
Think about typehints as seat belts for code. In principle, they aren't needed, but during a crash they can save you!
@DanielStoehr203
@DanielStoehr203 Жыл бұрын
Do you have a favorite Type checker? Pyright? Mypy? And why? Are there differences?
@ranjansingh9972
@ranjansingh9972 2 жыл бұрын
Type Hints add to why I find Python to be a frustrating language. It’s a language that seems to support every paradigm of programming, and because of that it’s hard to know ‘the right way’. It’s just endless learning of new language features and tweaks - and there’s no escaping it because the libraries/frameworks you use pull in language features from across the spectrum. Probably been trying to learn/code in Python for 6 years and still feel like a complete novice. That same amount of time in an older language, like C, was enough for relative mastery (vastly different eras though, I concede).
@lowkeygaming4716
@lowkeygaming4716 Жыл бұрын
Nice vid. Very insightful.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you, glad you liked the video!
@samsung40_media87
@samsung40_media87 2 жыл бұрын
I do it automatically, it doesn't feel like extra work and follows on from explicit > implicit and defining the return type as a way to guide others so as not to use mixed return types
@davethorn9423
@davethorn9423 2 жыл бұрын
If I had a function expecting a string , surely don't call the argument number , call it num_str or something ? Or am I missing something . Just clear naming seems to be a solution ?
@johnjsal
@johnjsal Жыл бұрын
Is that VS Code you were using? What is the name of that syntax theme?
@davidedigrande3204
@davidedigrande3204 2 жыл бұрын
My internal OCD programmer COMMENDS that I add type hints in all of the code. Sometimes I do it in variables declarations too, when the type of the object is not obvious.
@eengamer158
@eengamer158 2 жыл бұрын
The only reason I use type hints is to irritate my teacher by using intentionally wrong hits because he doesn't allow me to use my programming language of preference
@cezhou9140
@cezhou9140 9 ай бұрын
Type hints is like you spent an eternity to get accustomed to duck typing and then it gets shattered to dust.
@vaolin1703
@vaolin1703 4 ай бұрын
Just use typing.Protocol
@colletantoine8885
@colletantoine8885 2 жыл бұрын
Thanks for this great video ! How to you manage type hints with bumpy in Vscode ? I always end up with a lot of warnings although I use bumpy.typing ...NDArray etc.
@bitswapper
@bitswapper Жыл бұрын
VSCode doesn't show the type mismatch in python when I use type hints
@HaiderGill-th5bp
@HaiderGill-th5bp Жыл бұрын
I was always told to prefix my variable names with int_, flo_, str_, boo_ in C so I know what type it is, I expanded it for C++ obj for object why do it because datetime could be an datetime obj or a string holding a datetime...
@miguelvasquez9849
@miguelvasquez9849 2 жыл бұрын
How should i type when a function receive an object that is not imported in my module? Should i import it only for the hinting?
@p.t.8312
@p.t.8312 2 жыл бұрын
Do I need a special VS Code extension to highlight incorrect types in, for example, function arguments? Looks like it doesn't work by default.
@Celestialzzz
@Celestialzzz 2 жыл бұрын
in vs.code for me type hinting does not flag a type mismatch error as you display at 7:55 in your video. Is there an extension that you have to download first to have this work?
@CynicalOldDwarf
@CynicalOldDwarf 2 жыл бұрын
I like the concept, hate the syntax though. I wish they'd have kept a c-style typing syntax (as in type first, e.g. int a_number) instead of using typescript's syntax
@blutella4162
@blutella4162 2 жыл бұрын
Great video.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thank you!
@willemvdk4886
@willemvdk4886 2 жыл бұрын
I definitely like "Type Driven Development" way more than I like "Test Driven Development", honestly ;)
@kurkabane702
@kurkabane702 2 жыл бұрын
Can someone explain why the function argument 'number' is reffered further as 'nr'? Is it some recent feature?
@sandie_jr
@sandie_jr 7 ай бұрын
Finally, I'm convinced!
@ArjanCodes
@ArjanCodes 7 ай бұрын
Glad the video was useful then! Ahah
@hansdietrich1496
@hansdietrich1496 11 ай бұрын
I'm waiting for the day, when all python code, that is type hinted, automatically gets jitcompiled and is just 100x faster than the other code. At that point, most people will switch by themself.
@kosmonautofficial296
@kosmonautofficial296 2 жыл бұрын
Interesting video thanks
@TechieGuy82
@TechieGuy82 2 жыл бұрын
Love you videos.. Actually "your bad joke" made me laugh :D Thumbs up
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks! 😃
@hshhsjhahsvs7728
@hshhsjhahsvs7728 2 жыл бұрын
Am rooting for type hints included.
@TheKubaski
@TheKubaski Жыл бұрын
I noticed that you use a tab to debug the python code. Does anyone know how to set that up?
@realms4219
@realms4219 2 жыл бұрын
Type hints are implicit documentation, the best kind
@appuser
@appuser 2 жыл бұрын
It's hard not to like them when you discover bugs right away when you start using them and from that point forward (that would otherwise escape your notice).
@russianbotfarm3036
@russianbotfarm3036 5 ай бұрын
If you’re going through the rigmarole of type hints you should just use a static language.
@presstv
@presstv 2 жыл бұрын
Did you kill Person A along with Bernard The Headless? that's not fair🤣😂. great video Arjan :)
@malmiteria
@malmiteria 2 жыл бұрын
i think you didn't talk about some fair criticism of type hint tho. For exemple, one of the great value of type hint you talk about is entirely reliying on IDE tooling, which make it much less valuable in general (think any IDE that doesn't support type hint) Another big one to me is that it's a hint, so i can be wrong. And since it's built in a way for you to trust it, and rely on it, it can trap you in some errors hard to anticipate, if you absolutely type hint everything everytime. In other term, it's a situational tool, which has its good use case, and its dangerous use case also, for any non straightforward code, you're kinda lost in some more complexity I mean, how would you type hint a decorator for example? what about a decorator with parameters? Sure, it's doable, but is it really helping? I'm sure there's more to say, like, it's made to look a lot like type declaration in other statically type language, so it gives a very missplaced impression of what it is, for anyone coming from those language, which is definitely *not* going to lower the learning curve for them (by trapping them harder in the idea that it's more than just a hint i mentionned earlier, for example), and python is usually known for its great learning curve.
Avoid These BAD Practices in Python OOP
24:42
ArjanCodes
Рет қаралды 53 М.
Spongebob ate Patrick 😱 #meme #spongebob #gmod
00:15
Mr. LoLo
Рет қаралды 13 МЛН
The CUTEST flower girl on YouTube (2019-2024)
00:10
Hungry FAM
Рет қаралды 56 МЛН
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 51 МЛН
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
Rust: When C Code Isn't Enough
8:26
CodeAhead
Рет қаралды 162 М.
Next-Level Concurrent Programming In Python With Asyncio
19:19
ArjanCodes
Рет қаралды 176 М.
Python Typing - Type Hints & Annotations
24:46
Tech With Tim
Рет қаралды 113 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,7 МЛН
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 273 М.
The Ultimate Guide to Writing Functions
24:31
ArjanCodes
Рет қаралды 182 М.
How to Design an AWESOME Function Signature in Python
28:05
ArjanCodes
Рет қаралды 34 М.
7 Python Code Smells to AVOID at All Costs
22:10
ArjanCodes
Рет қаралды 372 М.