Multiple inheritance vs Multilevel inheritance?

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

TJF wrote:The idea to create OOP style wrappers for FB is not new. In the header creator GirToBac I implemented such a code generator, but stopped development because an important feature is missing in FB syntax in order to extend a new class from multiple bases

Code: Select all

TYPE D EXTENDS A, B, C
@CoderJeff
Is there any chance to implement this new feature in FB in near future?

PS
I tested a workaround by chaining up multiple intermediate TYPEs, but found out that the generated code is too hard to understand/maintain. So I decided to wait until multiple extension is implemented in FB.
fxm wrote:I think that multiple inheritance will never be implemented in FreeBASIC, on the other hand, I am impatiently awaiting "IMPLEMENTS".
todo.txt:

Code: Select all

  - INTERFACE ... END INTERFACE
      - structs extending OBJECT, not allowing any fields, only methods
      - all methods automatically are ABSTRACT
		interface A
			declare [abstract] sub bar( )
		end interface
      - IMPLEMENTS:
		type Child [extends Parent] [implements A, B, C]
        or allow just one interface?
		type Child extends A
      - multiple interfaces comes down to multiple inheritance (too hard?)
After reading these posts I'm really confused. What are we currently have (or not have)? What are we going to do?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Multiple inheritance vs Multilevel inheritance?

Post by fxm »

Currently, FreeBASIC only supports "Single Inheritance" and "Multilevel Inheritance" and "Hierarchical Inheritance", but not "Multiple Inheritance" or "Interfaces":
- Any derived type has at most one direct base type.
- By cons, one base type can have several direct derived types.

FreeBASIC also supports "Inheritance Polymorphism".

For the rest, I let coderJeff here answer on what can be done in the near future or in the distant future.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

fxm wrote:Currently, FreeBASIC only supports "Single Inheritance" and "Multilevel Inheritance" and "Hierarchical Inheritance", but not "Multiple Inheritance" or "Interfaces":
- Any derived type has at most one direct base type.
- By cons, one base type can have several direct derived types.

FreeBASIC also supports "Inheritance Polymorphism".

For the rest, I let coderJeff here answer on what can be done in the near future or in the distant future.
Then FreeBASIC is on par with Objective C, which only supports Multilevel inheritance according to this document:

https://www.tutorialspoint.com/objectiv ... itance.htm

So it's nothing Objective C can do that FreeBASIC can't.

The only barrier is to change the mindset, from C++ and Java's OOP style to Objective C's OOP style.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Multiple inheritance vs Multilevel inheritance?

Post by coderJeff »

TJF wrote:

Code: Select all

TYPE D EXTENDS A, B, C
@CoderJeff
Is there any chance to implement this new feature in FB in near future?
For me probability is zero. There's just too many other issues that should be addressed before even thinking about this. Not sure if you have been following recent development, but still sorting the long time issues even with single / multiple inheritance and namespaces.

I'm not an expert, however, based on my experience with programming and freebasic, general multiple inheritance would be a complex and time-consuming feature to implement. Given the developer resources available, I can't see how it would be worth the cost.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

coderJeff wrote:
TJF wrote:

Code: Select all

TYPE D EXTENDS A, B, C
@CoderJeff
Is there any chance to implement this new feature in FB in near future?
For me probability is zero. There's just too many other issues that should be addressed before even thinking about this. Not sure if you have been following recent development, but still sorting the long time issues even with single / multiple inheritance and namespaces.

I'm not an expert, however, based on my experience with programming and freebasic, general multiple inheritance would be a complex and time-consuming feature to implement. Given the developer resources available, I can't see how it would be worth the cost.
Why don't give up on multiple inheritance completely and follow Objective C's OOP style? "Single Inheritance" and "Multilevel Inheritance" and "Hierarchical Inheritance" are enough.

Objective C is worth for FreeBASIC to learn from. When it started it also compiles to C code like FreeBASIC currently does before it got it own compiler (based on GCC and now Clang). Objective C's OOP style is most suitable for FreeBASIC.
funlw65
Posts: 8
Joined: Jun 20, 2010 22:15
Contact:

Re: Multiple inheritance vs Multilevel inheritance?

Post by funlw65 »

Solving the actual issues is infinitely more urgent. When it is rock solid, then there probably will be enough time for propositions...

If you really need Qt now, see Lazarus+FreePascal combination.
funlw65
Posts: 8
Joined: Jun 20, 2010 22:15
Contact:

Re: Multiple inheritance vs Multilevel inheritance?

Post by funlw65 »

Why don't give up on multiple inheritance completely and follow Objective C's OOP style? "Single Inheritance" and "Multilevel Inheritance" and "Hierarchical Inheritance" are enough.

Objective C is worth for FreeBASIC to learn from. When it started it also compiles to C code like FreeBASIC currently does before it got it own compiler (based on GCC and now Clang). Objective C's OOP style is most suitable for FreeBASIC.
He will be forced to rewrite Qt from zero. So Qt is out of question if he doesn't want to use it now from the C bindings.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

funlw65 wrote:Solving the actual issues is infinitely more urgent. When it is rock solid, then there probably will be enough time for propositions...

If you really need Qt now, see Lazarus+FreePascal combination.
Are you mistaken me with... someone else?
funlw65 wrote:
Why don't give up on multiple inheritance completely and follow Objective C's OOP style? "Single Inheritance" and "Multilevel Inheritance" and "Hierarchical Inheritance" are enough.

Objective C is worth for FreeBASIC to learn from. When it started it also compiles to C code like FreeBASIC currently does before it got it own compiler (based on GCC and now Clang). Objective C's OOP style is most suitable for FreeBASIC.
He will be forced to rewrite Qt from zero. So Qt is out of question if he doesn't want to use it now from the C bindings.
No. I don't need Qt. You definitely mistaken me with someone else.
funlw65
Posts: 8
Joined: Jun 20, 2010 22:15
Contact:

