Comment by ThePadawan
3 years ago
> Something that can't be accomplish more coherently with a simple function?
I think an example of `Iterable` (sort of like the one in the article) is a very ham-fisted way of getting this sort of check into Python code.
In the end, doesn't the difference just boil down to
class Iterable(ABC):
@classmethod
def __subclasshook__(cls, C):
return hasattr(C, "__iter__")
vs.
def is_iterable(t: Type):
return hasattr(t, "__iter__")
Where the first makes it harder to use `Iterable` incorrectly (i.e. supplying a non-type as parameter).
I can imagine that a Java or C# programmer would call the first version more "coherent" because it gives the interface `Iterable` a name explicitly.
Sort of like there's not reaaaaally a reason to use Extension Methods in C# (of course there are, but in a lot of simple scenarios there aren't) as opposed to static methods taking a Type as single parameter.
The difference is that if the first one is defined, it can be used like this without cluttering up the function body:
> Sort of like there's not reaaaaally a reason to use Extension Methods in C#
“but it will be so cool!” worked for me :)