Nibiru Chain: The breakthrough smart contract platform ushering in the next era of money. Nibiru powers an ecosystem of dApps including perps, RWAs, and more.
In older Cosmos-SDK versions, it was common to import the publicly exposed types
from a module by adding a "types" suffix to the package name. For example,
[Expand Task Menu]
- [ ] refactor(devgas): For #1866
- [ ] refactor(evm): For #1866
- [ ] refactor(epochs): For #1866
- [ ] refactor(genmsg): For #1866
- [ ] refactor(inflation): For #1866
- [ ] refactor(oracle): For #1866
- [ ] refactor(sudo): For #1866
- [ ] refactor(tokenfactory): For #1866
Implications
This means that the true package name, "types", has to be overwritten with an
alias for each import. The Golang LSP (what your IDE understands) still considers
all of the packages as having the name "types", so your IDE will only suggest
variables if you start typing "types". You can't just type "banktypes" in a new
file and see code suggestions.
When you use types from two modules at the same time or read code from within
a module, you'll see a nonsemantic prefix, "types" everywhere. Essentially,
package namespacing becomes irrelevant with this approach.
Suggestion
Follow the pattern of the nibiru/eth and nibiru/x/evm packages (also the
convention from v0.50 of the Cosmos-SDK) by using the top-level package of a
module for its types.
In other words, use bank.MsgSend instead of types.MsgSend or
banktypes.MsgSend.
Support Points:
Less namespace collisions: The module namespace is often completely unused aside from
one place, which is the top-level "app" directory.
IDEs become more useful: You can type a module's name and have your IDE automatically suggest its types
Less aliasing: Using an alias for every import produces a bad code smell (opinionated take).
"Using a generic name makes it easy to accidentally use the wrong value in
a different file" - [Uber Golang Style Guide]
I'd argue that this argument holds for imports and not just for other
variables.
Context
In older Cosmos-SDK versions, it was common to import the publicly exposed types from a module by adding a "types" suffix to the package name. For example,
Task List
[Expand Task Menu]
- [ ] refactor(devgas): For #1866 - [ ] refactor(evm): For #1866 - [ ] refactor(epochs): For #1866 - [ ] refactor(genmsg): For #1866 - [ ] refactor(inflation): For #1866 - [ ] refactor(oracle): For #1866 - [ ] refactor(sudo): For #1866 - [ ] refactor(tokenfactory): For #1866Implications
This means that the true package name, "types", has to be overwritten with an alias for each import. The Golang LSP (what your IDE understands) still considers all of the packages as having the name "types", so your IDE will only suggest variables if you start typing "types". You can't just type "banktypes" in a new file and see code suggestions.
When you use types from two modules at the same time or read code from within a module, you'll see a nonsemantic prefix, "types" everywhere. Essentially, package namespacing becomes irrelevant with this approach.
Suggestion
Follow the pattern of the
nibiru/eth
andnibiru/x/evm
packages (also the convention from v0.50 of the Cosmos-SDK) by using the top-level package of a module for its types.In other words, use
bank.MsgSend
instead oftypes.MsgSend
orbanktypes.MsgSend
.Support Points:
Less namespace collisions: The module namespace is often completely unused aside from one place, which is the top-level "app" directory.
IDEs become more useful: You can type a module's name and have your IDE automatically suggest its types
Less aliasing: Using an alias for every import produces a bad code smell (opinionated take).
I'd argue that this argument holds for imports and not just for other variables.