Re: Multiple inheritance vs Multilevel inheritance?

Post by funlw65 »

Obviously! The problem with multiple tabs in Firefox and multiple subject watching/reading at a late hour in night! I think I confused all in this topic! Mea culpa.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

funlw65 wrote:Obviously! The problem with multiple tabs in Firefox and multiple subject watching/reading at a late hour in night! I think I confused all in this topic! Mea culpa.
It's almost noon here and I'm going to have lunch ^^
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Multiple inheritance vs Multilevel inheritance?

Post by marcov »

j8w344c6 wrote:Objective C is worth for FreeBASIC to learn from. When it started it also compiles to C code like FreeBASIC currently does before it got it own compiler (based on GCC and now Clang). Objective C's OOP style is most suitable for FreeBASIC.
Could you explain why? As far as I know it, it is a completely different object model with dispatch based method invocation, iow it goes off in a totally different direction, so implementing it would rather be a colossal endeavour.

And Objective C also has Protocols which are basically like interface based multiple inheritance. Better directly add that (interfaces) to what is there instead of migrating to a totally foreign object model like ObjC.

(The QT remark is probably because you need some Objective C model support to conveniently communicate with Cocoa. He probably thought that you were a Macer because the Objective C suggestion, and a workaround is using QT. In the more distant past, OS X also supported a more procedural framework called Carbon but it was deprecated in 2007 and removed when OS X got a 64-bit userland (2017ish?). FPC added Objective Pascal support, and it was not easy)
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

marcov wrote:
j8w344c6 wrote:Objective C is worth for FreeBASIC to learn from. When it started it also compiles to C code like FreeBASIC currently does before it got it own compiler (based on GCC and now Clang). Objective C's OOP style is most suitable for FreeBASIC.
Could you explain why? As far as I know it, it is a completely different object model with dispatch based method invocation, iow it goes off in a totally different direction, so implementing it would rather be a colossal endeavour.

And Objective C also has Protocols which are basically like interface based multiple inheritance. Better directly add that (interfaces) to what is there instead of migrating to a totally foreign object model like ObjC.

(The QT remark is probably because you need some Objective C model support to conveniently communicate with Cocoa. He probably thought that you were a Macer because the Objective C suggestion, and a workaround is using QT. In the more distant past, OS X also supported a more procedural framework called Carbon but it was deprecated in 2007 and removed when OS X got a 64-bit userland (2017ish?). FPC added Objective Pascal support, and it was not easy)
I don't know ObjC. I only have a quick look at it via tutorial on tutorialspoint. I found the syntax to be very like FreeBASIC. On both we have a root class: NSObject on ObjC and simply Object on FreeBASIC, that other classes could extend from. I don't know about ObjC protocols, I only looked at interfaces so far.
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: Multiple inheritance vs Multilevel inheritance?

Post by miilvyxg »

j8w344c6 wrote:
marcov wrote:
j8w344c6 wrote:Objective C is worth for FreeBASIC to learn from. When it started it also compiles to C code like FreeBASIC currently does before it got it own compiler (based on GCC and now Clang). Objective C's OOP style is most suitable for FreeBASIC.
Could you explain why? As far as I know it, it is a completely different object model with dispatch based method invocation, iow it goes off in a totally different direction, so implementing it would rather be a colossal endeavour.

And Objective C also has Protocols which are basically like interface based multiple inheritance. Better directly add that (interfaces) to what is there instead of migrating to a totally foreign object model like ObjC.

(The QT remark is probably because you need some Objective C model support to conveniently communicate with Cocoa. He probably thought that you were a Macer because the Objective C suggestion, and a workaround is using QT. In the more distant past, OS X also supported a more procedural framework called Carbon but it was deprecated in 2007 and removed when OS X got a 64-bit userland (2017ish?). FPC added Objective Pascal support, and it was not easy)
I don't know ObjC. I only have a quick look at it via tutorial on tutorialspoint. I found the syntax to be very like FreeBASIC. On both we have a root class: NSObject on ObjC and simply Object on FreeBASIC, that other classes could extend from. I don't know about ObjC protocols, I only looked at interfaces so far.
Are you really want FB to be the same as this?

https://github.com/Quotation/LongestCocoa
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Multiple inheritance vs Multilevel inheritance?

Post by j8w344c6 »

miilvyxg wrote:Are you really want FB to be the same as this?

https://github.com/Quotation/LongestCocoa
I don't know about this. The code on tutorialspoint just looks beautiful. I don't know it could be that bad.
carlosridg
Posts: 1
Joined: Aug 12, 2022 5:03

Re: Multiple inheritance vs Multilevel inheritance?

Post by carlosridg »

The key difference between Multiple and Multilevel Inheritance is that Multiple Inheritance is when a class inherits from many base classes while Multilevel Inheritance is when a class inherits from a derived class making that derived class a base class for a new class.

Allowing multiple inheritance makes the rules about function overloads and virtual dispatch decidedly more tricky, as well as the language implementation around object layouts. These impact language designers/implementors quite a bit, and raise the already high bar to get a language done, stable and adopted.

It is simple to think this way, if class A inherits from multiple classes, then the class A will have the same grandparent class multiple times, this means the code will be complicated and a series of bugs will go unacknowledged. Personally, I think multiple inheritance has a bad rap, and that a well done system of trait style composition would be really powerful/useful… but there are a lot of ways that it can be implemented badly, and a lot of reasons it’s not a good idea in a language like C++.
Post Reply