back

by JNRowe·6y ago·view on hn ↗
> lack of typing information isn't "free solo" hard but it certainly makes life a lot less pleasant.

One of the projects I work on has switched to full type hinting along with heavy mypy¹ usage, and it has become an absolute pleasure to work with. Along with hypothesis², I can't recommend mypy enough. It must be said that retrofitting either to an existing project is a lot of work though.

1. http://www.mypy-lang.org/ 2. https://github.com/HypothesisWorks/hypothesis

2 comments
I note with interest that modern python has type hints.

Years ago the lack of visible types was often flouted as a benefit (i.e. terser code, less boiler plate, easier for learners to understand etc).

I eagerly await the addition of optional "scope hints" of { and } ! ;-)

Sarcasm aside, now that there are type hints and python programmers need to type as much as Java/golang/c# programmers, why not just write in those languages?

Genuine question - what are the benefits of starting something new in python (assuming all things being equal - i.e. equal knowledge in java/golang/c# and no legacy reasons forcing you)? Why would anyone pick writing type-hinted python Vs a fully explicitly typed compiled language?

> I eagerly await the addition of optional "scope hints"

Scope hinting is simply called braces; `from __future__ import braces`.

> Genuine question ...

IMO assuming all things are equal seems to miss how things actually are. The pluses still fall on Python some times, and other languages at other times. Things do vary; developer availability, library availability, target system support, certification story, tooling, even curbside appeal can be legitimate on some occasions.

I'm trying not to pick on your individual language examples, as firing digs seems to be missing the point we're discussing. Or perhaps it is the very point, as two of them wouldn't have even been in my list.

What I can't reconcile with myself is, if I'm going to add type hinting in Python, why not use a language where my efforts of adding type hints result in performance gains? I get why it's nice for a team, but it seems like a lot of work for half the potential benefit of a typed language.
I think that sort of thing is coming, with e.g. `mypyc` that compiles typed Python into C.
Cython can. However, machine performance doesn’t matter a lot of the time.