2 ms·
I see the problem when using third-party libraries, but if I was designing my own... Objects are pretty cheap in python: class Somebutton(Button):
by viraptor 17y ago
I see the problem when using third-party libraries, but if I was designing my own... Objects are pretty cheap in python:
class Somebutton(Button):
def onClick(self):
.....
def onSomethingElse(self):
.....
only one line of overhead (class line). And I'm pretty sure you can hack __dict__ in init, or use metaclasses so that the events are chained automatically, even without calling `Button.onClick(self)`. You can construct / add the object to it's container the same way (Somebutton(), instead of Button())
- 0x44 17y agoShould you have to hack __dict__ in init to get functionality that would be more easily/clearly expressed using an anonymous function?
- moe 17y agoNot trying to defend python's decision here but I have honestly yet to see an example where anonymous function really led to better code. In my experience (mostly JS and AS) they rather usually lead to little pieces of logic scattered all over the place and insufficient decoupling.