News for hackers. Stuff that matters.
Re:Reasons to avoid static type checking by baq on Sunday January 28, 2024 @03:13AM (#39163496)
I’d probably agree with you 5 years ago, but in those 5 years typescript has shown that you can take a completely dynamic language, add a very powerful and well thought out type system and the resulting language is so much better for non-trivial projects.

So if you ask me, who has been programming Python since before new-style classes, if types make sense for Python, the answer is a resounding ‘yes’: just steal as much typescript typing as possible.

Re:Reasons to avoid static type checking by BiteCode_dev on Sunday January 28, 2024 @03:50AM (#39163693)
I wish we'd steal more. TS type systel and syntax is much better that what we have.

And I hope one day iter[] and callable[] will be made available, cause importing typing sucks.

Re:Reasons to avoid static type checking by LarsDu88 on Sunday January 28, 2024 @03:28AM (#39163564)
And not only that, but you can take that statically typed code and build JIT compilers on top of them
Re:Reasons to avoid static type checking by Chris_Newton on Sunday January 28, 2024 @04:36AM (#39163976)
At first glance, JavaScript/TypeScript and Python seem like similar cases, but in practice, I have never found them to be so.

The JS/TS community has enthusiastically adopted static typing, to the point where (a) the type system in TypeScript is reasonably clean and intuitive for everyday work, (b) almost every major library uses static types and specifies them in its documentation, (c) almost all major tools and development environments pick them up and work well with them, and probably as a result of those things, (d) almost everyone now uses static types extensively, at least for new development.

The Python community seems far more hesitant. I don’t know why. Maybe it’s because we’d just had such a long transition from Python 2 to Python 3 and introducing static typing feels like another big change? Maybe it’s because Python’s static type system simply hasn’t been as clean and tidy as TypeScript’s, particularly before the recent generics changes in 3.12? Whatever the reason, in practice none of (a)–(d) above reliably holds in the Python world. Personally I do still prefer to use static types in new Python code, but it’s frustrating and often needlessly time-consuming when popular libraries don’t.

Re:Reasons to avoid static type checking by zokier on Sunday January 28, 2024 @05:25AM (#39164259)
While there are countless cultural and technical reasons why TS ended up more successful than Python here, I think the single most significant aspect was that TS decided to go with structural system while Python went with nominal. While nominal systems in general are fairly popular and well-received, the chief thing here is that structural types match how the language was being already used. Especially for Python they had before embraced "duck typing" as their idiom and nominal types are in conflict with that.
Re:Reasons to avoid static type checking by trashburger on Sunday January 28, 2024 @06:06AM (#39164487)
This is my single greatest complaint about Python's type system. Protocol should have always been the primary building block rather than just being relegated to something you use for "duck typing". Subtyping fits much better with things like the dynamic approach of the Django ORM, for example.
Re:Reasons to avoid static type checking by alanwreath on Monday January 29, 2024 @08:51AM (#39176217)
Not sure what you mean, while it’s true that it would have been nice that Protocols were always the primary building block, as of python 3.8 they _can_ be depending on your use of Structural Typing https://peps.python.org/pep-0544/