PowerShellPracticeAndStyle icon indicating copy to clipboard operation
PowerShellPracticeAndStyle copied to clipboard

Avoid Using Semicolons (`;`).

Open iRon7 opened this issue 2 years ago • 3 comments
trafficstars

The PowerShell practice and style guide has a rule for: Avoid Using Semicolons (;) as Line Terminators. I wonder whether there is a general readability recommendation for avoid Using Semicolons (;), period (at all), meaning: Don't put multiple statements in a single line but instead spreading them over multiple lines, thus: Rather than:

if ($Condition) {
    Write-Host 'Exiting...'; return
}

do:

if ($Condition) {
    Write-Host 'Exiting...'
    return
}

iRon7 avatar Dec 22 '22 09:12 iRon7

I would have said we had something like that, but I can't find it. I agree we should add something.

What if we add "avoid using ; to put multiple lines on one line" in the readability section where we "avoid using backticks for line continuation"

Jaykul avatar Dec 24 '22 16:12 Jaykul

@Jaykul,

avoid using ; to put multiple lines on one line

I generally agree with that statement except that it contains twice the definition lines (and line) where they should slightly differ as one (lines, maybe use "statement" or "command lines") is a subset from the other line. (I am not sure of the correct wording either, but somehow I think they should differ.)

iRon7 avatar Dec 26 '22 10:12 iRon7

Yeah, "multiple statements on one line" is probably best.

Jaykul avatar Dec 28 '22 05:12 Jaykul