inner classes

337 views
Skip to first unread message

Benjamin Strauß

unread,
Apr 9, 2015, 5:49:35 PM4/9/15
to core...@dartlang.org
Dart should have support for inner classes like in self or newspeak (and not like in Java).

It should be possible to define inner classes that are properties of their enclosing class' instances.

Simple example:

class A{
 
class Inner{
   
var foo = 'InnerParent';
 
}
}

var a1 = new A();
var a2 = new A();

var inner = new a1.Inner();

assert(a1.Inner != a2.Inner);


It should also be possible to override inner classes:

class B extends A{
 
var foo = 'OuterChild';

 
class Inner extends super.Inner{
   
Inner(){
     
assert(foo == 'OuterChild');
     
assert(super.foo == 'InnerParent');
   
}
 
}
}

If the receiver of a call inside an inner class is implicit, it would either be 'this' or the enclosing object of the inner class. If nothing would be found it would proceed up its inheritance chain. This would relate to the lookup process of normal classes that first look inside the library scope before going up the inheritance chain.

Inner classes would be able to extend, implement or mixin other classes.

Any thoughts?

Benjamin Strauß

unread,
Apr 9, 2015, 6:15:08 PM4/9/15
to core...@dartlang.org
I meant Beta and not Self of course. :)

Gilad Bracha

unread,
Apr 9, 2015, 6:54:48 PM4/9/15
to Benjamin Strauß, core...@dartlang.org
Benjamin,

Obviously, I have wanted to go this route all along. I don't know if this will ever happen in Dart though. The benefits of such a design are maximized if it comes in on day one.  We would have no need for libraries, imports, dependency injection etc. if we did this up front. But Dart is more conservative, and did not go this route.  At this stage, any design will have to deal with legacy in the language, libraries and implementations.

There are still benefits of course. We have encountered interesting scenarios where class hierarchy inheritance would be very valuable for example, and I've spoken about those in academic forums.  I wrote up a proposal for extensible libraries, which could be seen as subset of this functionality designed specifically to support class hierarchy inheritance. I will update it and turn it into a DEP sometime. However, I would not hold my breath :-(

On Thu, Apr 9, 2015 at 3:15 PM Benjamin Strauß <benm...@gmail.com> wrote:
I meant Beta and not Self of course. :)

--
You received this message because you are subscribed to the Google Groups "Dart Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to core-dev+unsubscribe@dartlang.org.

Erik Ernst

unread,
Apr 10, 2015, 5:42:03 AM4/10/15
to Gilad Bracha, Benjamin Strauß, core...@dartlang.org
Holding my breath a little bit, just in case.  ;-)  One thing that makes virtual classes expensive in terms of language complexity is that the type system must include a variant of dependent types, such that it is able to distinguish objects of type a1.Inner from objects of type a2.Inner during type checking.  It would indeed be a substantial extension of Dart..

To unsubscribe from this group and stop receiving emails from it, send an email to core-dev+u...@dartlang.org.



--
Erik Ernst  -  Google Danmark ApS
Skt Petri Passage 5, 2 sal, 1165 København K, Denmark
CVR no. 28866984

Gilad Bracha

unread,
Apr 10, 2015, 1:49:26 PM4/10/15
to Erik Ernst, Benjamin Strauß, core...@dartlang.org
Dart's type system is fortunately unsound, so we should be able to avoid all that.

Erik Ernst

unread,
Apr 10, 2015, 3:27:07 PM4/10/15
to Gilad Bracha, Benjamin Strauß, core...@dartlang.org
Would be nice, though.  ;-)

Benjamin Strauß

unread,
Apr 10, 2015, 4:49:45 PM4/10/15
to core...@dartlang.org, benm...@gmail.com
While i would love to see this done right in a mainstream language, it is true that it might be too late for Dart now. If the result of adding features like this would be complexity, a language specification with dozens of corner cases and 800 pages (not looking at any language in particular ;) ), then i would think thrice before going that way.

Anyway, i still hope you will continue to attend conferences and try to hammer it into peoples heads though. :)
To unsubscribe from this group and stop receiving emails from it, send an email to core-dev+u...@dartlang.org.

Erik Ernst

unread,
Apr 13, 2015, 1:33:18 PM4/13/15
to Benjamin Strauß, core...@dartlang.org
On Fri, Apr 10, 2015 at 10:49 PM, Benjamin Strauß <benm...@gmail.com> wrote:
While i would love to see this done right in a mainstream language, it is true that it might be too late for Dart now. If the result of adding features like this would be complexity, a language specification with dozens of corner cases and 800 pages (not looking at any language in particular ;) ), then i would think thrice before going that way.

Anyway, i still hope you will continue to attend conferences and try to hammer it into peoples heads though. :)

Will do.  ;-)

  best regards,

Benjamin Strauß

unread,
Sep 4, 2015, 6:49:21 PM9/4/15
to Dart Core Development, benm...@gmail.com
Gilad,

i know it might be painful to talk about this again because it probably will never make it into dart. But would this be worth bringing on the table again, now that Dart is supposedly taking a more innovative/riskier turn?

Am Freitag, 10. April 2015 00:54:48 UTC+2 schrieb Gilad Bracha:
To unsubscribe from this group and stop receiving emails from it, send an email to core-dev+u...@dartlang.org.

Gilad Bracha

unread,
Sep 4, 2015, 6:54:41 PM9/4/15
to Benjamin Strauß, Dart Core Development
I intend to bring it up again, as it fits with first class libraries and so on. But it is an uphill battle. 
Reply all
Reply to author
Forward
0 new messages