Тёмный

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

PowerShell.org
Подписаться 24 тыс.
Просмотров 26 тыс.
50% 1

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.

Наука

Опубликовано:

 

16 май 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 25   
@krwhynot
@krwhynot 2 года назад
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!
@TheStevenWhiting
@TheStevenWhiting 2 года назад
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.
@HarmonicaMustang
@HarmonicaMustang 4 месяца назад
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.
@tonyme7426
@tonyme7426 Год назад
Got to love the question on camel case as that is the biggest discussion we have on projects with external developers. Naming conventions.
@MuhammadBerki
@MuhammadBerki Год назад
Great session thanks 🙂👍
@daviddow5591
@daviddow5591 5 лет назад
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; $IntList=[System.Collections.Generic.List[int]]::new(); $IntArray = @(); write-output "List method(ms): $((measure-command -expression { $range | %{ $IntList.Add($_)}}).TotalMilliseconds)"; write-output "Array method(ms): $((measure-command -expression {$range | % {$IntArray += $_}}).TotalMilliseconds)"
@daviddow5591
@daviddow5591 5 лет назад
Also, don't write code in scripts like the spaghetti I just wrote lol
@Chad-Skillable
@Chad-Skillable 7 месяцев назад
Chris talks about this at 22:12
@PhrontDoor
@PhrontDoor 9 месяцев назад
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.
@RPG_ash
@RPG_ash Год назад
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.
@fuleo
@fuleo 5 лет назад
In vscode, there's "ms" command latency for every command he typed. How do I set that in vscode ?
@michaelo147
@michaelo147 4 года назад
Did you ever figure this out?
@citelao
@citelao 4 года назад
@@michaelo147 It's probably a custom prompt. If you grab and save the current time (globally) in the prompt, you can check that value the next time the prompt appears. If you subtract the two values, you get time elapsed. "Elapsed time PowerShell" and "custom PowerShell prompts" are good starting searches.
@michaelo147
@michaelo147 4 года назад
@@citelao I finally had some time for this and this was absolutely it. Thank you for teaching me something new.
@rpfrompr
@rpfrompr 2 года назад
@@citelao, could you explain? Was that added to him PS prompt?
@TheStevenWhiting
@TheStevenWhiting 2 года назад
@@rpfrompr As mentioned it appears to be related to the Prompt function. Where you can set what the prompt looks like. No clue on the code to make it display the elapsed time though. Someone has probably written a script for it somewhere.
@Our1stPlanet
@Our1stPlanet 3 года назад
All good stuff. Any chance of getting the source code on Github ?
@BrianLalonde
@BrianLalonde 5 лет назад
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.
@daviddow5591
@daviddow5591 5 лет назад
Well, aliases are good for shorthand at the terminal too, but with powershell core, it looks like aliases are going to be going away to some extent
@gareginasatryan6761
@gareginasatryan6761 3 года назад
I agree. In a copy command it’s pretty obvious what the positional parameters are. copy was probably one of my first commands when I was around 13.
@-dash
@-dash Год назад
I think the idea is if you adhere to the schema, there's very little chance for ambiguity and almost certainly does anyone revisiting the code a favor. "Select", at a quick glance, could be referring to Select-String, Select-Object, Select-XML, etc.
@gorge5412
@gorge5412 4 года назад
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.
@TheStevenWhiting
@TheStevenWhiting 2 года назад
American? He has an accent here in the UK, its probably that that's bothering you.
@geroffmilan3328
@geroffmilan3328 Год назад
@@TheStevenWhiting sounded fine to me too.
@go-meditate
@go-meditate Год назад
I am a non-native english speaker and I understood everything perfectly fine.
Далее
Writing Compiled PowerShell Cmdlets by Thomas Rayner
1:28:11
ПОМОГЛА НАЗЫВАЕТСЯ😂
00:20
Просмотров 2,9 млн
PowerShell Modules
25:01
Просмотров 12 тыс.
Stop, Intel’s Already Dead!
13:47
Просмотров 561 тыс.
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
Просмотров 884 тыс.
PowerShell Remoting
37:12
Просмотров 70 тыс.
PowerShell 2018: State of the Art by Jeffrey Snover
1:23:04
I've been using Redis wrong this whole time...
20:53
Просмотров 348 тыс.
КАКОЙ SAMSUNG КУПИТЬ В 2024 ГОДУ
14:59