-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Refactor to delete every modules keeper/hooks.go file #12079
Comments
To be clear, I'm not fully convinced on the correctness of the deleting I do think deleting the keeper/hooks.go is a clear win, and will also force improvement in the API abstractions in various testing code. |
Just because code of similar or identical structure exists in more than one place doesn't mean it's "boilerplate", and even if code is "boilerplate" that doesn't necessarily have a negative effect on a codebase. A little copying is better than a little dependency. Your proposed solutions rely on reflection, which should be avoided unless absolutely necessary. In fact, reflection-based code is generally far more deleterious to cognitive complexity than boilerplate! Reflection is never clear. |
agree here!! im a fan of doing it |
Only the |
A reminder to everyone that we have already agreed in prior discussions that #9656 is the long-term replacement for hooks |
while this is the long term solution I think removing some boiler plate today is a fine solution. If it takes longer than a day, which it shouldn't, then its a small win. |
Summary
~Every module has many lines of code of pure boilerplate around hooks. This is two-fold:
MultiStakingHooks.go
file, that just callsProblem Definition
These are two files in every module, contributing to the overall boilerplate and cognitive overhead of the SDK. If we fix this, were saving 1000+ LOC across cosmos
Proposal
Eliminate keeper/hooks.go
This seems more straightforward, make the default value for
keeper.hooks{}
a non-nil no-op multi-hook. Then make every call just usek.hooks.{hook name}
rather thank.{hook name}
Eliminate types/hooks.go
This one I'm less sure on how to do. If anyone has ideas would love to know. At minimum, we can make every multi-hook function a one-liner, rather than a 6 liner, by just using a helper function
Map
of typeinterface{}
. See https://blog.burntsushi.net/type-parametric-functions-golang/ inReflection in Go 1.0.x
.Then you combine that with run-time reflection to call a function on the struct by human readable name (https://stackoverflow.com/questions/8103617/call-a-struct-and-its-method-by-name-in-go), and the args.
One can either use generics to make the
Map
function expect a slice as typeh
or use generics for it.So then what this would transform into is:
before:
after:
For Admin Use
The text was updated successfully, but these errors were encountered: