6 ms·
> For example, you basically never care whether something is exactly of type list, you care about things like whether you can iterate over it or index into it.
by anderskaseorg 4y ago
> For example, you basically never care whether something is exactly of type list, you care about things like whether you can iterate over it or index into it.
This is an odd complaint. typing.Sequence[T] has been there since the first iteration of typing (3.5), for exactly that use case, along with many related collection types.
https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html
mypy isn’t perfect, but it’s sure better than making things up without any checks; you’re going to want it for all but the smallest projects.
- ReflectedImage 4y agoYou should never be using static typing with a scripting language like Python or Ruby. Dynamically typed code is 1/3rd the size of statically typed code, that means that one developer who is using dynamic typing is equivalent to 3 developers using statically typed code via MyPy. Since the code is 1/3rd of the size it contains 1/3rd of the bugs. This is confirmed by all the studies that have been done on the topic. If you use a static type checking with Python, you have increased your development time by 3 and your bug count by 3. Static typing's advantage is that the code runs a lot faster but that's only true if the language itself is statically typed. So with Python you have just screwed up.
- bombolo 4y ago> Dynamically typed code is 1/3rd the size of statically typed code, This is absolutely not true. > Since the code is 1/3rd of the size it contains 1/3rd of the bugs. That is made up and contrary to all empirical evidence I've ever collected. I'd be curious if you have a source, but I doubt it.
- ReflectedImage 4y agoAnyone with experience of writing both dynamic typed and statically typed can tell you that. Infact, you could just try it out for yourself. But here is your internet source for this blatantly obvious fact: https://games.greggman.com/game/dynamic-typing-static-typing/ https://games.greggman.com/game/dynamic-typing-static-typing...
- bombolo 4y agoI do have such experience and I really can't tell that. Which is why I wondered if anyone else was in fact saying that. > But here is your internet source for this blatantly obvious fact: https://games.greggman.com/game/dynamic-typing-static-typing https://games.greggman.com/game/dynamic-typing-static-typing... Ah no I meant a proper peer reviewed source. The claim that untyped code has fewer bugs is completely bonkers, so I was quite sure that no such source existed. Why do you think microsoft, google and facebook are all in the business of typechecking python? If typechecking would actually introduce bugs, it'd be better not doing it right? Using github for statistics is flawed. There are millions of 10 line js libraries. Yes it's easy to not make type mistakes in 10 lines. I suppose that type errors increase more than linearly with size.
- ReflectedImage 4y ago"The claim that untyped code has fewer bugs is completely bonkers" There are plenty of academic sources that will tell you that the number of bugs in a program is directly proportional to the number of lines in the program and static typing has no effect on this. https://stackoverflow.com/questions/2898571/basis-for-claim-that-the-number-of-bugs-per-line-of-code-is-constant-regardless https://stackoverflow.com/questions/2898571/basis-for-claim-... Additionally, statically typed code involves large amounts of boilerplate code in the form of abstract base classes, interfaces, generics, templating, etc. It's a very verbose code style. It's your turn, find an academic source to backup your claim that static typing reduces the number of bugs. Cause it just isn't true. Microsoft, google and Facebook have a lot of programmers coming from languages with static typing and want to make Python more familiar. It's a far distance away from anything resembling good practice. Actual Python houses typically don't use static typing.
- bombolo 4y agoPlease don't reply multiple times to the same thing. > Actual Python houses typically don't use static typing. If you had ever developed python professionally, you'd know this to be untrue. Also your "paper" points to a 404 page.
- TrickardRixx 4y agoPlease see Raymond Hettinger's keynote on efficiently handling bugs[0]. He makes the case that static type checking is a boon for Python except for in specific programs that make extensive use of covariant and/or contravariant types. [0] https://www.youtube.com/watch?v=ARKbfWk4Xyw https://www.youtube.com/watch?v=ARKbfWk4Xyw
- ReflectedImage 4y agoIncreasing the time to market by a factor of 3 is never worth it.
- dragonwriter 4y ago> You should never be using static typing with a scripting language like Python or Ruby. You should use it where it makes sense, and not where it doesn’t. I haven’t used any of Ruby’s type checkers, but Python makes this easy enough; make what has a reason to be dynamic dynamic, and have static safety rails everywhere else. (This is true with many “statically typed” languages that have dynamic escape hatches, too, not just traditionally “scripting” languages.)