I am having problem with finding any appropriate naming convention in PowerShell (verb-noun) that would reflect programming:
IsApple() {
return Fruit.Type == Fruits.Apple
}
Is there such a convention in PS?
I did not find any cmdlets having 'is' or 'has' as its verb. What I have seen people using is e.g. check-fruit
, but I am rather dissatisfied with this sort of a name for a function. It implicitly suggests that if I give it a fruit, it will tell me what type of fruit it is.
Of course, this is a simple enough case, which is perhaps not worth a separate function, but sometimes you will have significantly more complex checks to perform, including RegEx, AD queries etc., only to answer 'Yes' or 'No' question and build your further script execution on it.
It does not seem justified not to extract these checks to a separate function, but what is the naming convention that you would use, to tell the reader (preferably without going to the body of the 'Is-like' function) what I am checking against, like I instantly know, what I'm checking against when looking at IsApple()
The reason I am asking is that I have not seen any cmdlets in a form of is-apple
has-driver
etc.
In PowerShell, there're approved verbs for a function. They are different from version to version, but you can get yours using the Get-Verb
cmdlet.
As for your case, I could think of Assert-IsApple
or Test-IsApple
For reference, here is the link to the official list of verbs for PowerShell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With