What is the recommended coding style for PowerShell?

前端 未结 3 454
萌比男神i
萌比男神i 2020-12-22 14:51

Is there any recommended coding style how to write PowerShell scripts?

It\'s not about how to structure the code (how many functions, if to use modu

3条回答
  •  醉酒成梦
    2020-12-22 15:35

    I recently came across an excellent point about indent style in PowerShell. As the linked comment states, observe the difference between these same syntaxes:

    1..10 | Sort-Object
    {
        -$_
    }
    

    and

    1..10 | Sort-Object {
        -$_
    }
    

    While my inclination is to "do as the Romans do" and use the standard C# indentation style (Allman, more or less), I take issue with this exception and others similar to it.

    This inclines me personally to use my favored 1TBS, but I could be convinced otherwise. How did you settle, out of curiosity?

提交回复
热议问题