Cumulative

Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com> Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Wed Apr 2 13:08:29 PDT 2014


On Wednesday, 2 April 2014 at 18:14:46 UTC, Steve Teale wrote:
> But both of these approaches are clumsy compared to what I 
> would like to see.

Yeah, I think it would need language support to be worthwhile in 
the long run. I think it makes a lot of sense for constructors 
that the superclass has the first and last word in what the 
object should look like. E.g. let subclasses populate an array in 
their "inner-clauses"  and let the superclass verify it or 
compile it into something efficient.

However, it does require a sensible super class design since you 
don't override virtual functions, but merely extend them.

> I'm pleased to see though that some other languages have noted 
> this deficiency.

Yup, I am not sure if the inner clause was in Simula I in 1963, 
but I believe it must have been present in Simula67. It was also 
used for prefixing of blocks in Simula so that you could open 
"libraries" by turning a class into a scope. E.g.

class MyToolkit begin
   integer filehandler;
   methods like print()
   filehandler = openstuff();
   inner;
   closestuff(filehandler);
end

// and use it as

MyTookit begin
    print() // file is open, we can print here
end

As Simula was Bjarne Stroustrup's influence for C++ he really 
does not have an excuse for not adopting this stuff. ;-) Well, I 
guess RAII is his version of "inner"…

If you had virtual types as class members then I guess you could 
emulate inner with RAII like patterns. (By instantiating the 
class rather than doing a function call and let the constructor 
and destructor wrap the "inner")


More information about the Digitalmars-d mailing list