4 ms·
The first example illustrates perfectly why I dislike explicit typing: primes: set[int] = set() candidate: int = randint(4, domain) It's just so ugly
by TekMol 4y ago
The first example illustrates perfectly why I dislike explicit typing:
primes: set[int] = set()
candidate: int = randint(4, domain)
It's just so ugly and redundant.
My feeling is that redundant stuff like type hints make programmers create more bugs because they don't see the forest for the trees anymore.
As if you wrapped the driver of a car in so many seat belts that they cannot see the road anymore.
- jsmeaton 4y ago> My feeling is that redundant stuff like type hints make programmers create more bugs because they don't see the forest for the trees anymore. Not ones that ship to production. Some developers have a terrible time trying to get through the mypy errors. But from my observations, I haven't seen any typing related errors in a very long time.
- iknownothow 4y agoI don't exactly know what Pycharm does but I only add type hints when Pycharm's default type checker raises a complaint or is unable to infer the type. To me that's just the perfect middle ground. Sometimes adding a type to a single object (e.g. `df: pd.DataFrame = ...`) only once at the top of a 20-50 line function, is usually sufficient for Pycharm to infer all other types downstream without ambiguity.
- gjulianm 4y ago> My feeling is that redundant stuff like type hints make programmers create more bugs because they don't see the forest for the trees anymore. I've been using type hints heavily and it's been such a great help in avoiding bugs and also faster completion in IDEs. Most of the time, with correctly typed functions you don't have to write explicit types for variables. It's a little bit more code, yes, but it's definitely worth it for any codebase that grows more than a handful of files. Even for smaller ones I have found it very useful.
- mrtranscendence 4y ago> I've been using type hints heavily and it's been such a great help in avoiding bugs and also faster completion in IDEs Agreed. I've been using type hints for the past few years now even though most of my projects are fairly small (< 10,000 LOC). I wouldn't say they've prevented a huge amount of bugs, but they've definitely prevented a few, and I think they've helped in library design and documentation.
- giantrobot 4y agoType hints are great at helping understand intent. A lot of bugs happen from understanding a code signature but not understanding intent. In a language like Python where types are all loosey goosey it's easy to write subtle bugs by misunderstanding intent.