Git Product home page Git Product logo

Comments (2)

soc avatar soc commented on May 5, 2024

With #29 and #31 done, I think it makes sense to think whether it's possible to increase the consistency of === and ==:

The problem I see is that === can be used everywhere, including in generic contexts, while == requires Equals.

I am concerned that this (slight) convenience could make users use === in cases where == would be correct.

A rather brute approach would be:

  • Give === its own trait (e. g. Identity) that is implemented for every type and cannot be defined by a user.
  • In addition to Equals being defined for non-reference types, automatically derive == (Equals) for all reference types according to the following rules:
    • Equality would be based on calling == on all fields of a class, similar to Scala's case classes, Kotlin's data classes, C#'s record types and Java's proposed record classes.
    • To avoid the problems immediately cropping up with sub-classing, sub-classing would be discarded altogether, leaving only traits for polymorphism.
    • If a class implements Equals explicitly, this definition will be used and no equality operation would be derived.
    • Introduce annotations to let users
      • opt out of equality, e. g. @noEquals class Foo(let x: int) {}, or
      • adjust how equality is derived, e. g. class Foo(let x: int, @ignoreForEquals let y: int) {} would only use x to derive equality
    • If a class A contains a field of type B which does not support equality (the user has annotated the class B with @noEquals) then an error is reported, which can be fixed by:
      • adding @noEquals to A
      • ignoring the field with @ignoreForEquals
  • In the future if something like lambdas or function types were added, they would either:
    • not implement Equals, or
    • implement Equals in terms of Identity

What do you think, @dinfuehr?

from dora.

soc avatar soc commented on May 5, 2024

I think this can be closed as fixed; I'll file issues/questions that arise from e. g. value types, code generation desires, or meta programming topics when we cross that particular bridge.

from dora.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.