Class implementation ...

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Class implementation ...

Post by demosthenesk »

Hello,
i read the wiki help chm about constructors and destructors and i see the keyword CLASS which is not implemented yet.

When do you plan to implement CLASS keyword? It would be great improvement to use it instead TYPE.
fxm
Moderator
Posts: 12066
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Class implementation ...

Post by fxm »

Welcome to the forum!

At first glance, a CLASS would only 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).
- Other features ???

That being said, I would rather be in favor of implementing the INTERFACE structure first, which would provide new and more useful functionality.
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Class implementation ...

Post by speedfixer »

While there are many features of the CLASS concept that are not yet present automatically, one can pretend that a udt TYPE is a class.

Just add the qualities that you desire.
For example, you can add your own RTTI or RAII as you wish.

The flexibility is present in FreeBASIC.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Class implementation ...

Post by caseih »

demosthenesk wrote:When do you plan to implement CLASS keyword? It would be great improvement to use it instead TYPE.
What great improvement would that be? FB's TYPE is nearly exactly equivalent to C++'s class. There's really no need for a "CLASS" keyword to clutter up the namespace. TYPE already does what you want. I'm really not completely sure why C++ chose to add "class" instead of just adding syntax and public/protected/private to struct. I assume it had something to do with C++ at the time being a pre-processor for C. In any case, FB has no such encumbrances.
coderJeff
Site Admin
Posts: 4308
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Class implementation ...

Post by coderJeff »

caseih wrote:
demosthenesk wrote:FB's TYPE is nearly exactly equivalent to C++'s class. There's really no need for a "CLASS" keyword to clutter up the namespace.
The "class" keyword is a quasi-reserved word in the fbc compiler (it's a token word) and reserved for future use in the documentation: see Class

I agree that "type" and "class" will have similar end results in terms of the binary code emitted.

To be honest, I'm not sure what "class" has in store for us, but I would suspect that it will allow member definitions to be nested within the "class" structure itself. Maybe in fbc version 2. To allow member definitions to be specified within the class delcaration/definition would require a different machinery within the fbc compiler to allow it. Currently, "type" declarations must be complete followed by the implementation (definition of members) separately.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Class implementation ...

Post by caseih »

Yes, that makes sense.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: Class implementation ...

Post by angros47 »

coderJeff wrote:Currently, "type" declarations must be complete followed by the implementation (definition of members) separately.
If I understood correctly, as long as those implementations are defined as "private" they will behave just as if they were defined inside the class, right?
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Class implementation ...

Post by Josep Roca »

In WIndows COM programming, classes are important because they allow to develop an object with multiple interfaces. With Type, you can only have one interface.
dodicat
Posts: 7967
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Class implementation ...

Post by dodicat »

I think C++ allows member function to be implemented inside the class structure so they are automatically inlined.
I think templates would be a nice addition to fb
Even freepascal has them now (generics)

{$mode delphi}
procedure something<T>(var arr:array of T);
...
...

something<integer>(I);
something<string>(s);
Using macros is a bit outdated IMO.

Cannot multiple interfaces be implemented via virtual functions in various extended types and an abstract function in the (base) type?
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Class implementation ...

Post by caseih »

Josep Roca wrote:In WIndows COM programming, classes are important because they allow to develop an object with multiple interfaces. With Type, you can only have one interface.
Sure but COM isn't a programming language. You can use it from a straight C interface if you want. I can see that it might make it more convenient if the programming language has syntax that makes COM easy.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: Class implementation ...

Post by angros47 »

As far as I know, language D, too, offers only single inheritance, and still it is pretty compatible with C++. Right now I have the impression FreeBasic is more or less at the same level of D, in that regard
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Class implementation ...

Post by Josep Roca »

> Sure but COM isn't a programming language. You can use it from a straight C interface if you want. I can see that it might make it more
> convenient if the programming language has syntax that makes COM easy.

I can use COM with any language that supports pointers and structures, but writing COM servers without native support for classes and interfaces is too cumbersome.
Post Reply