Description
I guess I've gotten used to C# snippets that are "functional/productive". I find snippets like this in the PowerShell extension to be an awkward hybrid:
switch ($x)
{
'value1' { }
{$_ -in 'A','B','C'} {}
'value3' {}
Default {}
}
Seriously, what are the odds that I'll have value1
as a case or a second or third case as shown above. I believe these were written to show how to use a feature i.e. they are teaching. That is admirable but as soon as the user learns the features of switch, this snippet becomes cumbersome because now it is a toss-up WRT how much code they have to "delete" to make the snippet conform to their intent versus how much they would have typed in the first place without using the snippet.
I propose that at the very least the "common" language features lean more towards being productivity snippets and not "teaching" snippets. I recommend changing the switch statement snippet to something like:
switch ($variable) {
condition { action; break }
Default {}
}
Where the cursor is put on a condtion placeholder
second after $variable
and then the action placeholder
would be third.
BTW here are a few more examples of what I'm talking about:
try
{
1/0
}
catch [DivideByZeroException]
{
Write-Host "Divide by zero exception"
}
catch [System.Net.WebException],[System.Exception]
{
Write-Host "Other exception"
}
finally
{
Write-Host "cleaning up ..."
}
for ($i = 1; $i -lt 99; $i++)
{
}
Everybody who uses the try/catch/finally snippet is going to have to remove the DivideByZeroException and likely have to change the last catch to use an exception they want to catch (or not specify one at all). I believe there should a single exception there and it should be a placeholder. Likewise everybody is going to have to replace 99
in the for snippet. Might as well make it a placeholder.