Earlier quoted context omitted.
Not hard per se, but extremely unergonomic. A pandas dataframe types to something like Iterable[SomeKindOfProductType[int, str, str, ... (78 other columns)]]. The formal type of a dataframe in the middle of a transformation is... not very useful to know.
It's not very useful to type , but that's why we have type inference. It's certainly very useful to know , even if that knowledge is indirect via the type of the resulting dataframe after all the transforms.
Python’s “type hints” are a bit of a disappointment to me
541–550 of 597 posts
Re: Python’s “type hints” are a bit of a disappointment to me
#542Earlier quoted context omitted.
What Pandas does is notoriously hard to fit into a compile-time type system. Certainly too hard to go into the brains of scientists who didn't grow up coding. No, the code in data science isn't bad because of the lack of typing. The code is "bad" mostly because those writing it are relatively fresh from starting to program. Also there is more pressure to make things possible, often just to run it once, and neglect re…
> What Pandas does is notoriously hard to fit into a compile-time type system. Sounds a lot like F# type providers to me. https://thesharperdev.com/introduction-to-fsharp-type-provid...
And good luck teaching beginning scientists F#.
Re: Python’s “type hints” are a bit of a disappointment to me
#543Earlier quoted context omitted.
I didn't say "with compile-time languages" but "with compile-time type systems". And many similar tools in a statically typed language will necessarily create a way to have one static type that doesn't care what the data inside actually looks like. This even starts with basic Numpy and handling tensor objects. It's not easy for a type checker to understand what operations you can do with what shape of tensor. Worse,…
> This even starts with basic Numpy and handling tensor objects. It's not easy for a type checker to understand what operations you can do with what shape of tensor. That doesn't sound like a Python problem. Instead, it sounds like the natural consequence of numpy being designed in a way where their data types aren't organized into subtypes, and leave that as runtime properties. This is a natural reflection of numpy'…
Re: Python’s “type hints” are a bit of a disappointment to me
#544Earlier quoted context omitted.
It isn't a matter of "compile time": explicit type declarations and definitions can often be formally sound but practically worthless. Significant types in ETL-style applications typically come from outside (e.g. a certain CSV column in the input file contains a date in YYYYMMDD format, or maybe YYYYDDMM, figure it out, and don't forget time zones or your accounting will go wrong). Then types are mostly complex but o…
The source code shouldn't need to say anything about the type of the resulting matrix explicitly, perhaps. But why shouldn't the type system keep track of shapes and deduce the accurate type for the result of said multiplication?
Re: Python’s “type hints” are a bit of a disappointment to me
#545Earlier quoted context omitted.
On the small scale, Python is very productive. Once you get to large codebases with a rotating roster of many developers, it becomes a net negative, which is why type specification languages are gaining major inroads. I love Python, but I wouldn't write anything for production at any scale in it anymore. But for small scale stuff, it remains my favorite! (Although, I like static binaries languages, like Go, for a lot…
How is typing productive in large codebases? If I see a bunch of imports related to typing only, I have to juggle them around in my mind together with stuff that really matters. Not to mention the notorious circular import problem, that is much more likely in a big codebase. If I have a custom class, that class has to be passed as a type hint for functions. What If I use that class in another module, but have to impo…
Re: Python’s “type hints” are a bit of a disappointment to me
#546Earlier quoted context omitted.
What is "major inroads"? Python is actually rising in popularity and major companies are building big things entirely in Python... In my opinion there is no excuse not to.
Python has a tremendous amount of momentum because it has become so popular outside of the traditional software development world, but other languages are picking away at it, even given that momentum. And while I am in a bubble, like everyone else, in my bubble, and those I talk to in my bubble, all see large a shift away from Python. Adding stronger typing, like type hints, could reverse that, of course. The reason…
Re: Python’s “type hints” are a bit of a disappointment to me
#547Earlier quoted context omitted.
What is "major inroads"? Python is actually rising in popularity and major companies are building big things entirely in Python... In my opinion there is no excuse not to.
What you both are experiencing is your bubbles clashing.
Re: Python’s “type hints” are a bit of a disappointment to me
#548Earlier quoted context omitted.
Have you tried it? Python has gained most of its popularity before type hints, and I would (wildly) guess 99% of Python programmers don't even use type checking at all. Static typing is completely viable and I hear those arguments mostly from those who didn't use Python for a long time. The added productivity makes up for a little more debugging while the program is running. I'd also posit that many Python codebases…
I'm not sure I'm following your comment correctly, but you seem to be implying that adding type hints in Python results in some lost productivity? If so, I would counter that adding types isn't particularly onerous and adds very little overhead to development time, and over time they'll tend to increase your productivity since you'll make less errors, IDEs can give you better hints, etc. As to the percent of Python d…
Gradual typing is based on effort. Most people won't spend the effort. And they don't need to, most of the time, either.
Re: Python’s “type hints” are a bit of a disappointment to me
#549Earlier quoted context omitted.
On a quick search, for example https://link.springer.com/article/10.1007/s10664-013-9289-1 . "This paper describes an experiment that tests whether static type systems improve the maintainability of software systems, in terms of understanding undocumented code, fixing type errors, and fixing semantic errors. The results show rigorous empirical evidence that static types are indeed beneficial to these activities, exce…
Cool - this paper has 3 conclusions: - Static type systems are an effective form of documentation – Static type systems reduce the effort to fix type errors – Static type systems may not be helpful in preventing semantic errors It would have been awesome to have evidence for #3 but even just #1 & #2 could be useful, albeit to a much lesser extent. Could we quantify by how much? It’d be important to quantify because i…
Other take home message is that the famous 10x programmer was found in both groups. The one with dynamic language was faster, just as the argument for dynamic typing goes.
Re: Python’s “type hints” are a bit of a disappointment to me
#550This article is so hopelessly mis-informed, that it's practically hard to read without screaming "that's not how any of this works!" Most of their main arguments - type hints can be wrong, they can be ignored, and they don't inform you in a useful way about program state because of this - all evaporate as soon as you start using the correct tooling. My stack is pycharm, mypy, pydantic, sqlalchemy stub, several mypy p…
> My stack is pycharm, mypy, pydantic, sqlalchemy stub, several mypy plugins, black, isort, tabNine completion, and a bunch of custom scripts/Make to automate the common tasks. Christ. What a mess. With a stack like that, it's a stretch to say you're "writing in Python" anymore.
Who cares if I'm "writing in python" at all? I'm solving problems. Honestly a good IDE (pycharm or vscode) will give you 80% of the ergonomics.