Compartir a través de


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

         )

        Console.WriteLine("{0}-{1}",f,y)

    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

            </xml>

 

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

  • Anonymous
    January 28, 2010
    The comment has been removed

  • Anonymous
    January 28, 2010
    The comment has been removed

  • Anonymous
    January 28, 2010
    Can't you just use ordinary XML comments for 2), Đonny? Example:  Dim x = <root>    <elem/> <!--this is comment-->  </root> 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.

  • Anonymous
    January 28, 2010
    The comment has been removed

  • Anonymous
    January 28, 2010
    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.

  • Anonymous
    January 29, 2010
    The comment has been removed

  • Anonymous
    January 29, 2010
    Nathan, problem with this Dim x = <root>   <elem/> <!--this is comment--> </root> Is that the comment is part of resulting XML, which is not always what you want.

  • Anonymous
    February 01, 2010
    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.

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

  • Anonymous
    April 19, 2010
    Why not we introduce a REM block as shown below? Good if the code editor automatically warps the text inside the REM block Rem  This is an  example of  multiline  REM block End Rem

  • Anonymous
    May 13, 2010
    The comment has been removed

  • Anonymous
    March 15, 2011
    Holy, this is what I have been looking for! Great, useful!

  • Anonymous
    July 16, 2011
    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.