top | item 7827804

Python Programming for the Privileged Class

33 points| skfroi | 11 years ago |github.com

17 comments

order

jmpeax|11 years ago

One of the best type features of Go is the lack of need to do something like this: "@implements(IEatable)". If a class implements all of the methods of the interface, then it automatically implements that interface. Yuppy seems like a step backwards in OO in this regard.

RHSeeger|11 years ago

Is it possible to indicate, in an interface, that it's not a structural type? Ie, that classes need to specifically indicate they implement it to be considered it's type?

For example, the HtmlString interface could require only "toString" as a method, but not everything that has that method should be considered that type.

X-Istence|11 years ago

Thankfully in Python this isn't required either. Implement all of the methods of an interface and duck typing will take care of the rest for you...

asdfologist|11 years ago

Perhaps this is an unpopular opinion, but I think the Duck typing philosophy of Python is a feature, not a bug. Imposing the verbosity and rigidity of Java-style OO onto Python seems like a step backwards to me.

siliconc0w|11 years ago

I feel like one of the merits of python is the looseness of classes and multiple inheritance. You get the benefits of OO without some of the pitfalls. Sure, you can go through the effort of defining an abstract class but it often isn't needed since your object is often composed of a bunch of separate objects - dealing with a formal contract to some 'abstract' version of your object just adds boilerplate and ends up creating convoluted class hierarchies.

Myrmornis|11 years ago

It would be very helpful to add to the README a section explaining what problems this solves. So examples of conventional python classes exhibiting weaknesses that are improved by using yuppy features.

TTPrograms|11 years ago

I love Python and I love interfaces, so this appeals to me.

aeflash|11 years ago

But either way, you're going to get a runtime error. Languages like Java or C# that actually have real interfaces and abstract classes can detect these problems at compile time. This seems only marginally better.

X-Istence|11 years ago

This greatly reminds me of zope.interface!