More meaningful name for `invariant` function
See original GitHub issueI would like to have a more meaningful name for the function than invariant
. Something like throwOnFalsy
is for me easier to understand.
While working with developers that don’t know what tiny-invariant
is, I realized that is not easy understand at first sight what the invariant
function does. To improve this, it would be nice to rename the function with something more descriptive. I would still keep the original function to avoid breaking changes but also allow to import the new function with the descriptive name.
What do you think? Is throwOnFalsy
good for you or maybe you have a better name?
If you think it is a good idea, I would submit a PR for that.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Invariant (mathematics) - Wikipedia
In mathematics, an invariant is a property of a mathematical object which remains unchanged after operations or transformations of a certain type are ......
Read more >Immutable Values and Invariant Names - Musing Mortoray
Invariant names are available in Java with the 'final' keyword. The value to which a final variable refers can only be set during...
Read more >Invariant Assertions, Invariant Relations, and Invariant Functions
In other words, an invariant function is a total function V on S that satisfies the condition (T ∩ B)V ⊆ V ....
Read more >language agnostic - What is an invariant? - Stack Overflow
An invariant is more "conceptual" than a variable. In general, it's a property of the program state that is always true. A function...
Read more >Reading 13: Abstraction Functions & Rep Invariants
Resuming our discussion of what makes a good abstract data type, the final, and perhaps most important, property of a good abstract data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree entirely that
invariant
is not a great name. Personally, I thinkassert
would be a way clearer name thaninvariant
. However, leaning oninvariant
means that tooling that automatically allowsinvariant
messages to be stripped (eg https://www.npmjs.com/package/babel-plugin-dev-expression) just works™️Personally, I would like to see us move away from
invariant
towardsassert
. I am exploring making a new (ESM only) assert package: https://github.com/alexreardon/tiny-assertI guess this package
tiny-invariant
could just re-export the default function as a named exportassert
.So that people could do:
Autosuggestion and autoimport of IDEs (e.g. VS Code) would probably benefit from that.