-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Consider creating a conceptual help topic for calculated properties #3383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@matt9ucci, it would help if you clarified your thumbs-down vote; which aspect(s) of the proposal are you objecting to?
|
I teach PowerShell around the globe, and know that hash-table caculated properties are both an important aspect but also quite complex and confusing.
|
@mklement0 The former PowerShell-Docs admin says:
I would like you to consider writing real documents and PRs before opening issues. For example, After the PRs are successfully approved, you will be easily able to push the another PR of the conceptual doc and just say "Hey, I wrote a new conceptual doc. It is a copy of Format-Custom and some additional conceptual descriptions." I think such combination, real documents and progressive changes, is the most effective solution for smooth discussion and document improvement. |
Amen to that, @doctordns. Re 2: But as a part of PowerShell's "elastic syntax" for ad-hoc, command-line use, it's worth documenting the That said, it would help the stability problem if the |
I see two separate issues:
Re number 2, such a document would be along the lines of: |
Proposing a new topic is a contribution.
How is that related to whether this proposal has merit?
I don't understand what point you're trying to make: Because they have different key sets they're not fundamentally the same thing? It's too much wok? See table below.
Again, how is who implements the proposal related to whether it has merit?
Crucial conceptual information missing from the documentation does not call for progressive changes. Overview of which cmdlets support what key setsNote: The information below comes from inspecting
|
@doctordns: Fully agreed re 2.
The problem is longterm code stability: with elastic syntax, making your code work now doesn't mean that it will continue to work in future PowerShell versions, because the introduction of new key names could make a previously unambiguous name prefix ambiguous, causing the command to break. For instance, say you The proposal in PowerShell/PowerShell#8429 would take the keys out of the realm of elastic syntax - which is still useful in the context of parameter names for ad-hoc, one-off use - and guarantee that |
I suspect changes in the hash table keys supported calculated properties are pretty unlikely, but never say never. In the case that such a change was seriously to be suggested, that change would have to allow for the fact that it could be a breaking change and the community could take a view. Of course, those following the recommended best practice continue to be unaffected - the only people affected would be those using short forms typically from the command line. |
It's not a breaking change, because there is currently no ambiguity: no two keys for a given cmdlet start with the same letter; there is potential for cross-cmdlet ambiguity between The proposed change is fully backward-compatible; its value is in providing official short aliases that can be used in a future-proof manner, whereas the current implementation bears the risk of breaking old code in the future. |
Uh oh!
There was an error while loading. Please reload this page.
Calculated properties can be used with many cmdlets (
Select-Object
,Format-*
,Sort-Object
,Group-Object
,ConvertTo-Html
, possibly others, and, since v6.1,Measure-Object
).They're an important concept, yet only mentioned tersely in the context of the
-Property
parameter description.I think a dedicated conceptual topic that the cmdlet topics can link to would help, along the lines of
about_Calculated_Properties
.Things that should be covered:
The hashtable keys need not be spelled out, as long as the specified name prefix is unambiguous, so that
n
can be used in lieu ofName
, ande
in lieu ofExpression
.You may specify the expression script block directly as an argument (as opposed to specifying it as the
Expression
entry of an enclosing hashtable), e.g.,'1', '10', '2' | Sort-Object { [int] $_ }
, which is convenient for cmdlets that do not require (or support) naming a property via theName
key, such asSort-Object
,Group-Object
andMeasure-Object
Measure-Object
, unlike the other cmdlets, doesn't support passing a hashtable at all, and only accepts a script block, because its-Property
parameter ispsropertyexpression[]
typed, not[object[]]
typed.Name
key for naming the property will automatically use the script block's stringified content as the name.Pipeline logic is applied to the output from
Expression
script blocks, which means that outputting a single-element array will cause that array to be unwrapped.Errors inside expression script blocks are quietly ignored.
Sort-Object
, where statement- and script-terminating errors are output, but they do not terminate the statement.Expression script blocks run in child scopes (meaning that the caller's variables cannot be directly modified).
The text was updated successfully, but these errors were encountered: