I am going through some scripts and functions written be a predecessor, and quite a few functions start like this:
Function SomethingCool()
Why would you put empty parentheses in the function name like that?
It seems to be in lieu of having a parameter set, and the function just assumes that the variables it has exist in the script that calls it?
I have been unable to google my way to documentation about this, since the words “function” and “parentheses” (And various permutations) come up with unrelated results…
Using Function SomethingCool() is a shorthand approach to something like:
function Get-SomethingCool {
param ()
begin {}
process {}
end {}
}
My guess is the scripter learned in a diffent language that was more strict requiring a specific format and\or it nice to have consistency to your code. For instance, in my functions would all look like above, regardless if I have params or something in the begin block.
It’s probably a coding pattern they picked up from elsewhere. For example, in C# a method (aka function) must always have parentheses to be valid syntax.
It’s not very good PowerShell syntax, but it is technically valid.