Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Using == instead of === #16

Closed
twirl opened this issue Dec 23, 2014 · 5 comments
Closed

Using == instead of === #16

twirl opened this issue Dec 23, 2014 · 5 comments

Comments

@twirl
Copy link

twirl commented Dec 23, 2014

=== operator possesses additional semantics in JavaScript. It means ‘compare variables values AND compare variables types’. Using it in situations when types cannot differ (like typeof a === 'string') is just overloading code with meaningless semantics.
Our rule there is as follows: if function allows polymorphic behavior, i.e. function arguments could be of different types, then all arguments MUST be explicitly cast at variables initialization block at the beginning of the function. That strictly eliminates any need of checking types below that block, and any type checking simply means that you were too lazy to cast types explicitly.
I suggest to change this rule: if you need to check types, do it explicitly at the beginning of function or code block.

@ikokostya
Copy link
Contributor

all arguments MUST be explicitly cast

Operator == introduces implicit casts.

@twirl
Copy link
Author

twirl commented Dec 24, 2014

Follow the logic:
(a) all parameters must be explicitly cast before being used in any conditions;
(b) so there must be no difference whether you use == or === in conditions, since casting is already done;
(c) why using one more = sign?

@dmikis
Copy link
Contributor

dmikis commented Dec 24, 2014

You guys have core disagreement here: we never cast function arguments to types declared in documentation. We may normalise the arguments (i.e., remove optionals or assign defaults to them). Other than that we rely on user follows described function contract.

Yes, it may be bad for APIs such as Maps API, but it works pretty well for us.

@twirl
Copy link
Author

twirl commented Dec 25, 2014

You are saying that you don't use polymorphic functions. Either state this in a codestyle or provide guidance what to do in such case. Personally, I simply don't understand then why using === at all if you know all types at runtime (with possible exclusion for null, since it's an object — known language bug)/

@vtambourine
Copy link
Contributor

(c) why using one more = sign?

To avoid possible error and misuse.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants