Hacker News new | ask | show | jobs
by uryga 2963 days ago
I don't see a contradiction here. (speaking as a Python and Haskell user):

1 - dynamic languages, while granting great freedom, make it easy to shoot yourself in the foot with simple typing bugs, so we cope by adding type checking

2 - many (most?) static type systems are not expressive enough to type some programs, so people embed dynamic solutions to build the stuff they need.

Haskell is pretty decent at typing most stuff I want, but it makes me think about it up front, which is nice sometimes, but not always. Python lets me build stuff quickly and work out the design as I go, but it's hard to make sure everything works as intended. I wish there was something that let me bodge things together, but then constrain them with types when I need to...

1 comments

Python 3.6 introduced type checking as an option, so you can hack something together in Python, then add types later.
Type hints aren't checked or enforced by the compiler. They're really just special-syntax comments to help the developer (or IDE, as the case may be). I wouldn't call this "type checking".
You can run a type-checking tool (e.g. mypy) which will tell you if you've made any type errors.

Since Python has no 'compile' step, type-checking takes the place of compiling in other languages.

I'm using the type annotations from `typing` in a Python 3.5 project I'm working on, but only as a form of documentation. Unfortunately mypy doesn't work for me – the project heavily uses a namedtuple-style sum type library, and I haven't found a way to make the types it generates work with mypy.

(iirc mypy has builtin support for namedtuple, but doesn't really support other types generated at runtime)