question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More meaningful name for `invariant` function

See original GitHub issue

I 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:open
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alexreardoncommented, Oct 28, 2022

I agree entirely that invariant is not a great name. Personally, I think assert would be a way clearer name than invariant. However, leaning on invariant means that tooling that automatically allows invariant 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 towards assert. I am exploring making a new (ESM only) assert package: https://github.com/alexreardon/tiny-assert

1reaction
pkerschbaumcommented, Nov 6, 2022

I guess this package tiny-invariant could just re-export the default function as a named export assert.
So that people could do:

import { assert } from 'tiny-invariant';

Autosuggestion and autoimport of IDEs (e.g. VS Code) would probably benefit from that.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found