Language Extension Through Preprocessing

General discussion for topics related to the FreeBASIC project or its community.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

Cool that there is movement, but this is the syntax bit. It doesn't look like true polymorphism (usually implemented with virtual methods in the more conservative languages)
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

v1ctor wrote:I added some support for inheritance. The changes are in the v0_22-inheritance branch.

work:

Code: Select all

type TObject
	public:
	declare sub thing()
	
	private:
	dim as byte unused
end type

	sub TObject.thing()
		print "TObject.thing()"
	end sub

type TBase extends TObject
	public:
	declare constructor(value as integer)
	
	public:
	declare sub thing()
	
	protected:
	dim as integer value
end type

	constructor TBase (value as integer)
		this.value = value
	end constructor

	sub TBase.thing()
		print "  TBase.thing()"
	end sub
	
type TDerived extends TBase
	public:
	declare constructor (value as integer)
	declare sub thing(value as integer)
end type
Hmm.. nice work. :)

Can we use moar BASICish language? "extends" sounds very dull.

Some ideas:
"DerivedFrom TBase" <-- my favorite.
"Using TBase"
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

agamemnus@ if FB goes JAVA why new words for working things :-)
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Post by Imortis »

agamemnus wrote: Hmm.. nice work. :)

Can we use moar BASICish language? "extends" sounds very dull.

Some ideas:
"DerivedFrom TBase" <-- my favorite.
"Using TBase"
Here is the info from TODO.txt in the SVN about OOP. This is a very old file. It has been there for years:
[ ] classes
- *MUST* follow the GCC 3.x ABI to make it easier to reuse C++ libs compiled by GCC
- Java/Php5-ish syntax: CLASS INTERFACE EXTENDS IMPLEMENTS THROWS ABSTRACT
- must support forward references for any kind of symbol, so classes can't be stored
directly to AST
- how to deal with "foo(expr)"? it could be an array or a function call..
- keeping everything in a parser/token tree will allow templates to be added later
- class shouldn't be emitted unless referenced
- function bodies defined outside classes follow the private/public proc rules
- single inheritance, plus interfaces
- exceptions - with stack unwind support
- pure virtual methods
- down casting
- some support for RTTI
EXTENDS is what was planned long ago. I doubt it is going to change.
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

The other alternative would be "inherits" as in vb.net. The other keywords are pretty much standard and are the choice of most OO languages (abstract, interface, class etc).

I'm only adding support for inheritance right now. Polymorphism should be added later.
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Post by VonGodric »

nice work v1ct0r. Thumb up!

I was wondering that perhaps while you are here and before you disappear into the wild again - please document and restructure the source so it would be easier for other people to get their heads around and help out? For example document describing the general compiler flow and internal logic, comments in the files what they do and what the main functions are, in what context they are invoked... Some header files are humongous and navigating / making sense of them is a problem...

And any hope for osx support? Or what would need to be done to compile on osx? I might have a go if I knew where to start...
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

D.J.Peters wrote:agamemnus@ if FB goes JAVA why new words for working things :-)
I don't like Java, its abstract syntax, and the IDE/compilation issues... :-|

Imortis wrote: Here is the info from TODO.txt in the SVN about OOP. This is a very old file. It has been there for years:
...
EXTENDS is what was planned long ago. I doubt it is going to change.
Just because v1ctor posted it there long ago doesn't mean there's no latitude for change.

v1ctor wrote:The other alternative would be "inherits" as in vb.net. The other keywords are pretty much standard and are the choice of most OO languages (abstract, interface, class etc).

I'm only adding support for inheritance right now. Polymorphism should be added later.

I think it should be "inherits", then, for three reasons:
1) I don't like the sound of "extends". (Sounds too much like a viagra ripoff!!)
2) Closer to a BASIC language (VB.NET as you said); "inherits" is less abstract-sounding. Very important.
3) Will someone who already extensively uses and likes C++ or Java use FreeBasic? Very likely not. From VB or another basic? Yes. It should be more familiar to them to make it more likely they will switch.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

v1ctor wrote:The other alternative would be "inherits" as in vb.net. The other keywords are pretty much standard and are the choice of most OO languages (abstract, interface, class etc).
Well, I'm biassed of course, but if you recycle class, you can use parentheses:

Descendant = class(parentclass)

or

Descendant = interface(parentinterface)

abstract and similar keywords (sealed, deprecated,platform,abstract) appear before class/interface kw.
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

VonGodric: Sup, mate? Hmm, I doubt the sources will ever be well documented. I don't have much time to work on the missing features, let alone writting docs, really sorry.

If nobody is against "inherits", it could be that, no problem. But I find it easier to remember "extends" than "inherits". Probably because in my tongue, "inherits" is written as "herda", while "extends" is "estende" (stupid Portuguese, the noun has a "x" while the verb is written with a "s").

marcov: that's too Pascal-ish :)
HD_
Posts: 215
Joined: Jun 10, 2006 12:15
Contact:

Post by HD_ »

extends sounds fine to me, also easier to type and rolls off the tongue.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

IMO the 'extents'/'inherits' question should be seen from a practice point of view. Which one makes it easier to translate code from the most used other languages (C/C++ ATM).

When FB can support all C/C++ features in an UDT it makes sense to have the same keyword. When an FB UDT has to get reviewed after the translation it makes sense to use another keyword.
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Post by VonGodric »

I vote for extends. For inherit-ophiles: #define inherits extends ;)

TJF: in C++ you don't have a keyword for that. its just: class MyClass: public BaseClass {};
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

v1ctor wrote:
marcov: that's too Pascal-ish :)
Something can never be too Pascal-ish. :)

Anyway, the point was more that you don't necessarily need a new keyword, but can use a fixed position after a keyword that already signals a class declaration.

You are probably aware of it, but for the benefit of the forum: you'll also need kws or syntax too for what is "super" in Java, to select between a method in the current class and the parent. Without argument the methodname is the same as the current one. And of course a method might not be implemented in the direct ancestor, but it might also be in one ancestor beyond.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Post by MOD »

I also vote for 'extends'. C++ and Java uses similar methods but Java has keywords for it. And IMO 'extends' is more understandable than 'inherits'.

v1ctor: great job and thank you for not dropping FB!
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Post by VonGodric »

never mind
Post Reply