4 ms·
What's the static-typing landscape look like for Python? JavaScript, the other dynamic language that's eating the world, has the well-known TypeScript to help i
by _bxg1 7y ago
What's the static-typing landscape look like for Python? JavaScript, the other dynamic language that's eating the world, has the well-known TypeScript to help it scale. I couldn't imagine maintaining any large codebase without a good type system.
- netfl0 7y agoPython’s new type hinting seems to solve most problems pragmatically, are there issues you have with it?
- sabujp 7y agopytype is nasty when you're trying to set a return type for a function that was previously returning different types (e.g. let's say different protos).
- ShinTakuya 7y agoHow so? You could use the Union type temporarily if needed.
- BerislavLopac 7y agoMy main problem with it is that it can add a lot of extra syntax which -- while immensely useful for static checking -- is never executed in production. PEP 484 includes support for stub .pyi files, which contain the typing, but IDEs still don't take advantage of that.
- Varriount 7y agoPython has type annotations[0] and tools such as mypy[1], which enable fairly decent optional static typing. [0] https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html [1] http://mypy-lang.org/ http://mypy-lang.org/
- _bxg1 7y agoIt's cool that there's an official spec; JS doesn't have that even though the syntax for typescript and flow is nearly identical.
- itsjloh 7y agoDropbox had a nice post on this not so long ago https://blogs.dropbox.com/tech/2019/09/our-journey-to-type-checking-4-million-lines-of-python/ https://blogs.dropbox.com/tech/2019/09/our-journey-to-type-c...
- mav3rick 7y agoIt kind of feels wrong when dynamically typed languages add "hinting". It means they admit that strongly typed is the way to go. Edit: typo statically typed
- lacampbell 7y agoStatically typed
- sgillen 7y agoIt means admitting that in some situations strongly typed is a better way to write code.
- shabda 7y agoPython designers have some thoughts on this :) $ python -c "import this" | grep purity Although practicality beats purity.
- mynegation 7y agoNot only "they admit", but Python _is_ actually strongly typed. You probably meant to write "statically typed"
- dragonwriter 7y ago> It kind of feels wrong when dynamically typed languages add "hinting". Python doesn't have just hinting, it has an optional static typechecker. Anyhow, I don't see it's weirder than static languages adding the option to use “dynamic” as a pseudotype to opt out of static typing on a case by case basis. Languages are more than typing regimes, and language designers can believe that there is no one typing regime that is right for all use cases.
- 01100011 7y agoLack of static typing and explicit destructors are two things that keep me from using Python for anything but toy scripts that I can monitor myself. It's a shame, because the syntax and built-ins are expressive, readable, and powerful. It's also slow, but I can deal with slow. Machine time is often cheap, while developer time is expensive.
- joshuamorton 7y agoPython has both of those, static typing is easy to use (all my new code is type checked!) and destructors can be used, they just like really, really shouldn't be. Context managers instead. Why do you even want destructors in python?
- war1025 7y agoPython does have explicit destructors, at least when using CPython. Having worked on a python codebase for the past eight years, static typing isn't really much of an issue. Just document what types you expect, and write the code to match. If it runs, it runs. Plus, you have pylint to catch most of the silliest mistakes.
- dragonwriter 7y ago> Python does have explicit destructors, at least when using CPython Python has finalizers rather than destructors, though they are sometimes referred to as destructors (the Python docs explicitly note that this is incorrect but not why, there is discussion of the difference—inbthe context of C#—here: https://blogs.msdn.microsoft.com/ericlippert/2010/01/21/whats-the-difference-between-a-destructor-and-a-finalizer/ https://blogs.msdn.microsoft.com/ericlippert/2010/01/21/what... )
- overgard 7y agoPython has destructors but I can't remember ever seeing a good use for them. I think with statements pretty much capture almost every use case for destructors
- narimiran 7y ago> Lack of static typing and explicit destructors are two things that keep me from using Python (...) the syntax and built-ins are expressive, readable, and powerful. > It's also slow It looks to me like you're describing Nim. Static typing, similar syntax to Python, expressive, readable, powerful, fast; and destructors are being worked on as we speak.