some syntactic sugar for mixin declaration.

102 views
Skip to first unread message

chl

unread,
Mar 26, 2013, 10:50:14 AM3/26/13
to mi...@dartlang.org
Currently to declare a mixin we need a compulsory extend clause. Like so:
class Foo extends Object with Bar {
 
//implementation
}


Is it possible that, if the extend clause is omitted and there is a with keyword, than the compiler inserts 'extends Object' before 'with'?
ie:
class Foo with Bar{
 
//implementation
}


Ladislav Thon

unread,
Mar 26, 2013, 10:54:04 AM3/26/13
to mi...@dartlang.org
I bet it would be possible, but do we want to do that? Given that the with clause is a part of the extends clause, as I've explained few days ago in the apply a Mixin to a class thread.

LT

chl

unread,
Mar 26, 2013, 10:56:40 AM3/26/13
to mi...@dartlang.org
True, its part of the extends clause, or at least i think it is. But theres no meaning, in extending Object as all objects already extend Object correct?

Ladislav Thon

unread,
Mar 26, 2013, 10:57:50 AM3/26/13
to mi...@dartlang.org
True, its part of the extends clause, or at least i think it is. But theres no meaning, in extending Object as all objects already extend Object correct?

But extends Object with Bar means that it doesn't extend Object. It extends Object_with_Bar.

LT

chl

unread,
Mar 26, 2013, 11:08:25 AM3/26/13
to mi...@dartlang.org
I agree to what you are saying, as it is technically correct. That's why i'm not asking to change the specification, but for a little bit of syntactic sugar.

Ladislav Thon

unread,
Mar 26, 2013, 11:27:12 AM3/26/13
to General Dart Discussion


> I agree to what you are saying, as it is technically correct. That's why i'm not asking to change the specification, but for a little bit of syntactic sugar.

And I ask: does this sugar make sense? People are already confused by the syntax, and I believe that this sugar would make the syntax even more confusing.

LT

Florian Loitsch

unread,
Mar 26, 2013, 11:46:18 AM3/26/13
to General Dart Discussion
If you use Object as base-class you might as well extend the mixin. It sounds strange, but it has the same effect:
`class Foo extends Object with Bar` is equivalent to `class Foo extends Bar`.

Alternatively we are debating if we should use a convention where mixins are generally bundled with a base-class. For example: a ListMixin could come with a ListBase class.
The main-difference between the ListMixin and the ListBase would be that ListBase would implement List (which wouldn't be the case by mixing in the ListMixin) and could also provide more advanced constructors.

With this convention you wouldn't need the syntactic sugar anymore, because you would just extend the Base class.


LT

--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 



--
Give a man a fire and he's warm for the whole day,
but set fire to him and he's warm for the rest of his life. - Terry Pratchett

chl

unread,
Mar 26, 2013, 12:05:52 PM3/26/13
to mi...@dartlang.org
Does the same hold, if you are mixing in more than 1 class?

chl

unread,
Mar 26, 2013, 12:10:57 PM3/26/13
to mi...@dartlang.org
Are people confused with the current syntax? And if so, which part is it that makes it confusing?

Florian Loitsch

unread,
Mar 26, 2013, 1:09:25 PM3/26/13
to General Dart Discussion
On Tue, Mar 26, 2013 at 5:05 PM, chl <chiah...@gmail.com> wrote:
Does the same hold, if you are mixing in more than 1 class?
Well then you can always write: class Foo extends Bar with Bar2 ...
So yes. it still holds. When you extend "Object" with a mixin the first mixin can always take the place of "Object". 

Ladislav Thon

unread,
Mar 26, 2013, 1:15:10 PM3/26/13
to General Dart Discussion


> Are people confused with the current syntax? And if so, which part is it that makes it confusing?

I believe that it's the fact that with M1, M2 looks exactly like implements I1, I2, but it works differently. While the implements clause modifies the class declaration, the with clause modifies the extends clause.

Also, I'm stupid. I've realized that extends Object with M1 is equal to extends M1 a long time ago, but I always forget about it when discussing mixins. Luckily, we have Florian :-)

LT

chl

unread,
Mar 26, 2013, 8:53:17 PM3/26/13
to mi...@dartlang.org
Well thats true, so i concede, thanks for the discussion.
Reply all
Reply to author
Forward
0 new messages