Reddit: why aren't people using D?

Bill Baxter wbaxter at gmail.com
Thu Jul 23 17:33:25 PDT 2009


On Thu, Jul 23, 2009 at 5:20 PM, Rainer Deyke<rainerd at eldwood.com> wrote:
> Walter Bright wrote:
> I don't see what's confusing about this.
>
> Most iostreams are non-copyable, i.e. the following just plain doesn't
> compile:
>  stream_type a;
>  stream_type b = a;
>
> Iostreams are not reference types, at all.  It's not possible for one
> iostream to (accidentally or intentionally) alias another iostream.
> There are not idiomatically allocated with 'new'.  Therefore they avoid
> the problems of having reference types in the language.

I don't get your meaning in that last sentence.  What's the problem of
having reference types in the language?  C++ has reference types in
the language -- T&.  If you just mean it's not possible to forget to
deallocate on scope exit, then you just need to use "scope" in D to
get that effect.  Or an explicit "scope(exit)" clause.

> Long distance
> bugs with iostreams are highly unlikely.
>
> Iostreams are passed as references - real references, with the 'T&'
> syntax, equivalent to 'ref T' in D - because that's the only way to pass
> them around.  The callee always knows they are receiving a reference,
> because the '&' is an explicit part of the function signature.

Seems like scope handles most of this just fine.  Except the case
where you want to have an iostream as part of a larger class.  But
then that larger class is probably going to need deterministic
destruction too, so wherever it's used it should probably be scope'ed
also.

--bb



More information about the Digitalmars-d mailing list