Comments (3)
I like this.
I previously proposed to allow us to optionally add ByRef to ref arguments for better clarity of code. But, I don't think both proposals will happen as they need language changes which is not valid now.
from vblang.
I would argue that the underlying behavior is broken (or the documentation is, at the very least, misleading)...
Module ByrefTest
Structure PDQ
Public P As Integer
Public D As Decimal
Public Q As Long
Sub FooBar()
ByrefTest.FooBar(Me)
End Sub
End Structure
Sub FooBar(ByRef dst As PDQ)
dst.P = 123
End Sub
Sub Main()
Dim o As PDQ = Nothing
o.FooBar()
' Prints 0... expecting it to be 123.
Console.WriteLine($"{o.P}")
End Sub
End Module
I slightly modified the original code to reflect the point that, according to the documentation found at:
It states that the ByRef
keyword "specifies that an argument is passed in such a way that the called procedure can change the value of a variable underlying the argument in the calling code."
I don't see the need to have to specify ByRef
in both places. If the method specifies that it is ByRef
that should be enough. If you wanted to force it to be ByVal
(for whatever reason), we already have a mechanism in place to override that behavior. The problem as I see it is that the documentation suggests one thing but the implementation clearly doesn't follow what the docs specify.
from vblang.
To further illustrate why I believe this is a bug...
Module ByrefTest
Structure PDQ
Public P As Integer
Public D As Decimal
Public Q As Long
Sub FooBar()
ByrefTest.FooBar(Me)
End Sub
End Structure
Sub FooBar(ByRef dst As PDQ)
dst.P = 123
End Sub
Sub Main1()
Dim o As PDQ = Nothing
o.FooBar() ' Call FooBar within the structure...
Console.WriteLine($"{o.P}") ' Output: 0
FooBar(o) ' Call FooBar outside of the structure...
Console.WriteLine($"{o.P}") ' Output: 123
End Sub
End Module
If I modify the sample so that FooBar is called slightly differently, I get two different results... event though I'm essentially executing the same code. The only difference is the usage of Me
.
from vblang.
Related Issues (20)
- [Proposal] Additional Kinds of Is Clauses
- (off-topic?) inter-language 'drag race' competition HOT 20
- [Proposal] Tuple Sub-Clauses
- Support unmanaged generic constraint for interop with C#
- [T(Index) Is Nothing] is [CObj(T(Index)) Is Nothing] instead [T(Index) Is Default]. HOT 5
- Discard XML namespaces HOT 2
- Strange “type of” HOT 3
- Record method for My.Computer.Audio HOT 3
- Custom implicit Ctype is not used in dynamic mode HOT 4
- [Proposal] ReadOnly As InitOnly Properties
- "Two Anxieties and One Unarticulated Need - Why doing nothing is sometimes the right thing to do" -- Anthony D. Green HOT 5
- "An Alternative Path" HOT 2
- Open Silver Roadmap: VB.Net support HOT 1
- VB to support consuming API that has required members. HOT 3
- Open Letter on the Visual Basic Strategy 2023 HOT 34
- CDate(CStr(Nothing)) should not cause an exception HOT 5
- 请支持vb,please support vb HOT 10
- Small Visual Basic is meant to attract kids to VB .NET HOT 1
- null-conditional for boolean operation should be typed to nullable HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vblang.