Auto syntax revisited

Georg Wrede georg.wrede at nospam.org
Wed Feb 22 06:13:16 PST 2006


Fredrik Olsson wrote:
> And the possibility of allowing non stack objects to automatically go
> out of scope in the future without changing the syntax? 

This is important. For the destruction itself, it makes no difference 
whether an object is on the stack or on the heap.

A programmer might have an opinion on where to initially store the 
object, but that has to do with issues like heap fragmentation, or 
whatever else except destruction details.

> Ones we go 1.0 much of the syntax will
> pretty much have to stay, so better be prepared :). A functionality
> restricted by the compiler is easier to fix and causes less harm than
> a feature restricted by the syntax.

True!

> Plus with: auto a = A(); It is absolutely no way to just at a glance
> make sure with 100% sertenty that a is not assigned the result of a
> function, instead of being instantiated on the stack.

Yes. And even more important, it should be obvious and stand out to the 
human reader -- or else debugging becomes a pain.

That is, if the programmer has an opinion on where the object should be, 
then that opinion should stand out. If he doesn't care, then that should 
be the simplest syntax.

Likewise, and /separately/ from that, it should be equally obvious if 
the programmer wanted it to be a scoped object. But if he didn't, then 
it does _not_ have to stand out (i.e. use normal syntax here), since the 
default has always been to not force immediate destruction.



More information about the Digitalmars-d mailing list