-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refacto] DRY for module/extensions method #461
Conversation
I was thinking about something similar, but instead of checking for the module/extension hooks at runtime, I would have used lists compiled during bootup. |
dcb4d32
to
b960a56
Compare
I just repush with a fix, I got mixed up in my branch..
Not sure of what you are saying here, the module/extensions methods are not touched and the dispatch is still triggered by a method in KMKKeyboard.
This is not a misuse of introspection to me as it is precisely a perfect use case for it. If you don't use Side note: I don't really see how using lists built at boot would allow you to reduce the repetitive code without also refering the function by their name somehow.. You will reduce each KMKKeyboard function I removed by some lines sure, but you will still have the 6 functions differing only by the module method ? |
The precompiled lists would get around repeated runtime checks for immutable data. Doesn't concern introspection. I was thinking about CPython were you can query |
I am extremely against this style in any language (my day job is Ruby and I caution against |
I think if we want to reduce code here, the trick is probably to add a wrapper method that handles the try/catch stuff and accepts a debug error string, a reference to a method to call, and |
Ok, I could argue some of those points, but I'm not sure it is worthwhile to spent more time on this as It seems a lost cause given the global opinion. |
I opened a linked issue, because I think the general intent is still worthwile investigating. |
Remove a big chunk of repetitive code.
Note: in the meantime I made the function lookup before calling it. That makes it unnecessary to define all the Module method in all module.
Imho, It makes no sense to force the definition of
on_powersave_disable
for example for module that have no relation at all with power... A module should be required to define only what it needs.I pushed only this first to get the discussion going but what can come with this is: