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

New line after pipeline? #106

Open
brianmccarty opened this issue Apr 13, 2018 · 4 comments
Open

New line after pipeline? #106

brianmccarty opened this issue Apr 13, 2018 · 4 comments

Comments

@brianmccarty
Copy link

brianmccarty commented Apr 13, 2018

What do you think about the pipeline and newlines.

Get-PSSession |
    Where-Object { $_.computername -like "*.outlook.com" } |
    Remove-PSSession
Get-PSSession | Where-Object { $_.computername -like "*.outlook.com" } | Remove-PSSession
@dotps1
Copy link

dotps1 commented Apr 13, 2018

I personally do it like this:

Get-Process |
    Sort-Object -Property Name |
        Out-GridView

When I'm writing scripts anyway. I don't do that when I'm using the shell.

@pauby
Copy link
Contributor

pauby commented Apr 13, 2018

Reability is more important and having it all on one line makes it more difficult to understand at a quick glance. If your code is more readable over multiple lines then break it up.

@michaeltlombardi
Copy link

michaeltlombardi commented Apr 16, 2018

If we care about readability, we sure might want to chime in on a very relevant PowerShell issue:

When it comes to style, clarity, and readability, the options below are organized from best to worst:

# Doesn't work, but it _should_
Get-PSSession
| Where-Object { $_.computername -like "*.outlook.com" }
| Remove-PSSession
Get-PSSession |
  Where-Object { $_.computername -like "*.outlook.com" } |
  Remove-PSSession
Get-PSSession `
| Where-Object { $_.computername -like "*.outlook.com" } `
| Remove-PSSession
Get-PSSession |
  Where-Object { $_.computername -like "*.outlook.com" } |
    Remove-PSSession
Get-PSSession | Where-Object { $_.computername -like "*.outlook.com" } | Remove-PSSession
Get-PSSession |
Where-Object { $_.computername -like "*.outlook.com" } |
Remove-PSSession

The version with backticks is better than the pyramid indent but worse than the single indent because it is slightly harder to maintain, but it remains easier to read and understand especially with long or complex pipelines.

@vexx32
Copy link
Contributor

vexx32 commented Apr 20, 2018

That first option is very F#-like. I approve.

let f1 str server =
    str
    |> parseUserName
    |> getUserByName server
    |> validateLogin <| DateTime.Now

Getting that to work, though, would be a fairly big task, I think. It goes against a few established behaviours. Currently my go to is option 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants