Why you should use Type Hints in Python - Are type hints worth it?

preview_player
Показать описание
Are type hints worth it when programming in Python? Or is it just increases the size of your code? In this video, I will explain why I love pythons type hinting and think every programmer should use them as early as possible in a project.

Questions of the day
■ Do you use type hints in your project?

Follow me here:

Related videos:

Type hints documentation:

Type Checkers:

Timestamps:
00:00 Intro
00:38 The problem with a dynamic type system
02:07 Type hints help to write and read code
04:45 What are type hints doing for you?
06:32 How are type hints preventing type errors?
08:17 When should you use them?
10:09 How to start?

---

This video contains advertising content.

#python #programming
Рекомендации по теме
Комментарии
Автор

From past experience, people who say that "thing X is easy" usually don't program with a lot of people.

When you program in a company with 11 other programmers and everyone of them access to view and edit every code, It's really easy to not know changes even in your own code, not to mention codes from other people. You need to study it before touching anything.
Is it not impossible to debug it? Nope, but it is HARDER... And why should anything be HARDER when it can be EASIER?
Even if you have to search who commited the changes to an existing function, or take some time to read proper documentation, it can be hard and more time consuming.

More often than not programming complex business logic is already hard enough for you to add more complexity, therefore Type Hints are more than welcome. Every thing that adds to code readability is more than welcome. Great video!

ProfBrunoClemente
Автор

Long time programmer in other languages and just learning Python. One thing I was missing is the strong type-checking of other languages. Yes, yes, I know Python's proponents love the type-free behavior, but... Stumbled across your videos about type hints and intrigued. Will certainly be adding this to my 'tool box' of Python. Thank you.

mikefochtman
Автор

Great explanation of the motivation. I've used typescript and fell in love with types. Very happy to see Python has this option!

mauricios
Автор

good video on the topic I just was baffeled about.
Thanks for explanation!
BTW - nice production!

Malins
Автор

Thanks for the links and details on hinting - I can't wait to force my coworkers to use them now

Type hints are awesome -> there is a reason for strongly typed languages and the various benefits they add. I love that python lets you choose when to be explicit with typing and when you can be a bit looser.

Being able to dynamically create types is also incredibly powerful!


PS. If you haven't read/researched into strongly typed functional languages like SML, they are getting much closer to the incredible world of Compilation Implying Correct Code which is awesome!

jewpcabra
Автор

Editing and Presentation is awesome. Also your content and teaching style is unique and fabulous.

sujeetkumar.
Автор

I really love the editing, quality content you should have more subscribers

Hasasinful
Автор

Thanks so much for the content, bro, the world needs more type hints hahaha

dalanxd
Автор

Great content. I didn't know of type hints in python, very interesting

marco.nascimento
Автор

I have used them in one of my projects but didn't know what they are called. Nice video.


Subscribed.

ritiksaxenaofficial
Автор

Oh yeeees! Very useful video! Thanks so much!

masumasi
Автор

Type hints are stupid
.
.
.
.
...ly useful!

I view them as super useful comments that the type checker helps ensure you keep up to date!

DevOpsDirective
Автор

I am about to create a framework for Python from a pure C++ 3D game engine in which would execute independently. However... there was a mention that Numpy executes faster than C which I haven't got around to verify myself. Also... Facebook create a Python to C/C++ transcoder made from their artificial intelligence that I want to fully check out in a short while.

ThankYouESM
Автор

One thing I'd say to people who are not convinced is to consider which functions define "entry points" to your code?

If someone is likely to call a function from another module, you should have sufficient documentation to tell them *how* to call it without reading your source code -- type hints can function as that documentation.

nialltracey
Автор

Types hints very good for a loosely typed language like Python. Although these sorts of things are not needed in languages like Java or TypeScript.

kennyanthony
Автор

Type hints have some use, but I totally disagree with fanatics who adopt it like a new religion (Most of them probably coming from a java background). A simple line of code like
> def process(items, filter)
becomes 3 times as long, and more difficult to read. The zen of Python says "simple is better than complex". A good docstring can provide even better information than the type hints.
I would say that type hints have their use in 1/4 of cases. For example, I would NOT use it in the def process(items, filter) example, and use a docstring instead; but I might use it in the Genome = list[int] example, because it's easier than creating a Genome class.

Alyamepi
Автор

⭐ THIS VIDEO IS SPONSORED BY KITE ⭐

❓ _Question of the week?_ ❓
Do you use type hints in your projects?

KieCodes
Автор

Sir, can you upload the "music generator" genetic algorithm to github?
I would love study it

So nice content

israelenriquez
Автор

can we do this?:
def function(var_1:list[float, float, float], var_2:list[int, float]):
pass

I can't seem to find info on this

jrohit
Автор

Wish this guy's voice was deeper... so it would sound like Arnold Schwarzenegger telling me how to code.

Cynthia_Cantrell