Live data from Hacker News

Python's “disappointing” superpowers

lukeplant.me.uk

151–160 of 264 posts

Re: Python's “disappointing” superpowers

#151
post #110

Earlier quoted context omitted.

We had dedicated QA testing. QA testing failed to create the requisite conditions. Type checking is not a replacement for QA testing. However, it is much cheaper and also finds bugs that might be incredibly hard to find through random chance or through structured smoke testing, because it does not depend on how common a given code path is. QA testing is even less likely to find issues than automated test suites, sinc…

[flagged]

This is nearly impossible to precisely study:

- Because correlation != causation, for one thing: 2.5x the number of bugs in static "style" code bases (not sure what that means) does not mean that static type systems lead to more bugs. It could be that users of dynamically typed languages find themselves needing robust automated tests more often, because they can't rely on static typings. This would suggest that in a similarly productive language, your effort would go much further with types than without, even if this measurement is accurate.

- Because measuring bugs is hard: you don't actually know how many bugs a given piece of code contains, you only know how many you found. Statically typed code contains more information about the intent of the code. Not only does this make it easier for machines to analyze, it makes it easier for humans to analyze, too. Ask anyone who does security audits whether they prefer code that has strict static type information or not.

- Because not all bugs are the same; a reputable study would need to go through great pains to classify the different kinds of bugs and determine their severity as well as determine why they happened. Counting bugs as just a number and then comparing them is like counting SLOC. It doesn't tell you anything on it's own!

> Static typing has nothing to do with code correctness, it's purely about code performance.

Uhhh... Says who? Type erasure systems offer no performance benefits at all, since the types are removed before runtime.

There are contradicting studies, that suggest static typing prevents bugs, but there's little point in trying to fight them. None of the studies I've seen feel robust or complete enough, and on top of that, what would really be helpful is a meta-analysis of multiple more robust studies so we can get an idea of the true takeaways.

Until then, there will be some subjectivity.

There's no nice way to say this: I don't trust people who treat issues like this as black and white. To me, it's a sign of immaturity as an engineer. I do of course believe that static type checking is a net win overall and that the evidence to the contrary likely has other factors (like, for example, relying on relatively primitive type checkers that catch less errors, require more handholding, and generally have trouble handling idiomatic code) but like I said, YMMV: everyone has their failure and success stories. To me, if I can find a bug before I even save the file, versus needing to wait until QA catches it, or worse, it lights prod on fire, it's probably a win. As far as this "static code style" business goes, I don't understand it. My code does not look that different when it's JS vs TS. For Python, MyPy still doesn't seem sufficient, so I would not be surprised if strictly using things MyPy supports would make code worse. For us, switching to Go had more benefits than JUST types; of course we wound up having better performance and memory usage too, and the error handling practices, while verbose, definitely put error handling and edge cases front and center.

Re: Python's “disappointing” superpowers

#152

Earlier quoted context omitted.

[flagged]

> No citation is needed, it's fairly obvious to any experienced Python programmer. So you can't even explain it, despite claiming to be experienced. Why should I listen to you? Your whole response is just you saying "First off, you're wrong. Second off, I'm right." Here's a very simple example: I want to change a dict to a class. In untyped Python, how do you make sure that you make this change safely without introdu…

Here's a citation if it makes you happy: https://games.greggman.com/game/dynamic-typing-static-typing...

2% of bugs can be caught via static typing.

For your very simple example, your IDE can do that!

Re: Python's “disappointing” superpowers

#153

I maintain Python code bases for a living, and feel that the language has simply been pushed too far. Static typing in Python doesn't give you the advantage of actually static typing and even IDE support is -- well it's not terrible, just not great. The thing is, once we go through all this static typing exercise in Python, we get no performance advantages, and the whole thing seems bolted on, with worse semantics th…

Honestly, static typing encouraging data shape documentation alone makes it worth it to me. Yes, they're pretty hacky in Python and don't feel great, but I'm sure it'll continue to improve. I'm just so over having to guess what a function might accept or return. Life is too short to spend it constantly reverse engineering code because people can't be arsed to write proper documentation.

This would sum up my sentiment as well, just for documentation reasons alone it is wildly beneficial.

People who love dynamic typing seem to think their code is just “understandable” and it almost always isn’t

Re: Python's “disappointing” superpowers

#154

Earlier quoted context omitted.

Well a lot of people are claiming that static typing reduces bugs compared to dynamic typing, but I haven't seen from them a shred of evidence of this. When I go looking for myself what I found was studies saying that dynamic typing reduces development time by 2.5x and bugs per software feature by 2.5x. So perhaps one of these people claiming that static typing reduces bugs over dynamic typing, could provide the slig…

In the amount of time you’ve repeatedly said this all over this thread you could have provided a citation

Here: https://games.greggman.com/game/dynamic-typing-static-typing...

