Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Suggestion: New special variable for pipeline enumeration index

Reply
 
Old 04-17-2008   #11 (permalink)
RickB


 
 

Re: Suggestion: New special variable for pipeline enumeration index

On Apr 16, 10:12*am, MichaelL <goo...@xxxxxx> wrote:
Quote:

> On Apr 15, 10:56 pm, RickB <rbiel...@xxxxxx> wrote:
>
Quote:

> > But even here, there must be a place to store it, meaning the integer
> > must be a property on some object associated with every single step in
> > every single pipeline of every user everywhere, just because you
> > don't feel like adding a counter to the step where you happen to need
> > counts.
>
> Simple - store the integer as a member of the Cmdlet class. The memory
> (and cpu) overhead would be minuscule.
>
> And you're focusing on the wrong thing - you're considering this as
> though it were a counter of objects. *My suggestion for $% would be a
> counter of operations on objects, a logical supplement to $_. *And
> just like $_ it is transient and provides transient information while
> processing the pipeline - but this information can then be used
> wherever beneficial. *Your arguments against it would equally apply to
> $_ itself!
>
Quote:

> > You could even create a step in your pipeline that attaches a noteproperty
> > to each object with it's sequence. *Then you would have it everywhere
> > without even having to maintain counters everywhere.
>
> Granted that annotating the objects themselves, as you have suggested,
> is trivial enough, but doing so addresses a somewhat different use
> case. *It's also a very expensive operation.
>
> What I'm suggesting is massively cheaper, in terms of both cpu and
> memory, (vanishingly so in fact), is trivial to implement, is highly
> generic and provides a feature that is directly analogous to one of
> the most commonly used in other text processing languages. *(such as
> 'NR' in awk) * It's usefulness in such languages is proven and
> incontrovertible.
>
> What I'm suggesting isn't going to change the world because, and, yes,
> the effect can be simulated in other ways, but at either much greater
> cost or significant inconvenience. *However improving the feature-set
> of a product such as powershell involves comparing the cost of a
> feature to the possible usefulness. *I'm suggesting provide easily
> accessible information about the activity of the pipeline which
> typically relates to a "real-world" meaning of the entities that are
> being processes, and does so with virtually no cost.
>
> All your arguments have been centered on misunderstandings that have
> led you to be inappropriately concerned about a performance hit that
> doesn't exist.
>
> And arguing, as you have done, that a feature has no usefulness
> because you don't do the kinds of operations where it would be useful
> is like saying no one could possibly have a need for Excel because all
> you do is write letters.
>
> Michael
If this actually gets any traction I'm guessing that it will
immeditely
be requested that it work in foreach loops too. There it might even
open the door to requests that foreach handle hashtables/dictionaries
using $% would represent the key...

I know every feature is something that someone else might never use.
My initial reaction was based on experience with idiosyncracies of
other languages rather than rational thought about an implementation
in this particular.
I appologize.
My opposition clearly deserves dropping.

My System SpecsSystem Spec
Old 04-18-2008   #12 (permalink)
Joel (Jaykul) Bennett


 
 

Re: Suggestion: New special variable for pipeline enumeration index

On Apr 16, 11:12 am, MichaelL <goo...@xxxxxx> wrote:
Quote:

> On Apr 15, 10:56 pm, RickB <rbiel...@xxxxxx> wrote:
>
> Simple - store the integer as a member of the Cmdlet class. The memory
> (and cpu) overhead would be minuscule.
Scripts, Functions and Script Cmdlets aren't derived from the Cmdlet
class...
Quote:

> And you're focusing on the wrong thing - you're considering this as
> though it were a counter of objects. My suggestion for $% would be a
> counter of operations on objects, a logical supplement to $_.
To be clear, you're talking about two different things here, the $_ is
the *pipeline output* from the command before (or the automatic
iteration variable) which only exists in scripts. There is no $_ in
cmdlets -- PowerShell takes the output from one pipeline step and
feeds it into the property marked ValueFromPipeline on the next
pipeline step (if there is one) and/or parses it's properties to find
matches for the properties marked ValueFromPipelineByPropertyName ...
Hypothetically, cmdlets (and script cmdlets) could have a property
marked [CounterFromPipeline] or something, *and* provide it as a $%
variable to the PROCESS block on scripts and functions.

However, my objection still stands.

You said earlier that you want $% to be an "integer value holding a
count of the number of items that a pipeline has processed" -- this
number is DIFFERENT for each step of the pipeline at any point in time
(if you don't think so, then you must not have run the script from my
last post). I'm not sure what you mean now by "a counter of operations
on objects."
Quote:

> Your arguments against it would equally apply to $_ itself!
The $_ is the reason for the existence of the "process" block -- it is
the pipeline output that is being passed into the script/function/
script cmdlet's "process" block as the output is enumerated -- without
it, the process block has nothing to do. Your proposed counter, on
the other hand, is _extra_ information -- information that *could* be
calculated by the process block.

My objection is just that it _should_ be calculated there, since most
commands (by this I mean cmdlets and script cmdlets, scripts, and
functions) won't have a use for it -- no matter how little the work
seems, do it when you need it, not all the time.
Quote:

> What I'm suggesting is massively cheaper, in terms of both cpu and
> memory, (vanishingly so in fact), is trivial to implement, is highly
> generic and provides a feature that is directly analogous to one of
> the most commonly used in other text processing languages. (such as
> 'NR' in awk) It's usefulness in such languages is proven and
> incontrovertible.
As I understand it, what your suggesting would necessarily have the
same cost as having every command implement it's own counter even if
they didn't need it. The commands which do need it, incidentally,
already do calculate it -- as an example, these two lines do basically
the same thing (in Bash and then PowerShell), and both awk and more
count the lines themselves, rather than getting it from the host:

cat *.txt | awk 'NR <= 100' | more

cat *.txt | select -first 100 | out-host -p

Although awk is technically a language all of it's own, it's really
analogous to a cmdlet in powershell -- the shell doesn't track counts,
"awk" the app does.

I'm not saying there's no usefulness in being able to count pipeline
items ... there clearly is. I'm just saying that having the shell do
it for every command is wasteful compared to doing it in the few
commands that need a counter -- In any case, I don't actually have any
say in the matter ;-)

Incidentally, the shell does track all of this sort of information
that you couldn't figure out on your own ... the $MyInvocation
variable has stuff like what line of a script the command was called
from, the position on that line of this specific command, the number
of commands in the pipeline, and which position this command is in,
etc.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Current script special variable PowerShell
Networok Enumeration Vista networking & sharing
Suggestion: I submitted a suggestion for a Generic Soap Cmdlet via Connect. Please check it out and vote. PowerShell
Variable issues within pipeline using wmi PowerShell
Suggestion: Consider shorter standard names for Alias.Function, and Variable PSDrives PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46