'Class' Keyword

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

'Class' Keyword

Post by vdecampo »

I was curious what was the future intention for the 'Class' keyword? Right now FB recognizes it as a reserved keyword, but I don't see any use for it currently. Would it make sense to treat it similar to Type? I was just curious what features it would have beyond what Type offers.

Cheers
-Vince
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: 'Class' Keyword

Post by fxm »

This is just my personal opinion (no echo from Jeff):
fxm wrote: Feb 14, 2022 16:39
exagonx wrote: Feb 14, 2022 16:01
fxm wrote: Feb 13, 2022 17:16
A class would just be a particularization of a TYPE with default features:
- Implicitly extending OBJECT (from the base CLASS).
- Implicitly all non-static member procedures being VIRTUAL (or ABSTRACT if no procedure body is defined).
- Implicitly having a default virtual destructor (for full compatibility with polymorphism).
- others??? (member fields protected by default)

The CLASS keyword is already reserved, so why not implement it now like that?
Forgive me if you are not well prepared on the subject (even if I actually consider myself ignorant) but I did not understand what the FreeBASIC TYPE lacks to be a full-fledged Class.
I think what is missing next is the INTERFACE structure (new structure for FB) which the new CLASS keyword should also be able to support (implement).
The IMPLEMENTS keyword is already reserved but not INTERFACE.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: 'Class' Keyword

Post by vdecampo »

fxm wrote: Apr 24, 2022 15:17 This is just my personal opinion (no echo from Jeff):
I think support for Interfaces would be outstanding but would also require compatibility with Is and TypeOf and probably others. I have really become accustomed to the Class/Interface pattern and find it a great method for organizing functionality.

Cheers
-Vince
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: 'Class' Keyword

Post by coderJeff »

From TODO.txt
- what should CLASS keyword do? struct vs. class as in C++?

And from wiki
- Declares a class object

The CLASS keyword was reserved long ago only with the idea that we want to do something with it, but is currently future unknown.

My opinions:
- CLASS should not be some simple variant of TYPE
- TYPE is a kind of low-level construction with heavy ties to gcc/g++ (when exported), and can be either trivial (i.e. a memory layout) or complex (methods, vtables, etc)
- CLASS could be used to break away from some gcc/g++ restrictions and let fbc do it's own thing
- CLASS could be used to break away from current single pass compiler requirements - implementation within fbc would be more complex, but should make it easier for users to write code with method definitions within the class body, easier use for classes that refer to each other and avoid complicated forward referencing for users (and type patching within fbc), etc.
Post Reply