I think it's more effective to show that there is no evidence to contradict me first.

Re: Python's “disappointing” superpowers

#155

Earlier quoted context omitted.

> No citation is needed, it's fairly obvious to any experienced Python programmer. So you can't even explain it, despite claiming to be experienced. Why should I listen to you? Your whole response is just you saying "First off, you're wrong. Second off, I'm right." Here's a very simple example: I want to change a dict to a class. In untyped Python, how do you make sure that you make this change safely without introdu…

Here's a citation if it makes you happy: https://games.greggman.com/game/dynamic-typing-static-typing... 2% of bugs can be caught via static typing. For your very simple example, your IDE can do that!

Here is a study that show Python is more bug-prone and that TypeScript is far more reliable: https://danluu.com/empirical-pl/

That source shows why language studies are so difficult, and why it is hard to draw conclusions. For example, your study doesn't count KeyErrors or NoneType exceptions as type errors, but those count as well. There are other considerations: you're only looking at released projects which might have a ton of tests to balance the fact that they're dynamic. But there is absolutely no way you can say "dynamic languages are less buggy". There's no data for that.

> For your very simple example, your IDE can do that!

No it can't. An IDE doesn't help at all here, because it doesn't know where you passed around that dict, and where it was created. There's no type hints. That dict is now a class, and you have to go find where else you used it. If you don't use any type hints in Python, how would you find all those cases? You have to hunt for it yourself, grok the entire codebase (which you may not have worked in for a while), and then run it a ton of times to make sure you caught every edge case. Refactoring in Python is very time consuming and dangerous compared to typed languages.

Re: Python's “disappointing” superpowers

#156
His first example of python's Callable type-hinting not supporting keyword only arguments was true 5 years ago when type hinting was first catching on, but Protocols have existed since python 3.8 and they support keyword only arguments.

Re: Python's “disappointing” superpowers

#157

I kinda hope we can just let Python be Python: it’s in a global-ish maximum for what it’s for, and I suspect any big move away from that will make it worse overall. Obviously things like UTF-8 support, or maybe getting a clean lexical scope option, or other “fixes” are good. Performance improvements are good. But there are lots of mainstream languages that have mature static type systems, strong metaprogramming facil…

I still think python has a ton of headroom to grow. It's maxing out the data science space, and it does reasonably well in the web service space, but they really have not pushed very far into the distributable GUI and CLI space. Dependency, packaging, and distribution have been improving in leaps and bounds still for python, and type-hinting makes large projects manageable.

Re: Python's “disappointing” superpowers

#158

I used to be a huge dynamic languages fan, with python being my favorite language over the majority of my career. Then I worked on a large python project of ~100k LOC with a team of ten. That's when I realized that writing code faster isn't the problem. Reading it is, making changes to code someone else wrote is, and refactoring across dozens of modules is a problem. Static languages help a lot with all three. I stil…

This is almost always framed in a way that shows large systems need the extra rigidity of some static systems. And that dynamic systems are only about rapid prototyping.

I think that is a bit of a false framing. To wit, any system of 100k LOC will be hard to get into. Even harder to make changes in. There is no getting around that. None. Even worse if you have many entities flying about these 100k LOC. Each change to an entity will be dangerous. Static or dynamic. Especially if they are persisted anywhere, as at that point it is all too easy to get static guarantees that aren't reflecting actual data.

Re: Python's “disappointing” superpowers

#159

When I did most of my work in Python, typehints weren't a thing. I still feel like static typechecking is less useful in Python since its datamodel is overally less of a hot mess compared to Javascript for example. And Python modules/frameworks can be a lot more "typed" than you'd expect. Django models, forms etc offer more runtime validation than typesystems can easily achieve. Yes, at runtime. But between not havin…

> its datamodel is overally less of a hot mess compared to Javascript for example. I don't understand this, what do you mean? TypeScript is such a success partly because everything is an object in Javascript. There's no need to distinguish between classes and "dicts", as you have to with Python. Another example: Python functions have args and kwargs, which make typing significantly more complex (as the article points…

> Python functions have args and kwargs, which make typing significantly more complex

Not really. It's only complex when they're used with poor design decisions. There are plenty of languages that allow you to do things that aren't a good idea. Python is no exception. Type hinting just makes those shortcomings more readily apparent.

> Callable doesn't even support kwargs

PEP 544 and Protocols have existed for 5 years, and they support keyword only type hinting for callables.

Re: Python's “disappointing” superpowers

#160
post #151

Earlier quoted context omitted.

[flagged]

This is nearly impossible to precisely study: - Because correlation != causation, for one thing: 2.5x the number of bugs in static "style" code bases (not sure what that means) does not mean that static type systems lead to more bugs. It could be that users of dynamically typed languages find themselves needing robust automated tests more often, because they can't rely on static typings. This would suggest that in a…

[flagged]
Post reply on HN