Block Comments

Block Comments

  • Comments 35

<Update 01/04/2012: This post was written in 2008, when PowerShell was in version 1. Block comments were introduced in Version 2.>

One of the raging debates that have had within the team is the issue of whether to support block comments.  In PowerShell, we have the comment character #  e.g.

# This is a test
get-Process -Name LSASS # you can put a comment at the end of a line too

 

There are times when you have a large set of lines that you need to comment out (e.g. code in progress, cutting out code to test something, function headers, etc).  Some believe that we should support a block comment model like C.  e.g.

/*
Now
is
the
time
to
use
PowerShell
*/

 

so you don't have to put a # in front of every line:


# Now
# is
# the
# time
# to
# use
# PowerShell

Now you can join the debate.  The connect database has a bug filed on this that you can vote on or comment on.  https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=319307&SiteID=99

Let us know what you think.

If you need help knowing what to think, let me know and I'll tell you.  :-)

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 5 and 8 and type the answer here:
  • Post
  • I would like to see support for block comments as well as single line comments. If you support both you end up making everyone happy, even those that like Sridhar who use both at the same time. I think it is pointless to use /* */ for a single line but the guy who introduced me to programming would use that for a single comment line in his C/C++ code. Why just have one way?

  • Yes, there should be an language feature for block comments.  I like #@...@# in the style of here strings.  Like here strings, these tokens should be recognized only when alone on a line, thus avoiding accidental comments.

  • Block comments come in handy when I want to play with code in the MIDDLE of a line. Consider this: /* 0.5 * */ func($var1 /* 42 + args[0] */, bar($x) /* TODO: try $y */). Granted, one could break this piece into several lines and use # end comments, but that would look somewhat awkward and spacy. Beyond all good-style reasoning, I still believe the "one statement/one line" format is more natural, compact and easy to read.

  • Couldn't follow the link.  Here's my vote, though - PLEASE add block comments.  The /*...*/ is a good format.  Better yet, to keep with the # symbol, you could always use /#...#/.

    Thanks!

  • Was this ever resolved?

    I definitely vote for block comments and not an indirect solution such as @'...'@ > $null or @" ..."@  approach.

    karl

  • Yes - V2 will have block comments.

    <#

    anything you want

    ...

    #>

    jps

  • Many thanks for speedy reply and am glad to see that we'll have block comments soon.  will they be available on version 3?

  • They will be available in CTP3 which we expect will be available sometime in Dec.

    jps

  • Please enable block commenting.

  • I can't even begin to imagine why this is even considered debatable. GIVE US BLOCK COMMENTS!

  • C style block comments. Now. Why does every scripting language re-invent the wheel when it comes to comments? As others have said, there should be no debate about whether block comments are supported or not.

    /*

    this is a comment

    over a  number of lines

    */

    optionally it would be nice to also support

    // this is a comment

    but then I am just used to C and C++

  • OP is old and issue has been put to bed so this is really just a general note for the team on future features being debated.

    Why not give people the choice? Adding support for block comments doesn't FORCE people to use them - anyone who thinks it is bad practice can simply avoid them and they are no worse off at all.

    Given that adding support for block comments doesn't change or remove any other piece of functionality, I can't see why you _wouldn't_ add them?

    The short version is that if a proposed feature will make some people's life a little bit easier while not inconveniencing anyone at all then the decision should be easy. It's like having beer available by the six-pack and debating whether it should be made available by the case as well.

  • Sean try this

    powershell.com/.../ebook

  • give us our beer...er, block comments!  yeah, that's it.  

    But seriously, why not block comments?  I actually want to hear an arguement against them, other than that it looks prettier.

  • Crazy that they don't have block comments.  Coming from C based languages, I'd go for ./*...*/ myself.  Maybe we could make it look more like basic with `*...*`  : )

Page 2 of 3 (35 items) 123