OK i'm impressed: Scripting Games Week 1
Well guys, and gals another year has passed, and the annual scripting games are upon us again. After a week of reviewing submissions for their technique and style I must say that I am truly impressed! As a community the average ability seems to be growing by leaps and bounds. That"™s not to say we"™re all Samurai just yet, but we"™re getting there!
Before I go off and nit-pick I want to congratulate you all on a small mountain of really well written scripts. Some of the things that the community was preaching 5 years ago are now just standard. Stuff like comment your code, format for readability, and Parameters. At this point I"™m convinced those who still aren’t conforming are simply non-conformist and well that"™s a lost cause. For the rest of us great work and keep it up!
**Where is the Help!
**
What IÂ
didn’t
 see enough of in the advanced category is help. Honestly if you"™re going to write a 200 line script fill out the help! It"™s not that hard and it is THE difference between a good script and a great solution! It"™s also one of the fundamental differences between hacking and tool building, both are focused around automating a given problem set. The hacker just gets it to work, the tool builder makes it usable by the masses. If you haven"™t figured it out yet the real money is in tool building, I"™m just sayin!
**Trust but Validate.
**
I was pleasantly surprised by the amount of error handling in this first round of submissions, however I was disappointed by the lack of parameter validation.  When done correctly parameter validation can remove most of the potential errors a script can run into, and the best part is you find out that it"™s not going to work before the script does anything! For example in this week"™s scenario every single script was asked to supply a source and destination path. The following would have removed all but an access denied error.
Param ( [Parameter(Mandatory=$true, ValuefrompipelineByPropertyName=$true)] [ValidateScript({Test-Path $_ -PathType Container})] [Alias("FullName")] [string]$Source , [Parameter(Mandatory=$true, ValuefrompipelineByPropertyName=$true)] [ValidateScript({Test-Path $_ -PathType Container})] [Alias("FullName")] [string]$Destination ) This is the equivalent of filter to the left, andÂ
I’ve
 talked to endless developers who are a little jealous of our ability to use an arbitrary scriptblock for parameter validation. For more static values the ValidateSet attribute will perform the same function, but with the added benefit of Intelli-sense and tab completion.* Guys use this* I"™m telling you it"™s one of the most powerful features in PowerShell and I just don"™t see it use often enough, but then again I"™ve been tilting at this windmill for years now.
**Parameter names
**
This one is a little more nitpicky than the average, but honestly there simply isn"™t an excuse for a script with three parameters to all start with the same letter. Meaning the following is just disrespectful to yourself and your users.
Param( [String]$ArchiveSource, [String]$ArchiveDestination, [String]$ArchiveAge ) I mean that"™s a no-brainer right? I don"™t assume malice here just a lack of focus. Anyone who stops and thinks about it immediately sees the problem, and solution. So I guess what I"™m asking is that we collectively take a second to think about usability. For those of you that haven"™t had your coffee yet. The solution is that since three parameters all contain Archive we need to move that bit from the beginning of each parameter name.  In this case since there is no real need to differentiate I would suggest removing it all together.
Param( [String]$Source, [String]$Destination, [String]$Age ) Here we"™re focusing on what"™s really important which makes the parameters easier to comprehend, but also lets us get to TAB faster which is a huge part of usability!
**Bring it in
**
In summary all in all I would say we had a fantastic showing for our industry this initial week. I really like the new site and voting has been very productive which is nice. As we head into week two I look forward to what"™s to come as we collectively build upon what we"™ve learned this week.
~Glenn
Related Articles
Iron Scripter prequels: Puzzle 10 – A commentary
This is the commentary on the last Iron Scripter prequel puzzle: Iron Scripter Prequel Puzzle 10 - A commentary Next weekend will mark the start of summit and you can work on the Iron Scripter preludes - 4 daily puzzles as a lead in to the main event on Thursday 12 April 2018. If you haven’t chosen your faction yet you need to hurry
Iron Scripter Prequels: Puzzle 9 – A commentary
Here’s my commentary for puzzle 9: Iron Scripter Prequel Puzzle 9 - A commentary In this puzzle you were cleaning up the TEMP folder and the recycle bin plus working with scheduled tasks and/or scheduled jobs. One more commentary to come - probably early next week rather than Sunday and then we’re into the Summit and the main event.
Iron Scripter Preludes and Main Event: Rules and Info
Information is now available at IronScripter.us for the at-Summit events, and participants are advised to refresh themselves on the Rules. Participants attending Summit should begin choosing their faction and getting to know their teammates in the faction-specific channels of the DevOps-Summit Slack team (open only to attendees and alumni). Participants hoping to participate remotely may wish to start choosing a faction and finding a way to get in touch with them.