On Thu, 04 Jul 2013 20:15:08 +0100, Dmitry Olshansky <dmitry.o...@gmail.com> wrote:

04-Jul-2013 19:00, Regan Heath пишет:
In fact, you can generalise further.

The meaning of if(x) is "compare the value of x with 0" (in C, C++, .. ).

The value of x for a pointer is the address to which it points.
The value of x for a class reference is the address of the class to
which it refers.

If D's arrays are reference types,

They are not. It's a half-reference no wonder it has a bit of schizophrenia now and then.

True. The struct which contains the ptr and length is actually a value type. I think conceptually however we should be thinking of them as reference types, because.. the array struct is effectively a lightweight wrapper (adding length) around a reference type (ptr).

  then IMO they should exhibit the same
behaviour.


The behavior should be the most useful and since arr.length != 0 is what 99% of time a programmer wants to check.

IMO, the behaviour should be consistent. If you code if (x) then the compiler will compare 'x' (not a property of x) to 0. Doing anything else would be inconsistent and unexpected to anyone from a C background.

If you mean to check arr.length, then code that explicitly. Coding if (arr) and having it check arr.length hides details which really should be visible for the programmer to see.

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to