3 ms·
> The if-statement example demonstrates precisely how OO classes can make code more complicated than it needs to be. does python have something like interfaces
by andrekandre 4y ago
> The if-statement example demonstrates precisely how OO classes can make code more complicated than it needs to be.
does python have something like interfaces/protocols?
i feel like something as easy as multiple loggers should just be as you say, a simple lambda, or an interface with a single function `log(string)`, then you don't need all those annoying if statements..
- michelpp 4y agoThe "Zope" interface model was proposed 21 years ago but not accepted: https://peps.python.org/pep-0245/ https://peps.python.org/pep-0245/
- andrekandre 4y agooh man... Rejection Notice I’m rejecting this PEP. It’s been five years now. While at some point I expect that Python will have interfaces, it would be naive to expect it to resemble the syntax in this PEP. Also, PEP 246 is being rejected in favor of something completely different; interfaces won’t play a role in adaptation or whatever will replace it. GvR. --- hmm, maybe someone should dust this off and give it another try...
- formerly_proven 4y agoYou can totally still use the zope.interface module or how it's called. But this was part of a phase in the late 90s / early 00s were Python coders from the zope-sphere of influence tried to imitate Java as much as possible, which is not where the community settled.
- jcheng 4y agoYes, since Python 3.8: https://peps.python.org/pep-0544/ https://peps.python.org/pep-0544/
- andrekandre 4y agonice!
- Groxx 4y agoGiven that python is entirely dynamically typed... it's completely unnecessary, python has been able to replace implementations of X with Y for essentially forever. Yes, there are tool-assisting type hint systems. But they're not part of the runtime. At runtime, if it quacks like a duck, it's a duck, and it matters not one bit what brand the duck is or how much of its innards match what you think ducks have inside them.