top | item 45400499

(no title)

iandanforth | 5 months ago

I hate typing in Python. I spend a good chunk of my day fighting the type checker and adding meaningless assertions, casts, and new types all to satisfy what feels like an obsessive compulsive nitpicker. "Type partially unknown" haunts my dreams.

Duck typing is one of the best things about Python. It provides a developer experience second to none. Need to iterate over a collection of things? Great! Just do it! As long as it is an iterable (defined by methods, not by type) you can use it anywhere you want to. Want to create a data object that maps any hashable type to just about anything else? Dict has you covered! Put anything you want in there and don't worry about it.

If we ended up with a largely bug free production system then it might be worth it, but, just like other truly strongly typed languages, that doesn't happen, so I've sacrificed my developer experience for an unfulfilled promise.

If I wanted to use a strongly typed language I would, I don't, and the creeping infection of type enforcement into production codebases makes it hard to use the language I love professionally.

discuss

order

jgb1984|5 months ago

Couldn't agree more! I've been using Python for almost 20 years, my whole career is built on it, and I never missed typing. Code with type hints is so verbose and unpythonic, making it much harder to read. Quite an annoying evolution.

pansa2|5 months ago

As the article says, type hints represent a fundamental change in the way Python is written. Most developers seem to prefer this new approach (especially those who’d rather be writing Java, but are stuck using Python because of its libraries).

However it is indeed annoying for those of us who liked writing Python 2.x-style dynamically-typed executable pseudocode. The community is now actively opposed to writing that style of code.

I don’t know if there’s another language community that’s more accepting of Python 2.x-style code? Maybe Ruby, or Lua?

maleldil|5 months ago

> Need to iterate over a collection of things?

Iterable[T]

> Want to create a data object that maps any hashable type to just about anything else?

Mapping[T, U]

dwattttt|5 months ago

Beyond the advantage that a type-checker/linter can tell if you're doing the right thing when writing those functions, it lets an IDE infer what type you're iterating over, in order to provide more support/completion/hinting/checks (without recursively analyzing arbitrary code, so: 'instantly' vs 'maybe not ever).

dragonwriter|5 months ago

> Duck typing is one of the best things about Python.

And duck typing with the expected contract made explicit and subject to static verification (and IDE hinting, etc.) is one of the best things about Python typing.

> If we ended up with a largely bug free production system then it might be worth it, but, just like other truly strongly typed languages, that doesn't happen

I find I end up at any given level of bug freeness with less effort and time with Python-with-types than Python-without-types (but I also like that typing being optional means that its very easy to toss out exploratory code before settling on how something new should work.)

rkomorn|5 months ago

> I find I end up at any given level of bug freeness with less effort and time with Python-with-types than Python-without-types

Same.

Type hints also basically give me a "don't even bother running this if my IDE shows type warnings" habit that speeds up python development.

Absence of warnings doesn't guarantee me bug-free code but presence of warnings pretty much guarantees me buggy code.

Type hints are a cheap way to reduce (not eliminate) run time problems.