News for hackers. Stuff that matters.
Re:The Python dictionary dispatch pattern by b0b10101 on Tuesday August 29, 2023 @08:32AM (#37306772)
It's a favourite pattern of mine too.

I'm pretty sure it's bad practice but in one project i needed some form of parameterised extensibility (parsing a broad mix of files onto a standard format). So what i did was have other devs subclass an abstract base class I created (with some predefined attributes and methods to fill in) and then generated my execution dictionary based on the attributes of the subclasses of the base class.

Re:The Python dictionary dispatch pattern by sanderjd on Tuesday August 29, 2023 @08:37AM (#37306836)
This doesn't sound like a bad pattern to me. (Though I certainly think I have seen bad implementations of it.)

But if the keys are known statically (as in the article), I think it's generally better to use named functions.

But it's good to be aware of the capability, for cases like you're describing.