-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Allow ByRef overloading in VB #505
Comments
ByVal is the default, why not have it the other way around?
This has the advantage of allowing ByRef to be optional for ref/out parameters in all cases. I found this issue while looking for that as a suggestion: I think it would make sense, as it makes the code more explicit and understandable. |
@jrmoreno1 |
First of all, I'm wondering why anyone would overload a method where the only difference was ByVal vs By Ref... I guess the obvious answer would be so that SOMETIMES they could modify the parameter and SOMETIMES they couldn't. Using the same method name in that case wouldn't seem the best programming practice IMHO... but that's just my opinion. If we're going to add new syntax to parameters, then I would suggest going all the way and implementing In, Out, as well as ByRef. Although I don't like the C# implementation of "In". To me, if I specify "In" the parameter shouldn't be allowed to be changed, regardless of whether I passed it by Val or Ref. |
Hi @Nukepayload2 , Delegate Sub Arg_in(Arg As Int)
Delegate Sub Arg_out(ByRef Arg As Int)
Dim Call_in = New Arg_in(AddressOf TestA)
Dim Call_out = New Arg_out(AddressOf TestA) |
This is not possible as VB has no difference in the call to a ByVal or ByRef parameter. So the simple solution is just to use another name for the Sub or Function. In and Out are great, but also without overloading on this. |
The problem with the Dim X = "Hello ''Adam''".
Replace ("''", Chr(34)) |
Yes, sorry. |
So this is a suggestion to change a language because the choices of another language allow the developers to write nonsensical code - code that shouldn't exist in a public API? If there was only a mechanism that was in place that said something like "if you are going to build public API's on this platform, you should adhere to these restrictions". If only such a thing were to exist and that thing could evolve over time as what was common upon languages evolves. If only. And if only the producer of said guidelines would ACTUALLY FOLLOW THEM. If only. In any case, just because someone can write bad API's in another language doesn't mean other languages should follow the crowd. |
I started to believe that vb should show any sign that the argument is ByRef or Out to make the code more readable and easy to understand, either by allowing adding optional those two keywords in front of the argument (like c#), or at least by showing the argument with special color in the editor. |
VB Supports before a ByRef parameter, there was an open issue to not require that variable to be initialized to avoid |
Don't see it in .NET Core 5 console app. |
This suggests to consider
And if x already declared, the Dim statement will be dropped. |
Overloading between in parameters and out or ref parameters is supported in C#.
But in VB, if you want to call one of an overload method which differ only by ByVal and ByRef, the compiler will report error BC31429 .
This feature was used in some C# class libraries such as CocosSharp, made them incompatible with VB.
C# signature:
C# call:
Suggested new VB syntax to distinguish between ByVal and ByRef:
The text was updated successfully, but these errors were encountered: