A) people will vote for the issue on Connect
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=334093&SiteID=99
B) Someone may be able to explain why the concept of "filter" is worth
having.
First of all, I know that typing:
filter name { "Filtering $_" }
saves you 9 characters over typing:
function name {process{ "Processing $_" }}
But I remain unconvinced that saving typing "process" and a pair of
braces is worth the confusion inherent in the fact that if you type
those two lines you'll overwrite the first definition of "name" with
the second definition (something which is an unavoidable side effect
of the fact that filters are really functions, and in fact, if you
execute: {Get-Command name} after defining the filter, you'll see that
PowerShell defines it exactly the way I defined the function.
Until recently, I thought there was no difference, other than the
syntax ... then I was trying to specify the CommandType to the Get-
Command function, and noticed two things:
1) if you Get-Command -Type "Filter" it includes all the Function
types as well (even though it lists them as Filter and Function in the
CommandType column)
2) if you define a filter, and then define a function with the same
name, it overwrites the filter, BUT IT DOES NOT update the
CommandType,
My current opinion is that the "filter" thing is more harmful (by
virtue of being confusing) than helpful ... anyone care to provide a
counter argument?
I can't remember that last time I used a filter. I suspect with script
cmdlets in V2 I will be even less likely to use them
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
The filter keyword predates full functions (with begin/process/end clauses)
by at least a year. It also predates scriptblocks and
Foreach-Object/Where-Object. When I added it, it didn't look like we were
going to have functions with more than one body element and I wanted some
kind of streaming capability in scripts. We kept it in the product because
it felt like a useful concept (and the concept is, just not this syntax).
So now "filter" is just syntactic sugar allowing a function that only has a
process block like
function double {process {$_*2}}
to be written more concisely as
filter double {$_*2}
I had expected that this shortcut would be more useful than it has turned
out to be however scriptblocks and where-object/foreach-object have pretty
much eliminated the need for simple named filters.
I suppose it might have been more useful if it was a shorthand for
function IsContainer {process { if ($_.PSIsContainer} {$_}}
so you could write
filter IsContainer {$_.IsContainer}
instead. The "filter" keyword will still exist in version 2 but we'll
consider removing it in a future version. As to whether we'll continue to
return both FunctionInfos and FilterInfos, I'm open to dropping the user of
FilterInfo (the class has to continue to exist or we'll break too much
stuff.)
-bruce
--
Bruce Payette [MSFT]
Principal Developer, Windows PowerShell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
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
My Book: http://manning.com/powershell
"RichS" <Ri...@discussions.microsoft.com> wrote in message
news:CE77784B-9E1B-476C...@microsoft.com...