4 ms·
I don't understand what value the dictionary is providing here, I suspect none? How is this better than just functions in a module? (import the module as math
by anentropic 3y ago
I don't understand what value the dictionary is providing here, I suspect none?
How is this better than just functions in a module? (import the module as math_exprs, use getattr)
- Znafon 3y agoYou could modify it easily, for example the user could register an additional function to the mapping. That would not be as easy to do with a module and getattr(). You can also list the registered function with math_exprs.keys() and that might not be as easy with a module either.
- anentropic 3y agoif all the keys are unknown until runtime then I guess the dict makes sense I don't think it makes much sense in the example code given
- llimllib 3y agoYou use it to dispatch to the appropriate function in a module based on the value of a runtime variable
- alanwreath 3y agothis. At least with the current example and even the surrounding chatter in this thread, I don’t see any benefit and plenty of room for downsides. Some of which haven’t even been mentioned yet (e.g how this will play with IDEs) I don’t mean to poo poo on it. I really do like learning new patterns, but I haven’t yet grasped this one’s utility.