When Implementing Classes...

For other topics related to the FreeBASIC project or its community.
Munair
Posts: 836
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

When Implementing Classes...

Postby Munair » Nov 21, 2017 21:17

Not sure if and when class support will be implemented as I have no idea what the current development state of the compiler is. But I was just thinking about it. Currently the keyword TYPE pretty much covers object oriented programming with inheritance, which is already close to full class support.

It is just my opinion that it would be great to leave the TYPE declaration and simply add the keyword class, similar to Pascal:

Code: Select all

Type TMyOpinion Extends Class(object)
  ...
End Type

And when subclassing:

Code: Select all

Type TMyOpinion Extends Class(TNoOpinion)
  ...
End Type

One could also do away with the keyword Extends and simply asign:

Code: Select all

Type TMyOpinion = Class(TNoOpinion)
  ...
End Type

Another option would be to replace the keyword TYPE by CLASS and downgrade TYPE back to simple structures, or put Class next to it, but at the risk of some confusion. Admittedly this would be more "BASIC" like:

Code: Select all

Class TAnotherOpinion extends object
  ...
End Class

whereby "extends Object" would probably be redundant when not subclassing. Not sure what the compiler engineers have in mind, but this is just an idea, and frankly, I hope we will see full class support coming soon!

Anybody having an opinion on this?
fxm
Posts: 9139
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: When Implementing Classes...

Postby fxm » Nov 21, 2017 22:15

Munair wrote:Currently the keyword TYPE pretty much covers object oriented programming with inheritance, which is already close to full class support.
Moreover, the polymorphism by overriding the virtual member procedures induces a quasi class structure.
IMHO, are still missing:
- the non-static member reference fields,
- the interface structure.
Munair
Posts: 836
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: When Implementing Classes...

Postby Munair » Nov 21, 2017 22:40

fxm wrote:
Munair wrote:Currently the keyword TYPE pretty much covers object oriented programming with inheritance, which is already close to full class support.
Moreover, the polymorphism by overriding the virtual member procedures induces a quasi class structure.
IMHO, are still missing:
- the non-static member reference fields,
- the interface structure.

It's funny to see that PureBasic does support Interfaces, but at the same time states it will never become an OOP language. Their Interface support is primarily to support communication with external OOP modules.
Josep Roca
Posts: 441
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: When Implementing Classes...

Postby Josep Roca » Nov 21, 2017 23:28

It's funny to see that PureBasic does support Interfaces, but at the same time states it will never become an OOP language. Their Interface support is primarily to support communication with external OOP modules.


PureBasic only supports interface declarations, not interface implementations. Interface declarations are also supported by FreeBasic using TYPE/END TYPE.
RockTheSchock
Posts: 220
Joined: Mar 12, 2006 16:25

Re: When Implementing Classes...

Postby RockTheSchock » Jan 18, 2018 20:40

I would design classes for shorter and more friendly oop code. I also like Java interfaces.
    -members private like in C++ or maybe protected as default.
    -No Declare statements needed.
    -Define member procedures inline and virtual
    -2 pass compiler / parser would be needed
    -class extends automatically object

Code: Select all

class foo
      sub test 
             print "hi"
      end sub
end class
Munair
Posts: 836
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: When Implementing Classes...

Postby Munair » Jan 19, 2018 7:36

A good solution would probably be to allow both TYPE and CLASS to define objects. TYPE has been used for a long time. The keyword CLASS would be very much a cosmetic addition.
fxm
Posts: 9139
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: When Implementing Classes...

Postby fxm » Jan 19, 2018 8:40

dkl wrote:... That brings me back to another idea: I think we really should use CLASS ... END CLASS as a form of TYPE ... END TYPE which automatically Extends Object and makes all the methods Virtual. That would be a syntax like Java, safer and less complex.

Return to “Community Discussion”

Who is online

Users browsing this forum: MrSwiss and 2 guests