PS: Coding Style

less than 1 minute read

Description:

When it comes to Powershell, there are two main styles that people will follow (actually three, but the third is just like one of them):

To Resolve:

  1. Styles:

    • OTBS

       function Get-Noun {
          end {
             if($Wide) {
                   Get-Command | Sort-Object Noun -Unique | Format-Wide Noun
             } else {
                   Get-Command | Sort-Object Noun -Unique | Select-Object -Expand Noun
             }
          }
       }
      
    • Stroustup: Same as OTBS but will place “else” in a new line.

    • Allman

       function Get-Noun
       {
          end
          {
             if($Wide)
             {
                   Get-Command | Sort-Object Noun -Unique | Format-Wide Noun
             }
             else
             {
                   Get-Command | Sort-Object Noun -Unique | Select-Object -Expand Noun
             }
          }
       }
      

References

https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/24
https://github.com/PoshCode/PowerShellPracticeAndStyle/blob/master/Style-Guide/Code-Layout-and-Formatting.md