Welcome to MSDN Blogs Sign in | Join | Help

Block Comments

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

Published Saturday, January 19, 2008 10:09 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# MSDN Blog Postings » Block Comments

Saturday, January 19, 2008 7:00 PM by MSDN Blog Postings » Block Comments

# re: Block Comments

Looks like the page link to connect leads to a Page not found or maybe it's not up yet.  

"The content that you requested cannot be found or you do not have permission to view it. "

Sunday, January 20, 2008 10:41 AM by Anonymous

# re: Block Comments

the link to the connect database does not work.

I think this debate is already solved by using Here-string, http://www.microsoft.com/technet/scriptcenter/resources/pstips/jun07/pstip0629.mspx

I use these on all my scripts at the beginning to document my script but I think here-string could also be used for commenting out large blocks of code

Sunday, January 20, 2008 11:52 AM by Sean McNeill

# re: Block Comments

Hmmm, the link works for me so that means that either you need to already have to be registered with CONNECT to use it or you have to be me to use it.  :-(

You can navigate to the issue by signing into connect and searching FEEDBACK for:

   CTP: Missing: Real uncomment a block

RE: Here Strings.  THe issue with HERE strings is that they only work for content that is PROPER PowerShell syntax (i.e. PowerShell script).  It does not work for arbitrary text.

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

Sunday, January 20, 2008 12:03 PM by PowerShellTeam

# re: Block Comments

FYI, I voted on it yesterday without a problem.

-----

Shay Levi

$cript Fanatic

http://scriptolog.blogspot.com

Sunday, January 20, 2008 12:11 PM by Shay Levi

# re: Block Comments

Well I'll admit to being (other than writing silly songs) a VERY new Powershell "newb".

As far as comments go here is my take.

If you FULLY understand the syntax, the "Block comment /* */ like in C makes it a LOT more readable.

If you are very new a simple # like used in Batch Files, Basic etc etc etc make's it easier to go through and understand what ISN'T code.

That's all.  I'll leave it to the experts on a good old fashioned "Rumble"... :)

Cheers

Sean

"Highway to PowersHell"

Sometime soon to be an Mp3.  Guard your ears.

Sunday, January 20, 2008 1:46 PM by Sean Kearney

# re: Block Comments

Now for an "unfunny" comment / question.

What is a decent book to pickup to get you into the "Basics" of Powershell but is also a good overall deeper manual if needed?

Basically Powershell for Dummies :O

Sean

Sunday, January 20, 2008 1:50 PM by Sean Kearney

# re: Block Comments

Block comments are the best. Please oh please include them in PS 2.0. It will help promote the concept of actually commenting your scripts (what a novel idea) since it's not as tedeious for those of us who still use notepad :)

For Sean: I'm working on Windows PowerShell 2.0 for Dummies for Wiley Press at the moment if that counts ;)

Steve Seguis

[Former MVP Admin Frameworks ]

Monday, January 21, 2008 12:03 AM by Steve Seguis

# re: Block Comments

Please support block quotes! One of my peeves about writing & debugging VBscripts is the inability to mass-comment lines of code.

I'll insert a comment/vote on Microsoft Connect as well.

Monday, January 21, 2008 9:19 AM by Trevor Sullivan

# re: Block Comments

I've been using this for block comments in Powershell:

@'

COMMENT GOES HERE

'@ > $null

Monday, January 21, 2008 9:52 AM by Orrin

# KISS

Go with multiline # comments. /* .. */ comments mixed with # one-line comments will look ugly.

In fact, C programmers sometimes comment like the following for good reasons:

/*

* Now

* is

* the

* time

* to

* use

* PowerShell

*/

That certainly looks better. For example, http://git.kernel.org/?p=git/git.git;a=blob;f=alloc.c;hb=HEAD

Monday, January 21, 2008 11:59 AM by Sridhar Ratnakumar

# re: Block Comments

You know what?  You're right.  It takes me very little time to get used to normal code and looking at it twice, the block comments are a lot more readable.

:)

Monday, January 21, 2008 7:36 PM by Sean Kearney

# re: Block Comments

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

Sounds like you could have a promising career in talk radio... '-)

Anyway, YES, provide multi-line comments. And MAKE THEM NESTABLE.

Tuesday, January 22, 2008 8:41 PM by Mike Schinkel

# re: Block Comments

I kind of like having a # on every line.  Yeah it looks hacky but it feels right for a scripting language.  

Wednesday, January 23, 2008 12:42 PM by JaredPar

# re: Block Comments

I've tried searching from Connect as the first comment suggested but I cannot find this.  I am a member of Connect (had to deal with DST last year).

Wednesday, January 23, 2008 4:21 PM by jw

# re: Block Comments

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?

Thursday, January 24, 2008 10:51 AM by Sean

# re: Block Comments

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.

Wednesday, January 30, 2008 9:45 AM by LeoTohill

# re: Block 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.

Tuesday, February 26, 2008 5:17 AM by Alex Hokhlov

# re: Block Comments

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!

Wednesday, May 07, 2008 1:09 PM by dtginc

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker