Title: Rule request: Avoid using the Assignment by Addition Operator (`+=`) to build a collection · Issue #1934 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: Rule request: Avoid using the Assignment by Addition Operator (`+=`) to build a collection · Issue #1934 · PowerShell/PSScriptAnalyzer
X Title: Rule request: Avoid using the Assignment by Addition Operator (`+=`) to build a collection · Issue #1934 · PowerShell/PSScriptAnalyzer
Description: (I thought there was already a request for this or at least discussion that the implementation is difficult as it is hard to define the type of the concerned variable. I think it is possible to come pretty far with just AST) Summary of t...
Open Graph Description: (I thought there was already a request for this or at least discussion that the implementation is difficult as it is hard to define the type of the concerned variable. I think it is possible to com...
X Description: (I thought there was already a request for this or at least discussion that the implementation is difficult as it is hard to define the type of the concerned variable. I think it is possible to com...
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/1934
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Rule request: Avoid using the Assignment by Addition Operator (`+=`) to build a collection","articleBody":"(I thought there was already a request for this or at least discussion that the implementation is difficult as it is hard to define the type of the concerned variable. I think it is possible to come pretty far with just `AST`)\r\n\r\n**Summary of the new feature**\r\n\r\nArray addition is inefficient because arrays have a fixed size. Each addition to the array creates a new array big enough to hold all elements of both the left and right operands. The elements of both operands are copied into the new array. For small collections, this overhead may not matter. Performance can suffer for large collections.\r\nThis will create more awareness of the possible performance impact for scripts as e.g. in #1933\r\nSee also:\r\n* [Why should I avoid using the increase assignment operator (`+=`) to create a collection](https://stackoverflow.com/questions/60708578/why-should-i-avoid-using-the-increase-assignment-operator-to-create-a-colle)\r\n* [PowerShell scripting performance considerations / Array addition](https://learn.microsoft.com/powershell/scripting/dev-cross-plat/performance/script-authoring-considerations#array-addition)\r\n* [PowerShell should support creating an List similar to how it supports arrays #5643](https://github.com/PowerShell/PowerShell/issues/5643)\r\n\r\n**Proposed technical implementation details (optional)**\r\n\r\nSee (PowerShell based) prototype `AvoidPlusEqualsToBuildCollections` at: https://github.com/iRon7/PSRules\r\n\r\n**What is the latest version of PSScriptAnalyzer at the point of writing**\r\n\r\n`1.21.0`\r\n","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2023-08-24T10:26:07Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/1934"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:579e312e-00ea-8a6e-cd73-a3cbe7c62079 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF90:6BC56:1C5EE:270D9:6AFDA83F |
| html-safe-nonce | 910f338fb173eb2b6dc9b1a7c305930c4b246fd79b17464d1a82c92c49b9a06d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjkwOjZCQzU2OjFDNUVFOjI3MEQ5OjZBRkRBODNGIiwidmlzaXRvcl9pZCI6IjY0MjM0NTc4MTQ0MzMwODE0MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 27140b90a0d137e2c9bb609c3460b8e2368968dd56f2cf6d29218cd367c71007 |
| hovercard-subject-tag | issue:1864859272 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PSScriptAnalyzer/1934/issue_layout |
| twitter:image | https://opengraph.githubassets.com/33751a087afd3fe3f3b469536d7157c8cd4938d5c37037dfcec7bab0c1f6f738/PowerShell/PSScriptAnalyzer/issues/1934 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/33751a087afd3fe3f3b469536d7157c8cd4938d5c37037dfcec7bab0c1f6f738/PowerShell/PSScriptAnalyzer/issues/1934 |
| og:image:alt | (I thought there was already a request for this or at least discussion that the implementation is difficult as it is hard to define the type of the concerned variable. I think it is possible to com... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iRon7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PSScriptAnalyzer git https://github.com/PowerShell/PSScriptAnalyzer.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 33149177 |
| octolytics-dimension-repository_nwo | PowerShell/PSScriptAnalyzer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33149177 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PSScriptAnalyzer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width