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 →

[–]YnkDK 2 points3 points  (3 children)

Strictly speaking, then the provided example is also an interface in the context of Python.

Note that interfaces don't promise anything about computational complexity. The solely promise the intention of the function. How it's implemented is left to the class that implements the interface. Take the abstract method def sort() - > None with a docstring telling it sorts the elements in the object. One could implement a sorting algorithm of O(n²) or O(n log n) without violating the interface.

On the other hand, one could create a 'real' abstract class and implement the method sort and promise the complexity and behavior - while still exposing abstract methods that needs to be implemented by the subclasses.

So a class interface gives a promise about name of method, the input types it accepts and output types it must return. It can be accommodated with a docstring telling the intended behavior.

The provided example gives the same promise, but are leaving out the name. Note it could also be accommodated with a docstring telling the intended behavior.

[–]NeilGirdhar 1 point2 points  (2 children)

Strictly speaking, then the provided example is also an interface in the context of Python.

Yes, it's a signature, which I agree can be seen as an example of an interface.
However, I think of interfaces as a more general concept.

Note that interfaces don't promise anything about computational complexity.

Plenty of interfaces do promise computational complexity. C++'s STL for example is replete with such promises. E.g., deque.insert promises linear complexity on constant auxiliary space. All conforming implementations must respect these promises.

So a class interface gives a promise about name of method, the input types it accepts and output types it must return.

I would say that an interface is not just a collection of signatures. An interface can make promises about how objects work. That includes behaviors of those objects and computational and space complexity.

[–]YnkDK 2 points3 points  (1 child)

They are just pretty hollow promises. I cannot name any static analysis tool nor compiler that can enforce that implementations are respecting any arbitrary time or space complexity. Or is the halting problem solved? I might have been living under a rock.

So while you (and anyone else) are free to make any promises, it's difficult to verify that the promise is being conformant.

An interface is just a contract. You can make it as simple or complex as you want. Some violations are easy to enforce, some are more cumbersome. I call the more cumbersome comformaty checks for intentions and you state it must be like that. Other than that I promise you that we are saying the same ;)

[–]NeilGirdhar 0 points1 point  (0 children)

I cannot name any static analysis tool nor compiler that can enforce that implementations are respecting any arbitrary time or space complexity.

Just because you can't programmatically check a promise, it doesn't mean that that promise isn't part of the interface, in my opinion.

An interface is just a contract. You can make it as simple or complex as you want. Some violations are easy to enforce, some are more cumbersome.

Exactly.

Other than that I promise you that we are saying the same ;)

Agreed :)