[wish] Wish to support multi base

Discuss the future of the AutoHotkey language
QiuDao
Posts: 18
Joined: 25 Mar 2021, 22:55

[wish] Wish to support multi base

Post by QiuDao » 01 Apr 2021, 03:23

Wish to support multi base in objects using the depth-first algorithm like the multiple inheritance in python which uses the breadth First Search though.

QiuDao
Posts: 18
Joined: 25 Mar 2021, 22:55

Re: Preview of changes: scope, function and variable references

Post by QiuDao » 08 Apr 2021, 01:21

In my opinion, the base mechanism for object is a most convenient language feature in AHK's OOP which does exceed some OOP language like python, c++, C#, etc, except that it only supports a single base in AHK's objects.
Is there a reason that every object should have only one base? How about implementing multiple bases in objects just like the multiple inheritance in python but using the depth-first algorithm instead which I think is more intuitive and suitable for AHK's base mechanism. One benefit is that it can reduce the length of the object's base chain and some objects have no need to inherit some base sometimes just to make up the base chain. It will become more flexible.
I don't think there are some side effects to introduce the multiple base for objects. You even need not have any modifications to the built-in class, just keep the way they are which has only one base, and the multi-base usage remains for our users.
Need not say the diamond inheritance, we can just avoid it in code writing, can't we?-
Last edited by QiuDao on 08 Apr 2021, 04:57, edited 1 time in total.

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: [wish] Wish to support multi base

Post by lexikos » 08 Apr 2021, 02:48

@QiuDao I have moved your post here as it appeared to be completely unrelated to the original topic.

I personally don't see any value in implementing multiple inheritance, and that's reason enough; but I can come up with a few others:

1. Simplicity (of implementation, documentation, usage).
2. Performance.
3. Memory usage.

Perhaps memory usage could be preserved by optimizing for single-inheritance, but not without sacrificing more performance or simplicity. Optimizing all of these requires time that I won't spend.

Another reason is that objects already have the flexibility to implement the behaviour of multiple inheritance in script.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [wish] Wish to support multi base

Post by Helgef » 28 May 2021, 23:56

I agree with @QiuDao. Versus implementing this _in script_, I think having it built-in have favours scripts as follows,

1. Simplicity (implementation, readability)
2. Performance

Cheers.

SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: [wish] Wish to support multi base

Post by SOTE » 29 May 2021, 01:19

Multiple inheritance is quite controversial, even in deeply OOP circles. Exemplified by the famous "diamond problem" (causing havoc as to which method a child class inherits from multiple parents). Various programming languages don't allow it, so are only single inheritance. Of those that allow for multiple inheritance, they have to implement all kinds of strategies to prevent problems.

What exactly are people doing in a scripting language such as AutoHotkey, where they think such is a necessity? This arguably wouldn't be a user friendly feature, but something that's more hard core. I'm curious as to the use case. How are some such advocates getting stuck, where multiple inheritance is seen as the only salvation? Or, is this something that is thought to be good to have, because some other language has it?

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [wish] Wish to support multi base

Post by V2User » 05 Jun 2021, 04:41

SOTE wrote:
29 May 2021, 01:19
How are some such advocates getting stuck, where multiple inheritance is seen as the only salvation? Or, is this something that is thought to be good to have, because some other language has it?
@lexikos
For example, an object named objC inherits two bases. One is baseB, the other is baseA whose base is baseB. If you want to reset baseB to another baseObj for objC and at the same time avoid baseA taking place any changes, multiple base is the only solution. No alternatives at this time if without reconstruction I think.

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: [wish] Wish to support multi base

Post by lexikos » 05 Jun 2021, 05:15

@V2User I have no idea what point you are trying to make. Your object starts with already having multiple bases, then you (poorly) describe an abstract problem lacking any practical details, and pose multiple bases as the solution. If there is no multiple inheritance in the first place, it seems the problem you posed can't possibly occur, so it seems that multiple inheritance is the cause of the problem, not the solution.

I'm pretty sure you answered neither of SOTE's questions.

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [wish] Wish to support multi base

Post by V2User » 05 Jun 2021, 06:03

lexikos wrote:
05 Jun 2021, 05:15
@V2User I have no idea what point you are trying to make. Your object starts with already having multiple bases, then you (poorly) describe an abstract problem lacking any practical details, and pose multiple bases as the solution. If there is no multiple inheritance in the first place, it seems the problem you posed can't possibly occur, so it seems that multiple inheritance is the cause of the problem, not the solution.

I'm pretty sure you answered neither of SOTE's questions.
@lexikos
I am sorry I didn't describe it correctly in my above reply. Here is the correct version:

Code: Select all

baseB:={}
baseA:={base:baseB}
objC:={base:baseA}
For example, an object is named objC in whose base chain contains two bases.That is:
objC's base is baseA while baseA's base is baseB.
If you want to reset baseB(It currently means baseA's base as it has not multiple base yet) to another baseObj for objC and at the same time avoid baseA occurring any changes, then, multiple base is the only solution. There are no alternatives at this time if without a code reconstruction I think.
However, with multiple base support, we can write:

Code: Select all

baseB:={}
baseA:={}
objC:={base:baseA,base[2]:baseB}
It is probably the only solution.
There is no doubt that it is the most elegant and efficient at the same time.

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: [wish] Wish to support multi base

Post by lexikos » 11 Jun 2021, 19:55

I'll echo this:
SOTE wrote: How are some such advocates getting stuck, where multiple inheritance is seen as the only salvation?
I wrote:objects already have the flexibility to implement the behaviour of multiple inheritance in script.
So no, it is not definitely not the only solution.

Composition is not only a valid alternative to multiple inheritance, but is said to have advantages. If you want to know more, there are numerous blog articles and Q&A posts about composition vs. inheritance in other languages.

In fact, composition by collecting properties together in one base object generally performs better than dynamic inheritance. I have used it as a means of optimization with chained single inheritance, but it could be easily used to implement a form of multiple inheritance.

SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: [wish] Wish to support multi base

Post by SOTE » 15 Jun 2021, 23:38

lexikos wrote:
11 Jun 2021, 19:55
SOTE wrote: How are some such advocates getting stuck, where multiple inheritance is seen as the only salvation?
I wrote:objects already have the flexibility to implement the behaviour of multiple inheritance in script.
lexikos wrote: So no, it is not definitely not the only solution.

Composition is not only a valid alternative to multiple inheritance, but is said to have advantages. If you want to know more, there are numerous blog articles and Q&A posts about composition vs. inheritance in other languages.

In fact, composition by collecting properties together in one base object generally performs better than dynamic inheritance. I have used it as a means of optimization with chained single inheritance, but it could be easily used to implement a form of multiple inheritance.
Excellent answer.

Post Reply

Return to “AutoHotkey Development”