Don't do that, do this instead: PowerShell worst practices and how to solve them by Chris Gardner

preview_player
Показать описание
In past years the 3 furies have shared their insights on various things people do wrong in PowerShell. Let's take that one step further and demo all those things and what you should do instead. We'll explain why it's bad and the other way is better, because code without context doesn't help anyone.
A lot of talks about "Best Practice" are aimed at showing you what you should be doing but not many take the approach of showing what you shouldn't be doing and how to change it. This can make it more difficult to grasp as it might not easily relate to how someone is currently working or has been working, showing the wrong way to do things is more approachable as everyone was a beginner at some point and many people made the same mistakes. Taking this one step further and providing reasoning why one approach is the wrong or worse way to handle something can also allow people to make an informed decision on using that approach anyway, if their circumstances require it.

PowerShell Summit videos are recorded on a "best effort" basis. We use a room mic to capture as much room audio as possible, with an emphasis on capturing the speaker. Our recordings are made in a way that minimizes overhead for our speakers and interruptions to our live audience. These recordings are meant to preserve the presentations' information for posterity, and are not intended to be a substitute for attending the Summit in person. These recordings are not intended as professional video training products. We hope you find these videos useful - the equipment used to record these was purchased using generous donations from members of the PowerShell community.
Рекомендации по теме
Комментарии
Автор

Thank you for this video, I have been using these "proper" Powershell grammar tips to my current scripts and it is helping clean them up. Thanks again!

krwhynot
Автор

5:17 Aliases, that's what was doing my head in. Still learning, slowly and the amount of people that release their code with aliases is super annoying. I spend after the time working out what they mean. One script I wrote, as I know I'll forget, I even commented what ever single line was doing to make it even more readable. Obviously I know that's not possible for large scripts but still useful for me.

TheStevenWhiting
Автор

Got to love the question on camel case as that is the biggest discussion we have on projects with external developers. Naming conventions.

tonyme
Автор

Glad to see I follow most of these practices already, though I didn't know about the $array += optimisation, I went back to my old scripts and modified them, they run much better now.

HarmonicaMustang
Автор

For more clarification on the memory usage of the array += thing: arrays are fixed sized collections of a single type. Assume you have an array (let's call it A) with 100 integers. If you want to add another integer to it (lets call this i), then the computer needs to allocate a new chunk of memory (let's call this array B) with enough space for 101 integers, copy A over to B, and then tack on i. So, if you do something like: $array = @(); 1..100 | foreach-object { $array += $_ } then you're asking the computer to allocate new memory 100 times. It isn't bad for small chunks of data, but adding data to the ends of lists is much more performant. If you want to run a head to head comparison, here's a piece of powershell code you can run (tested on v6): $range = 1..1000; $IntArray = @(); write-output "List method(ms): $((measure-command -expression { $range | %{ write-output "Array method(ms): $((measure-command -expression {$range | % {$IntArray += $_}}).TotalMilliseconds)"

daviddow
Автор

I half agree with the hungarian notation one (around 14:20ish). Sure you can put other things in the $strName than a string. But if the programmer made it an strName then he likely intends for you to keep it a string so if you change it to an array, you'll break stuff done later on.

PhrontDoor
Автор

Anybody know what the talk/video was about his comment at the end by a guy called Mike and WFP? I'd like to watch that.

RPG_ash
Автор

All good stuff.
Any chance of getting the source code on Github ?

OurstPlanet
Автор

In vscode, there's "ms" command latency for every command he typed. How do I set that in vscode ?

fuleo
Автор

Is "Select-Object" more readable than "select"? I don't think maximizing syntax increases readability. Zero aliases or positional params improves approachability for neophytes, but it's obscuring noise to anyone with experience trying to see the big picture.

BrianLalonde
Автор

Ouch. His . . . manner-of-speaking . . . is . . . very . . . difficult-to-understand. A few words gets spit out slowly; he stops, pausing, then races through the next fifteen words. Had to bail out after two minutes.

IT TOTALLY DISTRACTS FROM CONCENTRATING ON MATERIAL.

gorge