Catching up on my reading I came across this post - http://blogs.msdn.com/powershell/archive/2009/09/20/what-s-up-with-command-prefixes.aspx which is a good explanation for why we should use command prefixes when creating cmdlets. There is a reference to prefixes increasing the Hamming Distance of noun names.
Not knowing what a Hamming Distance is I followed the link to http://en.wikipedia.org/wiki/Hamming_distance and found that it is a measure of the difference between two strings i.e. how many substitutions are required to turn one string into another.
We can find the Hamming Distance as follows
Input a couple of strings, check they are the same length and then compare on a character by character basis.
The script can be used like this
PS> .\Get-HammingDistance.ps1 toned roses
Hamming Distance for toned and roses is 3
PS> .\Get-HammingDistance.ps1 baston boston
Hamming Distance for baston and boston is 1
PS> .\Get-HammingDistance.ps1 2173896 2233796
Hamming Distance for 2173896 and 2233796 is 3
I recently came across a script that used date and time information in this manner
This gives a result of
I didn’t like the way get-date was used three times – its messy . In most cases it won’t make much difference but if the script runs across a day boundary you just might get some odd results.
The same results can be achieved with
which will give a result of
The time differences are related to me clicking across different tabs in ISE
In this way we only call Get-date once and use the .NET string formatting to give the results we want. Much neater and we don’t need to worry about time or date boundaries