FoxPro syntax, Properties and fields
Posted: Sat Sep 07, 2019 10:46 am
I have been working on the FoxPro language support yesterday and have the following questions:
1) In FoxPro all classes (have to) inherit from a base class. The ultimate base class is Custom. This is not just an empty class, because it also provides quite a few properties, events and methods. For example properties like name, left, right, Events like Init, Error and Destroy and methods like AddObject, AddProperty etc.
What do you think, should we allow classes (declared with the FoxPro class definition syntax) to inherit from 'nothing' (i.o.w. from System.Object), which also means that these objects will only have the normal .Net methods such as GetType() GetHashCode() and ToString().
We could also add a compiler option that determines that when no base class is defined your class either inherits from System.Object or from XSharp.FoxPro.Custom.
2) The FoxPro class syntax speaks of "Properties" and not of "Fields" or "Instance variables"
What would you expect that happens when this is compiled to .Net. Should PropertyName1 etc. become a 'real property' (with a getter and setter) or should they be compiled into a Field.
The problem with compiling it to a field is that we sometimes see a syntax like this:
If we compile "Species" to a field then the Dog class will try to redefine the field in the parent class.
Our compiler will then produce the warning:
From what I have seen FoxPro declares everything as "real" properties and somehow stores name/value pairs in an invisible collection inside each object and both Species in the Animal class and in the Dog class read/write from the same collection. So all these properties are virtual as well
So my current thinking is to generate .Net properties from this and make these virtual so they can be overwritten in a child class. We can also add a collection, but we can also create a backing field. In case of a property that overrides a parent property we can change the getter and setter and redirect the call to the parent property.
But that would mean that you can't create fields with the current FoxPro syntax.
I see a couple of solutions:
a) with a special compiler option you can tell the compiler to generate fields or properties. When you generate fields you will get a warning when you redefine a field in subclass
b) we always generate properties but add a special syntax to declare fields, something like
Btw: our current definition allows you to specify the types for Fields/Properties:
3) All methods inside FoxPro seem to be virtual. This was also the case for Visual Objects. We have a compiler option that does this automatically.
4) The ADD OBJECT syntax creates a property (field?) and sets the value of the property to a new object of the specified type and allows to set initial values for some properties of this new object. What is not clear to me is if this object is also automatically added to a collection of children (controls) in the class ?
5) Now that we move FoxPro to .Net we will also be able add new functionality. So far we have added the following (for free because it is there in our compiler already)
- The ability to declare attributes on a type, property method etc
- The ability to add more (visibility) modifiers then just PROTECTED and HIDDEN. For example also INTERNAL,ABSTRACT, STATIC and SEALED
- The ability to define Generic types and methods
- All types can be specified in the Namespace.Type syntax. For example
I have more questions but these can be handled later
I would value your input on this.
Robert
1) In FoxPro all classes (have to) inherit from a base class. The ultimate base class is Custom. This is not just an empty class, because it also provides quite a few properties, events and methods. For example properties like name, left, right, Events like Init, Error and Destroy and methods like AddObject, AddProperty etc.
What do you think, should we allow classes (declared with the FoxPro class definition syntax) to inherit from 'nothing' (i.o.w. from System.Object), which also means that these objects will only have the normal .Net methods such as GetType() GetHashCode() and ToString().
We could also add a compiler option that determines that when no base class is defined your class either inherits from System.Object or from XSharp.FoxPro.Custom.
2) The FoxPro class syntax speaks of "Properties" and not of "Fields" or "Instance variables"
Code: Select all
DEFINE CLASS ClassName1 AS ParentClass
[[PROTECTED | HIDDEN] PropertyName1, PropertyName2 ...]
[[.]Object.]PropertyName = eExpression ...]
The problem with compiling it to a field is that we sometimes see a syntax like this:
Code: Select all
DEFINE CLASS Animal as custom
Species = "Animal"
ENDDEFINE
DEFINE CLASS Dog AS Animal
Species = "Dog"
ENDDEFINE
Our compiler will then produce the warning:
Code: Select all
warning XS0108: 'Dog.Species' hides inherited member 'Animal.Species'. Use the new keyword if hiding was intended.
So my current thinking is to generate .Net properties from this and make these virtual so they can be overwritten in a child class. We can also add a collection, but we can also create a backing field. In case of a property that overrides a parent property we can change the getter and setter and redirect the call to the parent property.
But that would mean that you can't create fields with the current FoxPro syntax.
I see a couple of solutions:
a) with a special compiler option you can tell the compiler to generate fields or properties. When you generate fields you will get a warning when you redefine a field in subclass
b) we always generate properties but add a special syntax to declare fields, something like
Code: Select all
DEFINE CLASS ClassName1 AS ParentClass
[[PROTECTED | HIDDEN] FIELD Field1, Field2 ...]
FIELD FieldName = eExpression ...]
Code: Select all
[[PROTECTED | HIDDEN] PropertyName1, PropertyName2 ...] [AS DataType]
4) The ADD OBJECT syntax creates a property (field?) and sets the value of the property to a new object of the specified type and allows to set initial values for some properties of this new object. What is not clear to me is if this object is also automatically added to a collection of children (controls) in the class ?
5) Now that we move FoxPro to .Net we will also be able add new functionality. So far we have added the following (for free because it is there in our compiler already)
- The ability to declare attributes on a type, property method etc
- The ability to add more (visibility) modifiers then just PROTECTED and HIDDEN. For example also INTERNAL,ABSTRACT, STATIC and SEALED
- The ability to define Generic types and methods
Code: Select all
DEFINE CLASS MyStack<T> WHERE T IS NEW()
Code: Select all
CLASS MyTable as System.Data.DataTable
I have more questions but these can be handled later
I would value your input on this.
Robert