[your code here]

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jan 30 00:48:37 UTC 2019


On Tuesday, January 29, 2019 4:45:58 PM MST Stefan Koch via Digitalmars-d 
wrote:
> On Tuesday, 29 January 2019 at 23:04:33 UTC, H. S. Teoh wrote:
> > On Tue, Jan 29, 2019 at 10:07:23PM +0000, Neia Neutuladh via
> >
> > Digitalmars-d wrote:
> >> On Tue, 29 Jan 2019 13:48:11 -0800, H. S. Teoh wrote:
> >> > On Tue, Jan 29, 2019 at 09:13:16PM +0000, qjnr via
> >> >
> >> > Digitalmars-d wrote:
> >> >>   if (args.length is 2)
> >> >>
> >> >                    ^^^^
> >> >
> >> > That's a syntax error.
> >>
> >> Compiles just fine on my end.
> >
> > But does it do what's intended, though?
> >
> >
> > T
>
> Yes.
>
> `is` is the same as `==` except for array and classes where it
> does pointer comparisons.
> since values like integers have no pointer identity.

That's not quite true. To be precise, is does a bitwise comparison. In the
case of integers, that's the same as ==, but for floating point values, it's
not the same (most notably with NaN). Also, it's definitely different for
structs. So, it's not just arrays and classes that differ for == and is.

For this code, both is or == would work, but it's certainly more idiomatic
to use == - to the point that if I saw someone using the is operator with
integers, I would be wondering if they understood what they were doing or
were trying to do something other than what they were actually doing.

- Jonathan M Davis





More information about the Digitalmars-d mailing list