powershell-intune-samples icon indicating copy to clipboard operation
powershell-intune-samples copied to clipboard

Ugly Code

Open Kor1134 opened this issue 6 months ago • 0 comments

  1. Code block indentation
If(test-expression){        # 1st/top tier code block; no indentation
    If(test-expression){    # 2nd tier code block is indented correctly
    $var = "val"            # 3rd tier code block is NOT indented correctly
    }
    $header = @{
        'Content-Type'='application/json'
        }        # why is this closing brace indented twice? It should
                 # match the margin of the line where the brace started
}
  1. $null in a test expression.
If ($test1 -eq $null) {
    # this is a bad test expression
    # it may work but it is considered bad PowerShell syntax
}
ElseIf ($null -eq $test2) {
    # this is a good test expression
    # if an expression is comparing against a $null value, $null should always be
    # on the left side of the comparison
}
  1. Whitespace
# 'If' statements have no spacing in the syntax...
If($authResult.AccessToken){
}
# ...but 'else' statements do
else {
}
# Some variable/parameter assignments are spaced and others are not
$var = @{                               # spaced variable assignment
    'Content-Type'='application/json'   # unspaced variable assignment
}

The lack of consistency and code etiquette from a Microsoft professional is appalling.

Kor1134 avatar Jun 18 '25 15:06 Kor1134