
On Thursday, August 14, 2014 9:20 PM, Gregory P. Smith <greg@krypto.org> wrote:
On Thu Aug 14 2014 at 1:06:20 PM Dennis Brakhane <brakhane@googlemail.com> wrote:
My pet peeve of static languages is that programmers are often too fixated on their particular problem that they don't think about alternate uses for their code and make the type declarations uncessarily complex.
For example, in Java nearly every method in Java that deals with character strings uses "String" as parameter type, while they should have used "CharSequence". Having to read an entire input stream and storing it in a String just to be able to use a method is not fun (String is final in Java)
I'm worried that in Python we will have utility functions that declare they require a List[int], when in fact they actually only require a Sequence[int] or Sequence[Number].
This always happens, even in docstrings where people state types today. For example, I often correct people during code reviews to say sequence of instead of list of in docstrings. Nothing can really prevent that
We can't _prevent_ it, but we certainly can _drastically reduce_ it, just by not providing List[int]. Again, I think 90% or more of the uses of List[int] in type annotations will be incorrect. Why go out of our way to make things more complicated just so people can make more mistakes? If anyone really does need a list of ints, implementing List should be pretty simple (in fact, it might even just be `class List(MutableSequence, list): pass`). Why bend over backwards to make it easier for people to make mistakes?