X Tutup
The Wayback Machine - https://web.archive.org/web/20230122194651/https://github.com/PowerShell/PowerShell/pull/17483
Skip to content
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

Add indented here-string and single line here-string #17483

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MartinGC94
Copy link
Contributor

@MartinGC94 MartinGC94 commented Jun 4, 2022

PR Summary

Fixes #2337
Fixes #13204
There were a lot of different ideas posted in this thread, and this is just my own personal preference/idea on how to solve this.
I am open to other ideas if that's what the team/community wants.

You can add as many @ signs as you want to the here-string, if you add 2 or more @ signs you allow the string terminator to be indented like this:

Write-Host @@'
    Hello world!

        Here-strings are cool
    '@@

The line with the fewest leading whitespaces (not including empty lines) dictate how many whitespace characters are removed from each line so in the previous example the first line would have no spaces, and the third would have 4 spaces.

Single line here-strings are also supported: Write-Host @'Hello world!'@ like the multi-line variant you can add as many @ signs as you want.

There are 3 reasons why I picked multiple @ signs over multiple ' .
1: It's easier to visually easier to see/count if you write @@@@@' VS @''''' especially when you also consider double quotes and all the different single/double quote variants that are also supported.
2: If you decide to swap between a single quote and double quote here-string it's easier to just change 1 character in each end instead of multiple characters in each end.
3: In the case of single line strings it allows the string to start with any character. It quotes were used you wouldn't be able to start the string with a quote character because it would be counted as part of the "header" section of the here-string.

PR Context

It's annoying to not be able to match the surrounding indentation if you for example use a herestring inside a function. Even if the content doesn't care about the leading whitespace the string terminator does so you end up with an ugly little '@ if you try to indent all the code that can be indented.
Sometimes when writing string filters you end up needing to quote values inside the string which means you either need to remember to escape or use the opposite quotes. It's nicer to just start a filter with @' or @" and no longer worry about having to escape characters inside the string.

PR Checklist

@pull-request-quantifier
Copy link

This PR has 150 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +115 -35
Percentile : 50%

Total files changed: 2

Change summary by file extension:
.cs : +109 -35
.resx : +6 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  👌  👎 (Email)
Customize PullRequestQuantifier for this repository.

@msftbot msftbot bot added the Review - Needed The PR is being reviewed label Jun 12, 2022
@msftbot
Copy link

msftbot bot commented Jun 12, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@MartinGC94 MartinGC94 changed the title WIP: Add indented here-string and single line here-string Add indented here-string and single line here-string Jul 25, 2022
@msftbot msftbot bot removed the Review - Needed The PR is being reviewed label Aug 5, 2022
@TravisEz13 TravisEz13 removed their assignment Aug 5, 2022
@msftbot msftbot bot added the Review - Needed The PR is being reviewed label Aug 13, 2022
@msftbot
Copy link

msftbot bot commented Aug 13, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@iSazonov
Copy link
Collaborator

Since C# got this I believe we need follow C#.

@msftbot msftbot bot removed the Review - Needed The PR is being reviewed label Dec 20, 2022
@MartinGC94
Copy link
Contributor Author

@iSazonov PowerShell is not C#. We can take all the good parts from C# but there's no need to take the bad parts as well. The C# docs for raw strings mention this:

If you need to start or end a raw string literal with quote characters, use the multi-line format

why would we want to add the same limitation here if we can avoid it?

@iSazonov
Copy link
Collaborator

Since this was not in C# but is now, it will raise questions for users. That is why it should be discussed.

@msftbot msftbot bot added the Review - Needed The PR is being reviewed label Dec 27, 2022
@msftbot
Copy link

msftbot bot commented Dec 27, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Medium Review - Needed The PR is being reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce a new, single-line raw string literal (single-line here-string alternative) here string syntax
4 participants
X Tutup