6 ms·
Why would you add type checking to Python! Using another language with static typing would be the solution. It’s not like the browser where you have to use Java
by parham 6y ago
Why would you add type checking to Python! Using another language with static typing would be the solution. It’s not like the browser where you have to use Javascript so you add another layer to your toolchain.
- jsmeaton 6y agoBecause you’re a python shop that wants some extra safety. Because you’ve got an existing code base. Because you want the benefits of a dynamic language with some of the benefits of type checking. Because the editor experience is way better when you selectively sprinkle in some types. Because you can choose how deep you go on types depending on the impact. We have avoided countless production issues just by annotating when something is Optional or not.
- HelloNurse 6y agoBecause type annotations are medium to high value documentation for your users. Because stating the type of something important can expose design issues (e.g. "wait a minute, it isn't always a X! in case Y it can be a Z! Forbid or support?") before they become a serious problem.
- pansa2 6y agoBecause someone suggested it, and Python’s main design principle nowadays is “include as many language features as possible”.
- anhner 6y agoSo that people who want to use it, can? You don't have to use it if you don't want to.
- pansa2 6y agoPython’s philosophy is supposed to be “one obvious way to do it”, not “you decide which way to do it, it’s optional”.
- konjin 6y agoThat's not been the case for a very long time now.
- pansa2 6y agoAgreed (type hints are just one example), but I wish it were.
- jsmeaton 6y agoThere is one obvious way to add type annotations. The annotations themselves are optional. That's just gradual typing[0], and it doesn't "break" the zen of python any more than having the choice of using a class over free functions in your program. The meme going around that Python is adding so many features that it's becoming something "not python" is super weird to me, and it appears as though it's propagated since the walrus operator discussion and hasn't really gone away. All popular languages add features and adapt as new tools, methodologies, and learnings pop up from other communities. This is a good thing (subjective, I guess), and in general I find Python to be somewhat restrained. [0] https://en.wikipedia.org/wiki/Gradual_typing https://en.wikipedia.org/wiki/Gradual_typing
- pansa2 6y ago> Python is adding so many features that it's becoming something "not python" Here's an example I came across recently. It's from the official documentation for the `heapq` module, so I assume it's now considered the idiomatic way to write a wrapper for each item in a priority queue: @dataclass(order=True) class PrioritizedItem: priority: int item: Any=field(compare=False) That's completely different to the way such a class would have been written even in Python 3.4. It would have been a simple class with an explicit `__init__` and `__lt__`. Instead, the above dataclass sits on top of a mountain of complexity and everything about it is implicit. It's in violation of both "Simple is better than complex" and "Explicit is better than implicit".