digitalmars.D.learn - is vs ==
- Brother Bill (5/5) Aug 30 For the modern D developer, which is the more preferred choice,
 - monkyyy (2/7) Aug 30 different things `is` is mostly a special case like `is null`
 - Steven Schveighoffer (11/16) Aug 30 `is` will do a direct bitwise comparison of the two sides, and
 - IchorDev (9/13) Aug 31 This question doesn't make much sense. It's like if you asked the
 - H. S. Teoh (8/10) Aug 31 [...]
 
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?
 Aug 30
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`
 Aug 30
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
 Aug 30
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.htmlFor 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.
 Aug 31
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.
 Aug 31








 
 
 
 monkyyy <crazymonkyyy gmail.com> 