Change store default suffix to: '', rather than: 'Store'; for better code comprehension and search #2018
jimattakeda
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
After many years of programming, in a diverse variety of languages, I have come to the firm conclusion that dynamically constructing identifiers (in a program) is a bad idea. My justification for this stance is:
grep
) cannot be used to find any of the references to a given identifier.id: 'myStore'
) get mangled [1] into something else (presumably:"myStoreStore"
, in this case, is: confusing, in general, and is particularly problematic for programmers who are un-familiar with Pinia (i.e., new team members, or a programmer who is unfamiliar with a project, but needs to do emergency technical support on that project).My proposal: change the Pinia store creation/access logic so that the default suffix is just an empty string: ''. I realize that this would be a breaking change, for existing code, so this change might need to go through a typical: announcement, deprecation, actual change, cycle. And that would take longer to happen. But I think it is still well worth it.
Before someone mentions it: yes, I am aware of the existing Pinia
setMapStoreSuffix()
function [3]. However, I do not consider that facility an acceptable substitute for what this proposal is asking for. It looks like a leaky abstraction, combining: TypeScript interfaces, redundant values (e.g., ''foo' for the suffix setting, and 'foo' for the interface; module declaration, and (possibly) ensuring that the code flow is in a certain order, i.e.,setMapStoreSuffix()
-->createPinia()
-->declare module 'pinia'
.Also, as additional, personal, personal motivation for this proposal, I have just spent several hours trying to get
setMapStoreSuffix()
to do what I want--but to no avail (and, NO, this is NOT a request for debugging assistance, it IS an experience report from a very experienced programmer).Further, constructive discussion is welcome.
[1] I'm using "mangled" in a technical sense here (e.g., C++ name mangling); and NOT a pejorative sense.
[2] https://www.karlton.org/2017/12/naming-things-hard/
[3] https://pinia.vuejs.org/cookbook/options-api.html#usage-without-setup
Beta Was this translation helpful? Give feedback.
All reactions