5 ms·
Modern python is no longer dynamic. Type checking is a big part of python now. Python also has ADTs which match it in power to rust.
by formulathree 3y ago
Modern python is no longer dynamic. Type checking is a big part of python now. Python also has ADTs which match it in power to rust.
- sneed_chucker 3y agoThat's great if you're in a codebase at a workplace which enforces python type annotation checking. Unfortunately, I can tell you from experience that out in the real world, at fortune 500 companies, there are millions of lines of untyped Python doing critical work while being full of subtle type errors which should be compile time errors but will rear their heads as runtime errors when it's least expected.
- formulathree 3y agoIt's changed a lot recently. I would say the majority of companies now use type checking. It's def not as pervasive yet as Typescript.
- dagmx 3y agoDo you work at the majority of companies? I can tell you that I’ve worked with code bases from each of the FAANG companies that don’t use type checking, because it’s optional. Anything that’s optional in a language will not be ubiquitous Your statements are incongruent with the reality of production.
- formulathree 3y agoI've likely worked for more companies then you in the last 5 years or so due to my personality. I don't stay at one place for long. Actually I've probably worked for more in my entire career, but only the last 5 years should be relevant. Even so where I worked is only part of the equation. You can look up which companies use python types in a google search. Let me add more nuance, companies that use python as glue code as in scripting languages don't use types. This makes sense as python is considered not as important as the main language. For companies that are primarily based on python... the majority use types. The ones that don't are actively migrating. This includes faang and subsidiaries. In fact type checkers for python are likely to be built by faang or companies close to that tier.
- dagmx 3y agoI’m unsure how you can so confidently make that assertion. Even at companies that do use type hints, there’ll be tons of legacy code that won’t (and probably tons of new code as well if we’re being realistic). It’s like saying every company uses bash scripts. It’s not really indicative of the prevalence in actual code bases in production use other than saying it may be used somewhere within the company. Between this and your other comments, you’re making very widespread comments that can’t logically apply to everything and nor do they in my experience.
- formulathree 3y ago>Even at companies that do use type hints, there’ll be tons of legacy code that won’t (and probably tons of new code as well if we’re being realistic). The first part is true, I agree with that assessment and I never made a contrary claim. Companies are migrating. The second part in parenthesis, is less common, I don't agree that it's a generality among companies that have python as a primary language. >It’s like saying every company uses bash scripts. It’s not really indicative of the prevalence in actual code bases in production use other than saying it may be used somewhere within the company. I don't even know what you're getting at with this example. Tons of companies use python "somehwhere" within the company. I'm sure in those cases it's often not typed. But for companies or teams that use python as a primary it's typically typed or in the process of getting migrated to be typed. That is the nuance I added to my claim. >Between this and your other comments, you’re making very widespread comments that can’t logically apply to everything and nor do they in my experience. Except you made statements that are factually wrong. I literally ran mypy on some code and your statements were categorically incorrect from your other comment. Usually these debates are anecdotal so logic doesn't apply as it's just fuzzy opinions regarding social aspects of society. But that's not the case here. You made factually incorrect statements and that has bearing on the correctness of your anecdotal statements too.
- dagmx 3y agoType hinting , not assertion, is a part of Python. Type checking is analysis post facto and doesn’t account for dynamicism of classes. The very ability to self modify an instance at any time or use __getattr__ makes it incredibly dynamic. It also doesn’t account for every dependency having accurate type hints or any at all.
- formulathree 3y agomodern python development is used in conjunction with an external type checker. That's what I meant. My mistake for not being clear. Obviously the python interpreter itself does not do any type checks. It's sort if like how modern development with javascript is used with an external compiler of another language (typescript) that compiles a typed language into one without types.
- dagmx 3y agoYeah but my rebuttal is that even with type hints and adequate type checking, that Python is too dynamic to trust consistent behaviour. An object can conform to a type in name only, but that’s not enough to tell you what methods or attributes exist on it at any given time.
- formulathree 3y agomonkey patching is rarely done. In practice, your rebuttal almost never occurs. I believe these type checkers can detect monkey patching and trigger a type error or warning.
- dagmx 3y agoIn practice it does occur very often. I’d suggest not ascribing your own experience to my own. I’ve been professionally coding in Python for over a decade in very varied codebases. There are tons of libraries in many companies that use dynamic attribute lookups for efficiency reasons, when adapting to different data sources and the like. Or pass through lookups on nested objects. Or they’re dynamically looked up on bound libraries from other languages and frameworks. And these type checkers cannot detect it. Python’s dictionary access is not guarded by the type checkers and neither is __getattr__. If you’re making such wide sweeping statements you need to be more familiar with the subject matter.
- mattgreenrocks 3y agoThe problem is less the language and more the culture around it. Typing will always be second-class, culturally. Additionally, mypy feels much slower to use versus something like Rust’s ‘cargo check’. Regarding ADTs: do type checkers ensure totality (all cases covered) when pattern matching? (I’m not casting aspersions here. It is what it is, you know?)
- formulathree 3y ago>The problem is less the language and more the culture around it. Typing will always be second-class, culturally. Additionally, mypy feels much slower to use versus something like Rust’s ‘cargo check’. Agree with mypy being slow. As for the culture it's largely moving in the right direction and it's at a point where you're more likely to find a python shop to be using typing than not. Of course for scripting I think people may not be so readily adopting types. >Regarding ADTs: do type checkers ensure totality (all cases covered) when pattern matching? Yes it does. Cast your initial presumption aside. This was a huge surprise to me too. Everybody loves typescript but basic usage of types in typescript is actually less powerful because it doesn't support this. You have to use it in a specific way though. https://tech.preferred.jp/en/blog/python-exhaustive-union-match/ https://tech.preferred.jp/en/blog/python-exhaustive-union-ma...
- still_grokking 3y ago> Modern python is no longer dynamic. Of course it still is. The type hints have no runtime semantics whatsoever. The actual type-checking still happens at runtime in Python, and is not related to any static checks. Out of the perspective of Python's interpreter the type hints don't even exist. They're like comments… Static type checking is not part of Python! > Python also has ADTs which match it in power to rust. All Turing-complete languages match each other in power… Besides that: Python doesn't have a static type system in the first place, so it can't compete with Rust in this regard. That's not even the same game.
- formulathree 3y ago>Of course it still is. >The type hints have no runtime semantics whatsoever. I clarified my meaning in another comment. You're right, I meant to SAY modern development involves type checking with python. But not with the interpreter. My mistake for not being clear. >All Turing-complete languages match each other in power… I obviously mean type checking. Additionally what you're saying isn't even true. Not all turing complete languages match in power or capability. >Python doesn't have a static type system in the first place, so it can't compete with Rust in this regard. That's not even the same game. Modern python development is done in conjunction with a type checker. Sort of like how modern javascript development is done with typescript. That levels up the game to where python is roughly in the same class as rust when it comes to type correctness. Depending on the type checker python matches the power of rust, roughly. There are differences, but for ADTs they are pretty similar in capability.
- still_grokking 3y ago[flagged]