Thread overview
is vs ==
Aug 31
monkyyy
6 days ago
IchorDev
6 days ago
H. S. Teoh
August 30

For the modern D developer, which is the more preferred choice, to use 'is' or '=='?

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

Or is either equally satisfactory?

August 31

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 '=='?

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

Or is either equally satisfactory?

different things is is mostly a special case like is null

6 days ago

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

6 days ago

On Saturday, 30 August 2025 at 22:15:26 UTC, Brother Bill wrote:

>

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

No: https://dlang.org/dstyle.html

>

For the modern D developer, which is the more preferred choice, to use 'is' or '=='?

This question doesn't make much sense. It's like if you asked the same thing about delegates vs functions.
is tells you if its operands are exact bit-for-bit matches, whereas == usually compares the contents of two things and may be overloaded using opCmp or opEquals.
For clarity's sake, is should generally be used for pointer comparison.

6 days ago
On Sat, Aug 30, 2025 at 10:15:26PM +0000, Brother Bill via Digitalmars-d-learn wrote:
> For the modern D developer, which is the more preferred choice, to use 'is' or '=='?
[...]

They have two different meanings.  `is` is for determining identity (is this the same variable); whereas `==` is for comparing values (do these two variables have the same value).  They are not interchangeable.


T

-- 
There are 10 kinds of people in the world: those who can count in binary, and those who can't.