Comments (5)
I just received another proposal for the naming to mitigate the breaking change on equals
.
The new name suggested was looselyEquals
or sameValue
in opposition to strict
. (alternative names: equalsLoosely
/ equalsLoose
/ looseEquals
).
References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
https://tc39.es/ecma262/#sec-islooselyequal
https://tc39.es/ecma262/#sec-samevalue
from bigdecimal.js.
I liked the idea of extending the API. We can certainly add them.
If the intention is to keep the API closely related to the JAVA implementation, it is also perfectly fine to find a different alternative for the === alias. (ex: sameAs, eq, etc...)
Since this library is ported from Java, diverging from it too much will cause confusion. Let me think what we can do about equals
.
from bigdecimal.js.
Hi!
I gave some more thoughts on the equals
issue.
Concerning my current stance, I think having equals
and strictEquals
is still a better approach for this library even if it means to draw apart from Java. It would require adding an explanation (and probably a link) to map the JS strictEquals
to the Java equals
.
I also think the JS community is already very familiar with the difference between == vs ===
, (assert equals, etc...) which is a recurring problem in weakly typed language like JS.
And so mapping ==
to equals
and ===
to strictEquals
seems more fitting.
Another point I would like to add: If operator overloading is added to Javascript one day, this will allow the following notations:
Big("2.0") == 2 // true
Big("2.0") == Big("2.00") // true
Big("2.0") >= 2 // true
Big("2.0") === 2 // false
Big("2.0") === Big("2.00") // false
Big("2.00") === Big("2.00") // true
It won't happen soon though as the proposal will take some time before even being considered for stage 2 (the maintainer seems to be taking a break from TC39). -- and Decimal will be released by then.
I also added a new suggestion to the list of alternatives names: equivalent (equiv) which I think represent the ==
idea above pretty well (better than sameAs
in my opinion)
from bigdecimal.js.
I think we can add eq
as an alias to equals
and make equals
method less strict, i.e only compare the value, not the scale. This is a breaking change though.
I am not sure with the name though. I think equalsStrict
is a better name than strictEquals
, because with autocompletion, both will be seen by the users.equalsIncludingScale
is definitely feels a bit long. equalsWithScale
is another alternative. However, equalsStrict
may be a better name. The only issue with it is that the intention about being strict may not be obvious by reading its name. I like method names with clear intentions like equalsSameScale
.
from bigdecimal.js.
First of all, I would like to come back on my previous comment.
After reading this issue, I think my example deosn't work well with the current usage of JS, it should probably become:
Big("2.0") === 2 // false
Big("2.0") === Big("2.00") // true
Big("2.00") === Big("2.00") // true
Big("2.0") ==== Big("2.00") // false
Big("2.00") ==== Big("2.00") // true
As most linter recommend ===
over ==
by default. And I think developers would also prefer 2.0
to be equal to 2.00
in most cases. It seems logical to avoid checking the scale when using ===
.
The new operator ====
in the list above would then do the same thing as ===
+ compare the scale just like the current equals
.
Anyway, first of all, I really like your point on autocompletion and definitely share your point of view on having a method names with clear intentions.
Of all the propositions listed so far, I think equalsStrict
might be the best as it infers a stronger check on BigDecimal's inner values compared to equals
.
equalsWithScale
is also nice. But I'm a bit concerned as we can also interpret the new equals
being the same as equalsWithoutScale
(I might overthink this one). I was also thinking of simply replacing Scale
by Precision
which should make it easier to understand ?
Concerning equalsSameScale
, in addition of having two words sharing the same meaning, At first glance it can be mistaken to a function used only to compare scale
values.
I have a few other names to suggest very similar to equalsStrict
:
equalsPrecise(ly)
equalsExact(ly)
from bigdecimal.js.
Related Issues (9)
- ES Modules HOT 2
- No identifiers allowed directly after numeric literal HOT 13
- Add markdown link checker to avoid broken links HOT 4
- Fix doc
- Big(1).divideWithMathContext(Big(3), new MC(0, RoundingMode.CEILING)).numberValue() HOT 2
- Make `add`, `subtract`, `multiply`, `divide` & `compareTo` handle `any` HOT 2
- Create a bigdecimal-light.js HOT 4
- "Can't find variable: BigInt" error thrown on Safari 13 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigdecimal.js.