Skip to content

ByVal in VB samples #13912

Closed
Closed

Description

@Youssef1313

I think specifying ByVal for method arguments makes the code look noisy. It will be much cleaner to write:

Private Function FunctionName(arg1 As Type1, arg2 As Type2)
End function

instead of:

Private Function FunctionName(ByVal arg1 As Type1, ByVal arg2 As Type2)
End function

There are many code samples I've seen so far that has ByVal specified for method arguments.
Should you consider updating these samples ?

Activity

  1. rpetrusha commented on Aug 19, 2019

    @rpetrusha
    Contributor

    Since ByVal is the default, it doesn't have to be explicitly specified. I agree with you, @Youssef1313, that is noisy. It also has the unfortunate effect, in my experience, of causing the occasional ByRef keyword to be overlooked. So it would be useful to remove it.
    I'll add this item to our backlog and the Community Contributor's project. If you're interested in removing ByVal from some or all of the examples, try to submit PRs that touch a small subset (approximately 100 or so) of files at a time.

  2. added this to the Backlog milestone on Aug 19, 2019
  3. paul1956 commented on Aug 20, 2019

    @paul1956
    Contributor

    There should be a CodeFix for removing ByVal and there may be third party tools that can do it for a whole project.

  4. Youssef1313 commented on Aug 20, 2019

    @Youssef1313
    MemberAuthor

    @paul1956 , I thought of that. but I'm not sure if unintended removal could be done in an automated solution. For example, the ByVal article itself has a code example, ByVal should NOT be removed there.
    I'm not sure if there could be other places where ByVal shouldn't be removed.

  5. paul1956 commented on Aug 20, 2019

    @paul1956
    Contributor

    A CodeFix only operates on "Code" and is smart enough to do the right thing, it can also be interactive.

  6. Youssef1313 commented on Aug 21, 2019

    @Youssef1313
    MemberAuthor

    @paul1956 , I'll try to do that soon when I get free time and see if I could get good results.

  7. paul1956 commented on Aug 22, 2019

    @paul1956
    Contributor

    I would be happy to post/contribute a standalone remove ByVal analyzer and refactoring if you think its interesting. It is very small.

  8. Youssef1313 commented on Aug 22, 2019

    @Youssef1313
    MemberAuthor

    Well, you can start that anytime and submit a small PRs ( as suggested by @rpetrusha ) if you want and they will review it, @paul1956 .

  9. paul1956 commented on Aug 22, 2019

    @paul1956
    Contributor

    I would like to start with correctly documenting line continuation in VB 16 I looked at the special character $ and has a line [!CODE-vbinterpolated-string-symbol] which seems to do no where in the Doc GitHub repo. does [!Code-vb have some special meaning?

  10. Youssef1313 commented on Aug 22, 2019

    @Youssef1313
    MemberAuthor

    [!code-lang....] is used in .md files to include a code sample.
    That is how to refer to a code in the samples repo from the docs repo.
    but I don't think you will find any [!code-lang...] in the samples repo. (Not very sure)

    The file you mentioned is here

  11. paul1956 commented on Aug 22, 2019

    @paul1956
    Contributor

    Tried doing a Pull Request and I get Error 500
    image

  12. paul1956 commented on Aug 22, 2019

    @paul1956
    Contributor

    I was working on the Doc Repo because I didn't see any VB code that needs work, The Doc's need updating for VB 16 and Core 3.0 and it seemed like a good place to start since there are lots of examples.

  13. paul1956 commented on Aug 22, 2019

    @paul1956
    Contributor

    Which Repo should I be looking at to find the VB code that needs moving? Can you provide a URL for the repo with 100 files that need ByVal removed it will only take a few minutes to do using a code fix I have.

  14. Youssef1313 commented on Aug 22, 2019

    @Youssef1313
    MemberAuthor

    I think you may start with samples repo, surely it has more than 100 files containing ByVal. But the work can be splitted into multiple PRs, each has about 100 files changed as suggested by @rpetrusha

  15. paul1956 commented on Aug 23, 2019

    @paul1956
    Contributor

    Many of the sample use older project formats, is it OK to upgrade to latest format? Eventually to get on Core will require format changes anyway.

  16. Thraka commented on Sep 13, 2019

    @Thraka
    Contributor

    FYI The automatic code inserted by visual studio snippets and autocomplete insert ByVal.

  17. Youssef1313 commented on Sep 13, 2019

    @Youssef1313
    MemberAuthor

    @Thraka, Do you mean the auto generated code like the designer file for winforms for example ?

    If yes. Then, In most cases, no one looks at that code. The more important is the code that the developer write himself. It looks much nicer without the noise produced by ByVal.
    For the auto generated code, I'm not sure if we can tell the VS team about that to address in later updates ?

  18. paul1956 commented on Sep 14, 2019

    @paul1956
    Contributor

    From what I understand the snippets in this repo are used to produce the product Snippets so my eliminating them here part of the issue is solved. I agree that eliminating them in all in the templates and the "System." in the Form Boilerplate would be great, not sure where to report the issue.

  19. Thraka commented on Sep 15, 2019

    @Thraka
    Contributor

    No I was thinking of something else, never mind :)

  20. added
    won't fix
    on Jan 25, 2021
  21. dotnet-bot commented on Jan 25, 2021

    @dotnet-bot
    Contributor

    This issue has been closed as part of the issue backlog grooming process outlined in #22351.

    That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the @dotnet/docs team for visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    won't fix

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions