News for hackers. Stuff that matters.
Re:Type hints – a mediocre programmer's reaction (2015) by marcosdumay on Thursday March 17, 2016 @04:57PM (#11307548)
Well, the problem is on annotating types, when you only actually care about behavior.

Duck typing isn't a bad thing. In fact, it's great. You just need to annotate the ducks instead of the types. For a great example of how to do it, look at Haskell's type classes.

(In fact, Haskell's easyness of integrating generic code is visible even to a beginner, but I never notice that this is because the entire language is based on duck typing.)

Re:Type hints – a mediocre programmer's reaction (2015) by aplusbi on Thursday March 17, 2016 @07:51PM (#11308659)
To be pedantic, Haskell technically doesn't use duck typing, it uses structural typing. Duck typing is run-time coercion of types, structural typing is compile-time inference of minimum interfaces.
Re:Type hints – a mediocre programmer's reaction (2015) by marcosdumay on Thursday March 17, 2016 @08:48PM (#11309004)
Noticed.

Interface based typing may be a better generic term.

Re:Type hints – a mediocre programmer's reaction (2015) by thristian on Thursday March 17, 2016 @06:43PM (#11308235)
Yeah, I immediately thought of Rust traits, which I hear are very like typeclasses. Python already has something like these, in the form of Abstract Base Classes: collections.Callable for function-like things, collections.Iterable for things that conform to the iterator protocol... But if gradual typing is to be useful, it really needs ABCs for all the common ducks that Python code uses: file-like objects, things that dict() can convert into a dictionary, things that can be converted into strings...
Re:Type hints – a mediocre programmer's reaction (2015) by justanotherbody on Thursday March 17, 2016 @08:07PM (#11308747)
I'm not sure any committee could agree as to what defines a filelike object (does it implement seek?)

In addition you'd need an IRO (interface resolution order) if you truly intended to prove everything would work

To say nothing of accidentally implementing an interface and getting an error because if it

Doesn't sound like my kind of python...

Re:Type hints – a mediocre programmer's reaction (2015) by aidenn0 on Friday March 18, 2016 @12:23AM (#11309888)
You have a seekable filelike interface that is a superset of the base filelike interface.
Re:Type hints – a mediocre programmer's reaction (2015) by Retra on Thursday March 17, 2016 @09:35PM (#11309209)
>I'm not sure any committee could agree as to what defines a filelike object (does it implement seek?)

You step back a layer of abstraction. Maybe it implements seek, maybe it doesn't. Either way it implements has_seek.

Re:Type hints – a mediocre programmer's reaction (2015) by jstimpfle on Thursday March 17, 2016 @05:55PM (#11307949)
Well... either your library invents its own type classes, and all client code must implement them (boilerplate!). Or it relies on agreed-upon type classes which come from another library. If it's not basic classes like Functor or Monad that's just not manageable (dependency hell!).
Re:Type hints – a mediocre programmer's reaction (2015) by marcosdumay on Thursday March 17, 2016 @06:17PM (#11308071)
Dependency hell is the situation where A depends on both B and C, but B depends on D, and C depends on D', where D and D' are not compatible.

Type classes absolutely do not create this kind of situation, as they are duck typing. But modules do create it, so it happens both on Haskell and on Python.

Now, in practice you use both, basic classes and library specific ones. And yes, if you want to create some behavior, you'll need to implement the specific code that enables it. You do not escape from that in Python either.

Re:Type hints – a mediocre programmer's reaction (2015) by jstimpfle on Thursday March 17, 2016 @06:46PM (#11308249)
I know dependency hell when I see it. It's already bothersome if I can't just apt-get install the right library version because another package depends on a conflicting version, or the latest boost version isn't available yet. I refuse to learn tools like pip or stack for every language I use, and to create sandboxes for new projects only to get the latest library versions. That's just never going to be portable software.

You can actually escape dependency hell for most APIs. That's the Unix culture of using plain text (read: very simple data types -- in C that would be arrays and structures of integral types) for communication.

Of course that won't work for libraries that provide transformations on parameterized structures. But let's face it, there's no point in depending on a Monad library just to save two lines of pure code.