Automating the world one-liner at a time…
<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
PingBack from http://msdnrss.thecoderblogs.com/2008/01/19/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. "
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
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
FYI, I voted on it yesterday without a problem.
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"... :)
"Highway to PowersHell"
Sometime soon to be an Mp3. Guard your ears.
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
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 ;)
[Former MVP Admin Frameworks ]
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.
I've been using this for block comments in Powershell:
COMMENT GOES HERE
'@ > $null
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:
That certainly looks better. For example, http://git.kernel.org/?p=git/git.git;a=blob;f=alloc.c;hb=HEAD
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.
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.
I kind of like having a # on every line. Yeah it looks hacky but it feels right for a scripting language.
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).