Skip to content

Commit

Permalink
tip: Update tip grammar a bit and rename example variable for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlydog committed Sep 22, 2023
1 parent 73f0f81 commit 0460a86
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/PowerShellTips/2023-09-22-avoid-array-addition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ $tip = [tiPS.PowerShellTip]::new()
$tip.CreatedDate = [DateTime]::Parse('2023-09-22')
$tip.Title = 'Avoid Array addition'
$tip.TipText = @'
Array addition is a expensive and inefficient operation and can, most of the times, be replaced by PowerShell explicit loop assignment.
Array addition is an expensive and inefficient operation and can usually be replaced by PowerShell explicit loop assignment.
Use a `List<T>` instead in those cases when adding to a collection while looping is required.
'@
$tip.Example = @'
# Array addition:
$result = @()
$items = @()
foreach ($i in 0..10) {
$result += $i
$items += $i
}
# Can be easily replaced with explicit assignemnt:
$result = foreach ($i in 0..10) {
# Can be easily replaced with explicit assignment:
$items = foreach ($i in 0..10) {
$i
}
# And, when not possible, a List<T> is recommended:
$result = [System.Collections.Generic.List[int]]::new()
$items = [System.Collections.Generic.List[int]]::new()
foreach ($i in 0..10) {
$result.Add($i)
$items.Add($i)
}
'@
$tip.Urls = @(
'https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/performance/script-authoring-considerations?view=powershell-7.3#array-addition'
)
$tip.MinPowerShellVersion = '5.1'
$tip.Category = [tiPS.TipCategory]::Other # Community, CoreCmdlet, Editor, Module, Syntax, Terminal, or Other.
$tip.MinPowerShellVersion = '0.0'
$tip.Category = [tiPS.TipCategory]::Syntax # Community, CoreCmdlet, Editor, Module, Syntax, Terminal, or Other.

0 comments on commit 0460a86

Please sign in to comment.