Auto syntax REALLY revisited
Georg Wrede
georg.wrede at nospam.org
Tue Feb 21 06:08:01 PST 2006
Mike Capp wrote:
> Georg Wrede says...
>
>>> I want another word substituted for 'auto'! We can't have it mean
>>> "autotype and/or RAII", at the same time. That is just too much
>>> of a disgrace.
>
> Amen.
>
>> To summarize:
>>
>> It would be handy to have a class that _requires_ RR instantiation.
>
> And it's not that big a leap. Currently I believe you can declare a
> class "auto" to force all instances to be auto; you'd just have to
> beef up this rule to say that ONLY instances of auto classes can be
> declared auto.
How about file descriptors and the like? I think there's a lot of stuff
that will sometimes be "auto" and sometimes not. It all depends on the
local needs in code. Opening a socket in a function call, and passing
its reference around while communicating, is an example of where auto
would be cumbersome. Then again, another program that opens many sockets
for a short while each, might really benefit from a guaranteed short
lived socket.
> This is probably going to get me chased out of town with torches and
> pitchforks, but I'd actually like to go one step further and rule
> that ONLY auto classes can define destructors.
Hmm. This I find a lot more attractive.
> The thinking being
> that if you care enough about a managed resource to write a
> destructor to release it, you almost certainly want that destructor
> called deterministically. Relying on the garbage collector to call it
> for you in a timely fashion is almost certainly setting you up for a
> nasty surprise. Far too many people still seem to think that GC is a
> panacea for resource management generally, not just memory
> management, and until they're jolted out of that I don't have much
> hope for D's RAII support improving.
Maybe we should solicit for counter examples?
If none are found, then we probably should implement this.
> (Incidentally, what's with this "RR"??? I've never seen it before in
> 10 years of writing C++. If you mean RAII, it's probably less
> confusing to the reader to say RAII, however silly an acronym it
> might be.)
Depends on the reader. ;-)
Check out digitalmars.D:32289.
More information about the Digitalmars-d
mailing list