Bad practice for passing ByRef and ByVal parameters in the same procedure?

Is it bad practice (VB.NET or any language) to encode a function with ByVal and ByRef parameters that are used in my getFile function below?

Function getFile(ByVal channel As Integer, _ ByRef Filename As String, _ ByRef Filesize As String) As Integer ... End Function ... Dim status As Integer Dim filename As String Dim filesize As Integer For channel In 1 To 16 status = getFile(channel, filename, filesize) ... Next channel 
+4
source share
1 answer

I usually try to avoid ByRef together; it often ends up being ugly and confusing. The fact that you mix ByVal and ByRef does not affect readability, not just all ByRef IMHO.

For example, if I only need the file name, I still need to pass the filesize variable, which, in my opinion, makes it a little ugly. And when reading the code, it is easy to miss that the parameter can be changed.

As Assaf says in his comment, instead I usually try to get around the whole problem if the method returns some kind of structure that can contain all the returned data. and if that fails, I would throw an exception, and not return a status (assuming the status is some kind of error).

+6
source

All Articles