Core2: Inline and multi-line comments

[This post is part of a series, "wish-list for future versions of VB"]

IDEA: Allow comments within multi-line statements, and in blocks, and within expressions.

    Sub g(ByVal f As String,  ' filename

          ByVal y As String   ' access mode



    End Sub



    Dim h = Sub()  ' a small subroutine

            End Sub


    Dim l = From g In gs   ' out of all the gin joints in all the world

            Select g.sam   ' you had to pick this one


    Dim k = {"hello",   ' the first element of the array

             "world"    ' the second



    (* This is a multi-line

       comment block




    Sub f(ByVal f As String (* filename *), ByVal y As String (* access mode *))

    End Sub


    Dim x = <xml>

                <a></a>  ' comment impossible here because we’re in XML-land



SCENARIO: Now that we’ve removed the need for line-continuation characters, and introduced more multi-line constructs (lambdas, array literals, LINQ queries), we have a stronger need for comments within these statements and expressions.


Provisional evaluation from VB team: This is a decent idea. However, the current compiler architecture dates back from the days that VB was strictly line-oriented language so we’d have to refactor the compiler first (see “Req0: Don’t add to (or change) the language”).

Comments (13)

  1. edddy says:

    Nice to have inline comments, but I don’t see multi-line comments useful.


    Sub f(ByVal f As String (* filename *), ByVal y As String (* access mode *))

    it would be better if you refactor the variable names, or simply use:

    Sub f(ByVal f As String,  ‘filename

        ByVal y As String) ‘access mode

  2. Dzonny says:

    Yes, please allow inline and multiline comments.

    1) Especially allow comments at the end of explicitly or implicitly continued line

    One thing missing from your example:

    If x < 10 Then _ ‘x is lower than 10

       Console.WriteLine("x is lower than 10")

    2) In XML – what about ASP.NET-like comments

    dim x = <root>

              <elem/> <%–this is comment–%>


    3) What about REM. Where it will survive (I suggest only in places where VB10 allows it)

  3. Nathan Tuggy says:

    Can’t you just use ordinary XML comments for 2), Đonny? Example:

     Dim x = <root>

       <elem/> <!–this is comment–>


    These work just fine, and even have nice (if subdued) syntax highlighting. In fact, these even work fine in VB 2008.

    As far as REM, I personally could care less what you do with it, as long as I never have to see it again. Comments should not have to use keywords, that’s my philosophy.

  4. Reinier Post says:

    Comments at the end of continued line: useful.

    Multi-line comments: not so useful.  Note how C/C++ programmers often paste comment characters in on every line of a comment block to make them stand out better.  I would not include this feature even if it was easy!

  5. Jens says:

    I really would like inline comments (in blocks and expressions), they would allow the cod to be much more readable.

    The multiline comment would be nice, but since there is an editor button to comment lots of lines, I can live without that.

  6. Michael Chandler says:

    I can’t say that comments in VB.NET are much of a pain point for me.

    Inline shouldn’t be needed often if parameters, etc, are well named.

    Comments on continued lines could be useful.

    Ctrl K + C handles multi-line commenting easily. I don’t think a new syntax is required.

  7. Dzonny says:

    Nathan, problem with this

    Dim x = <root>

      <elem/> <!–this is comment–>


    Is that the comment is part of resulting XML, which is not always what you want.

  8. Kyralessa says:

    Not sure where my original comment on this went; the captcha seems a bit flaky.

    Anyway, nearly every case with comments in the sample code would be much better off using XML documentation.  And XML documentation can be seen without having to go back to the source code.

    As for multiline comments, I find that in C# I hardly ever use them.  The only case I use them much is to paste in code that I need to then rework, e.g. VB code I’m converting to C#.  I’d rather see the VB team work on something else rather than spend time on comments.

  9. Simon Geering says:

    Inline comments would be very handy, block comments would be nice if it is a quick win but not nearly as important.

  10. Tojy John says:

    Why not we introduce a REM block as shown below? Good if the code editor automatically warps the text inside the REM block


     This is an

     example of


     REM block

    End Rem

  11. yannduran says:

    Inline comments especially would be extremely handy. I’ve wanted this for AGES. It’s one area where C# has it hands-down over VB.

    Some form of multiple-line comment would also be good, but a little less so than inline comments.

    I don’t particularly like rem/end rem, but it would be better than nothing. I lean more towards /* */

  12. <a href="">Andrew K.</a> says:

    Holy, this is what I have been looking for! Great, useful!

  13. Alexander Morou says:

    Why not '* and *'?

    It would make more sense than using '(' and ')' since they're already used for method calls, type-parameters, operator precedence coercion and so on.

Skip to main content