Skip to content

Introduce a more descriptive parameter alias for Get-Content -Raw #7715

Closed

Description

The filesystem provider's -Raw switch for Get-Content is confusingly named:

  • raw suggests reading raw bytes, which is not what it does.

  • conversely, raw doesn't convey that the file is being read as a whole.

Without breaking backward compatibility, a more sensibly named parameter alias could be defined, such as -Whole.

Environment data

Written as of:

PowerShell Core 6.1.0-preview.4

Activity

  1. added
    Issue-Discussion
    on Sep 6, 2018
  2. iSazonov commented on Sep 6, 2018

    @iSazonov
    Collaborator

    The parameter is not documented well :-)

  3. MartinSGill commented on Sep 6, 2018

    @MartinSGill

    I, personally, don't have a problem with it. I know Get-Content always returns an array of strings (at least for text files), so 'raw' to me means just the raw text, without any splitting.

  4. mklement0 commented on Sep 6, 2018

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov) : Good point, but that's a separate issue:

    The parameter description in the context of the filesystem-provider-specific help topic is passable, but can be improved: MicrosoftDocs/PowerShell-Docs#2697

    In the provider-independent help topic - the one that's discoverable far more easily - the generic description is downright misleading:

    This parameter is not supported by any providers that are installed with PowerShell.

    However, that, and the difficulty in locating the provider-specific help topics, are fundamental, structural problems not specific to -Raw that will go away (hopefully soon), according to MicrosoftDocs/PowerShell-Docs#1101 (comment):

    Yeah, the provider-specific help is a work-in-progress. Long story but we are working on it. The goal is to wrap all of that content into the provider-affected cmdlets and get rid of the provider-specific docs.

  5. mklement0 commented on Sep 6, 2018

    @mklement0
    ContributorAuthor

    Martin Gill (@MartinSGill):

    The typical connotation of raw in the context of files is uninterpreted (undecoded) data ("raw bytes").
    (As such, you could argue that -Raw should be an alias of -AsByteStream, which is the closest thing PowerShell has to passing bytes through.)

    By contrast, -Raw does perform interpretation / decoding, namely decoding the file's bytes to strings based on the file's assumed or explicitly specified character encoding, just as without -Raw.

    The only thing that -Raw changes is the partitioning of the data read, so that is what the switch name should reflect, hence my suggestion -Whole

  6. BrucePay commented on Sep 6, 2018

    @BrucePay
    Collaborator

    Michael Klement (@mklement0) "Raw" in this context means, "undecorated", "not cooked", etc. This is the parameter that the PowerShell team has chosen for this purpose. We could have chosen a different parameter but we did not. Some people will complain that it doesn't mean the right thing to them. That's fine. No matter what we choose, this will always be the case because different people have different perspectives. In PowerShell we try to choose a single term and apply it consistently so that, even if it does not seem intuitive to a person, they only have to learn it once. Sometimes we choose a sub-optimal term but we live with it because you should only have to learn something once. Very rarely, we try and "fix" things like we did with $_ and $PSItem. This sounded good because new users didn't "get" $_. So we added $PSItem as being easier to understand. The feedback we received from people who teach PowerShell is that rather than helping, having to teach two terms made it worse/more confusing for people trying to learn PowerShell.

  7. mklement0 commented on Sep 6, 2018

    @mklement0
    ContributorAuthor

    Bruce Payette (@BrucePay):

    "Raw" in this context means, "undecorated", "not cooked", etc. This is the parameter that the PowerShell team has chosen for this purpose.

    That would be fine, except, as previously stated, that is not what -Raw actually does:

    • It still decorates its (one) output string.
    • All it does is change the units of data being read from lines (by default) to the whole file.

    In other words:

    • The reality of the switch does not align with the stated purpose and this regrettable precedent prevents meaningful use of -Raw in other contexts in alignment with its true purpose.

    • One way of dealing with a misnomer is to provide a more sensibly named alias and to deprecate / deemphasize the old name.

      • In other words: The intent is for the new name to in effect supersede the old one, so the $_ / $PSItem comparison doesn't apply (given that neither is deprecated).

      • Yes, there will be confusion for a while, but over time the sensible name will (hopefully) prevail.

  8. BrucePay commented on Sep 6, 2018

    @BrucePay
    Collaborator

    The reality of the switch does not align with the stated purpose and this regrettable precedent prevents meaningful use of -Raw in other contexts in alignment with its true purpose.

    As I said, people will have different opinions on how whatever term we choose should be interpreted. Breaking the text into strings can be viewed as "cooking" and thus -Raw should return a single string.

    One way of dealing with a misnomer is to provide a more sensibly named alias and to deprecated / deemphasize the old name.

    We've never actually deprecated anything and aren't likely to do so anytime soon.

  9. mklement0 commented on Sep 7, 2018

    @mklement0
    ContributorAuthor

    We've never actually deprecated anything and aren't likely to do so anytime soon.

    That genie is already out of the bottle:

    -RootModule
    [...]
    In Windows PowerShell 2.0, this key was called ModuleToProcess.


    As I said, people will have different opinions on how whatever term we choose should be interpreted.

    You yourself noticed the problem with -Raw int the context of #7537: #7537 (comment)

    We added -Raw a long while back to address the perf issue but it doesn't really do the right thing.

    Since this discussion has now broadened in scope, let me reiterate and expand on what I proposed as an aside in #7713:

    • Retire the skunked -Raw, as proposed by this issue.

    • Introduce a general-purpose -Bare switch with the following, cross-cmdlet semantics:

    Output "bare" objects that are:

  10. iSazonov commented on Sep 7, 2018

    @iSazonov
    Collaborator

    We have too many such discussions without a conclusion.
    I think PowerShell Committee can consider this - should we replace -Raw with -Whole (as alias) or Won't fix?

  11. added
    Review - Committee
    on Sep 7, 2018
  12. mklement0 commented on Sep 7, 2018

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): To be clear: -Bare is not the right (alias) name for the current -Raw switch. As proposed in the OP, something like -Whole would make sense.

    Deprecating -Raw in favor of something more descriptive such as -Whole would clear the way for use of -Bare with the semantics described above, and -Bare would then become a new switch in the context of Get-Content, for requesting undecorated lines (strings without ETS properties), as suggested in #7537

  13. BrucePay commented on Sep 7, 2018

    @BrucePay
    Collaborator

    Michael Klement (@mklement0)

    That genie is already out of the bottle:

    -RootModule
    [...]
    In Windows PowerShell 2.0, this key was called ModuleToProcess.

    And yet it's still there in version 6, both as a parameter alias and mentioned in the .psd1 file:

    # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
    # NestedModules = @()

    Deprecated implies "don't use, will be removed at some future time". We don't do this. What we do is deemphasize things.

    In this specific case, "RootModule" is semantically much stronger than "ModuleToProcess". There is a clear semantic advantage in using one term over the other whereas -Base and -Raw - are almost synonyms (at least in this context).

    You yourself noticed the problem with -Raw int the

    Yes :-) I had intended/expected that -Raw should write a stream of undecorated strings into the pipeline however the developer who actually implemented it chose a different interpretation.

    Deprecating -Raw in favor of something more descriptive such as -Whole would clear the way for use of -Bare with the semantics described above, and -Bare

    Again, -Raw isn't going away so you'd have a cmdlet with both -Raw and -Bare which is pretty confusing (unless you make one an alias of the other in which case the semantic doesn't change.). Also the current -Raw semantic can be "fixed" by adding -Stream as in Out-String -Stream so you'd do gc -raw -stream foo.txt.

    Ilya (@iSazonov) The committee doesn't need to be involved in a parameter change but if we do want to propose a new normative pattern, it should go through the RFC process.

  14. vexx32 commented on Sep 7, 2018

    @vexx32
    Collaborator

    I would be in favour of leaving -Raw as an alias and changing the name to -Bare

    I'd potentially be in favour of using -Bytes as a switch to specify to retrieve the bytes in the file per line, which could operate hand in hand with a -Whole switch to read the bytes of the entire file (or just flat out always read all bytes in the file indiscriminately).

  15. 4 remaining items

  16. added
    Committee-Reviewed
    and removed
    Review - Committee
    on Sep 19, 2018
  17. mklement0 commented on Sep 19, 2018

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT)

    -Bare is not different enough from -Raw to communicate functional differences.

    Agreed - but that's precisely why I suggested introducing -Whole and de-emphasizing -Raw.

    -Bare wouldn't just benefit Get-Content, but, as I've proposed above, could become a general pattern for all cmdlets where undecorated / unwrapped output is desirable on an opt-in basis.

  18. iSazonov commented on Sep 20, 2018

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) It make sense to move the Bare proposal in new issue. It would be a new common parameter.

  19. mklement0 commented on Sep 24, 2018

    @mklement0
    ContributorAuthor

    Good idea, Ilya (@iSazonov) - please see #7855

  20. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  21. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  22. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  23. added
    Resolution-No Activity
    on Nov 16, 2023
  24. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedIssue-DiscussionResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions