When Implementing Classes...

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

When Implementing Classes...

Post by Munair »

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
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: When Implementing Classes...

Post by fxm »

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: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: When Implementing Classes...

Post by Munair »

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: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: When Implementing Classes...

Post by Josep Roca »

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: 252
Joined: Mar 12, 2006 16:25

Re: When Implementing Classes...

Post by RockTheSchock »

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: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: When Implementing Classes...

Post by Munair »

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
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: When Implementing Classes...

Post by fxm »

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.
Post Reply