Live data from Hacker News

Python Programming for the Privileged Class

github.com

1–10 of 18 posts

Re: Python Programming for the Privileged Class

#3
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.

Re: Python Programming for the Privileged Class

#5
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.

Re: Python Programming for the Privileged Class

#7

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

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.

Re: Python Programming for the Privileged Class

#8
This is very reminiscent of zope.interface used in Twisted. I wouldn't want to argue for or against it, but I've had times when something like this might have been useful in large code bases.

[1]: http://docs.zope.org/zope.interface/ [2]: http://twistedmatrix.com/documents/14.0.0/core/howto/compone...

Re: Python Programming for the Privileged Class

#9
post #3

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.

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.

Re: Python Programming for the Privileged Class

#10
post #3

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.

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...
Post reply on HN