Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Wildcard suggestion - new ==== and >=== operators #48

Open

Description

@suspiciousfellow

Most linting rules, good practice guidelines, etc attempt to avoid == due to its confusing semantics.

Overloading the strict equality operator is out because it's going to break stuff.

How about a new operator ==== that acts like === with the exception that it can be overloaded for two objects with same prototype?

Thus example in the PR would become

// Usage example
import Decimal from "./decimal.mjs";
with operators from Decimal;  // Enable operator overloading for decimals
                              // Declaration may use some other syntax

Decimal(1) + Decimal(2)       // ==> Decimal(3)
Decimal(3) * Decimal(2)       // ==> Decimal(6)
Decimal(1) == Decimal(1)      // ==> true
Decimal(1) == 1               // ==> true
1 == Decimal(1)               // ==> true
1 ==== 1                      // ==> true
1 ==== Decimal(1)             // ==> false
Decimal(1) ==== Decimal(1)    // ==> true
Decimal(1) === 1              // ==> false (not overloadable)

Activity

  1. cshaa commented on Aug 13, 2021

    @cshaa

    What's wrong with overloading == and !=? If you can change what that operator does, its current behavior isn't going to be a problem. The ==== operator you propose, apart from being excessively long, makes the impression of being more strict than ===, which would be very misleading if you overload it to be less strict.

  2. suspiciousfellow commented on Aug 18, 2021

    @suspiciousfellow
    Author

    The issue with using the existing operator isn't its behaviour when overloaded - it's its behaviour with existing types (the issues here are well known).

    Point taken on the potentially misleading impression though. Not sure what to suggest there, not enough symbols on the keyboard...

  3. Rudxain commented on Jul 24, 2022

    @Rudxain
    Contributor

    not enough symbols on the keyboard...

    Maybe =@=, =#=, =$=, =?= ? The rationale behind using a special symbol between the =s is to avoid ambiguity with assignment ops

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions