On Saturday, 30 August 2025 at 22:15:26 UTC, Brother Bill wrote:
For the modern D developer, which is the more preferred choice, to use 'is' or '=='?

`is` will do a direct bitwise comparison of the two sides, and cannot be hooked with an operator overload. This tests for *identity* (are the two sides the same instance).

`==` will use a type-specific comparison controlled by either the lhs type or the rhs type. This tests for *logical equality*.

Do the Style Guidelines or other authorities prefer one to the other for modern D coding?

Or is either equally satisfactory?

For value types that do not hook logical equality, `is` and `==` can be the same operation. There are some exceptions, for example floating-point numbers.

`is` is generally preferred for pointer or reference comparisons.

-Steve
  • is vs == Brother Bill via Digitalmars-d-learn
    • Re: is vs == monkyyy via Digitalmars-d-learn
    • Re: is vs == Steven Schveighoffer via Digitalmars-d-learn
    • Re: is vs == IchorDev via Digitalmars-d-learn
    • Re: is vs == H. S. Teoh via Digitalmars-d-learn

Reply via email to