We removed the reference to the Win32 library from our assembly, and after some refactoring it all compiled again.
However, after some inspection we encountered a strange method:
METHOD DeleteFile(filename AS STRING)
RETURN DeleteFile(path + filename)
It compiled, but that was it.
Instead of calling the win32 function it called itself recursively...
So, who decided in the .NET world that you don't need to prefix a call to a method with thisself?
I know that this sounds like a "issue" in our situation, but I don't agree with that.
I think that it is more fundamental: in a language that supports "functions" besides method calls with use of automatic selection of the 'context', the compiler should throw an error or warning that says that there are multiple options, and that the writer should supply the right context.
Like when the compiler gives an error if there are more than one namespace that contain a class and that the compiler needs directions which should be used here.
Or is this such a niche situation that we shouldn't bother?
Mixing functions and methods
Mixing functions and methods
Otto,
How can the compiler "know" that you are not calling yourself recursively on purpose ?
And w.r.t. writing code with or without self/this, that is a matter of style.
I know many companies that prefer not to use this/SELF when not necessary.
Robert
How can the compiler "know" that you are not calling yourself recursively on purpose ?
And w.r.t. writing code with or without self/this, that is a matter of style.
I know many companies that prefer not to use this/SELF when not necessary.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Mixing functions and methods
Hi Otto,
Personally, I'd much prefer it in all languages (VO, x#, c#, vulcan etc) that the "SELF" or "this" keyword is always mandatory when accessing instances member, as it makes code much better to read for my own taste and less error prone. But, as usual, this is a personal preference and as Robert said many others (I am sure including many people in the forums here!) prefer it otherwise, so we need to support both ways.
But, in any case, it's in our todo list to make your sample behave as you'd expect at runtime. In VO/Vulcan, the DeleteFile() call in the RETURN statement in your code
METHOD DeleteFile(filename AS STRING)
RETURN DeleteFile(path + filename)
resolves to the DeleteFile() function (if there exists one such function), so for VO/Vulcan compatibility, we will adjust also the x# compiler to search for a same named function first, before resolving the call to the same-named method. That will happen for the vulcan dialect, not sure if it should be done for the core dialect as well.
Chris
Personally, I'd much prefer it in all languages (VO, x#, c#, vulcan etc) that the "SELF" or "this" keyword is always mandatory when accessing instances member, as it makes code much better to read for my own taste and less error prone. But, as usual, this is a personal preference and as Robert said many others (I am sure including many people in the forums here!) prefer it otherwise, so we need to support both ways.
But, in any case, it's in our todo list to make your sample behave as you'd expect at runtime. In VO/Vulcan, the DeleteFile() call in the RETURN statement in your code
METHOD DeleteFile(filename AS STRING)
RETURN DeleteFile(path + filename)
resolves to the DeleteFile() function (if there exists one such function), so for VO/Vulcan compatibility, we will adjust also the x# compiler to search for a same named function first, before resolving the call to the same-named method. That will happen for the vulcan dialect, not sure if it should be done for the core dialect as well.
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Mixing functions and methods
Hi Chris, hi Robert,
personally I would prefer that a self or this prefix would be required. In C# this is not neccessary as there are no functions, but for X# it would be better to read.
(IMHO X# code is much more readable than C# code).
Wolfgang
personally I would prefer that a self or this prefix would be required. In C# this is not neccessary as there are no functions, but for X# it would be better to read.
(IMHO X# code is much more readable than C# code).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Mixing functions and methods
By making it explicit when the programmer meant to call the method and when the function.Robert wrote:Otto,
How can the compiler "know" that you are not calling yourself recursively on purpose ?
The discussion is, I think, 'fundamental' about mixture of functions and methods and the change from VO (where 'SELF:' is mandatory) to .NET (where it isn't and even Resharper gives you a warning(!) when you use 'this.'). We have two cultures here that are mixing.
I see a few options which could have 'prevented' this (unittests of course )
1. when there is a function and a method with the same name, the compiler could raise a warning that there are two possible solutions, 'if you don't specify which you want, the compiler will take the function'.
2. Vulcan.net or any other language that support 'functions' MUST use the SELF: prefix when the programmer wants to call a method.
In c# I also follow the preferred standard. We even prefer 'Resharper green'.And w.r.t. writing code with or without self/this, that is a matter of style.
I know many companies that prefer not to use this/SELF when not necessary.
For Vulcan this situation bothers me. One can even hijack a method by creating a function with the same name in the same namespace, and one will not know it at compiletime...
Mixing functions and methods
that's what I meant. it took you a lot less words than mewriedmann wrote:Hi Chris, hi Robert,
personally I would prefer that a self or this prefix would be required. In C# this is not neccessary as there are no functions, but for X# it would be better to read.
In the core language or other dialects, when there are no functions, it could be optional, like in c#.
Mixing functions and methods
Otto,
Like Chris said: we are considering to add a warning here. Not for the next build but it will come.
Robert
Like Chris said: we are considering to add a warning here. Not for the next build but it will come.
But in this case, since you have deleted the DeleteFile() function, there is no ambiguity: DeleteFile() is only a method. What should the compiler do? Allow the code to compile without SELF: ?Otto wrote: 1. when there is a function and a method with the same name, the compiler could raise a warning that there are two possible solutions, 'if you don't specify which you want, the compiler will take the function'.
2. Vulcan.net or any other language that support 'functions' MUST use the SELF: prefix when the programmer wants to call a method.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Mixing functions and methods
Before the deletion of the (library reference containing the) function the compiler could have raised a warning because of the ambiguity.
Now (after the deletion) it should raise a warning because I don't use the SELF keyword here (because functions are part of the language dialect).
Now (after the deletion) it should raise a warning because I don't use the SELF keyword here (because functions are part of the language dialect).