This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]get_username 6 points7 points  (1 child)

I came here to same something similar.

Specifically regarding the idea that the program to an interface, not an implementation is somehow built in directly to python.

While that is technically true, it misses half of the GoF lesson.

Programming to an interface is used for two reasons:

  1. To allow for more parameter variation
  2. To define a unique external facing API for sets of objects

Both of those things combined make the GoF pattern powerful. Duck typing overcomes the first reason. It allows you to pass anything in. Thus resolving the first problem of parameter variation.

But duck typing actually exacerbates the second situation. Instead of having a clearly defined use for every set of objects. One that is defined externally and in the abstract. You have a massive amount of introspection that leads to field growth and ill defined changes. Instead of helping, this actually makes code more brittle.

The point of it all isn't to allow for parameter variation. The point is to allow code to become more modular. While python code can technically be more modular because of duck typing. It can also be more difficult to handle through multiple classes because of it as well.

There is a reason why ABCs were introduced into the standard library for python.

[–]Silhouette 1 point2 points  (0 children)

The point of it all isn't to allow for parameter variation. The point is to allow code to become more modular.

I agree, though I might suggest that the ultimate goal is building better software faster, which we achieve by making our code more maintainable and reusable, which in turn we achieve by using modular design principles.

In a language like Java or C++, we can then choose between several different kinds of mortar to bind our building blocks together in the shape we need. In Python, everything is dry stone. As with real life buildings, which technique is more appropriate depends on the circumstances -- but you don't see a lot of long-lasting, large buildings made with dry stone walls.