is vs ==
Steven Schveighoffer
schveiguy at gmail.com
Sun Aug 31 02:11:50 UTC 2025
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
More information about the Digitalmars-d-learn
mailing list