SELF: mandatory ?
Posted: Tue Feb 09, 2021 11:14 am
Hello you all,
One of our customers has asked us to generate a compiler warning when the compiler chooses to call a function over a method with the same name, like in the example below
This is something that would never cause a problem in Visual Objects (and FoxPro and Xbase++) since in these languages the SELF: (THIS.) prefix is mandatory to call methods inside a class.
In X# we have adopted the C# syntax (Vulcan had that too) and we allow to call a method inside a class without SELF: prefix.
We have implemented this change for an upcoming release of the compiler and we now see MANY compiler warnings in existing code, such as in the VO SDK Classes where there is code to check parameters
but the class also has a Default method.
So we are now wondering:
- Should we really add this warning (of course you can always disable this warning the normal way)
- Or Should we add a compiler option to enable the check ?
- Should we make SELF: (THIS. in FoxPro) mandatory to avoid these problems ?
- Or should we add a compiler option to make SELF: mandatory ?
Even when SELF: is mandatory there can still be a problem when there is a STATIC method in a class with the same name as a Function. We'll generate the compiler warning in those cases.
Any feedback would be appreciated.
Robert
One of our customers has asked us to generate a compiler warning when the compiler chooses to call a function over a method with the same name, like in the example below
Code: Select all
CLASS Test
METHOD Left(sValue as STRING, nLen as DWORD) AS STRING
RETURN "Test"
METHOD ToString() AS STRING
RETURN Left("abc",2) // This will generate a warning that the function called and not the method .
// if you want to call the method you will have to prefix the call with SELF:
END CLASS
In X# we have adopted the C# syntax (Vulcan had that too) and we allow to call a method inside a class without SELF: prefix.
We have implemented this change for an upcoming release of the compiler and we now see MANY compiler warnings in existing code, such as in the VO SDK Classes where there is code to check parameters
Code: Select all
Default(@lParam, TRUE)
So we are now wondering:
- Should we really add this warning (of course you can always disable this warning the normal way)
- Or Should we add a compiler option to enable the check ?
- Should we make SELF: (THIS. in FoxPro) mandatory to avoid these problems ?
- Or should we add a compiler option to make SELF: mandatory ?
Even when SELF: is mandatory there can still be a problem when there is a STATIC method in a class with the same name as a Function. We'll generate the compiler warning in those cases.
Any feedback would be appreciated.
Robert