Welcome › Forums › General PowerShell Q&A › Brackets at the end of a function
This topic contains 5 replies, has 6 voices, and was last updated by
This is a little script from the brilliant Bruce Payette,
Function tillXmas ()
$now = [datetime]::Now
[datetime] ( [string] $now.year + "-12-25") - $Now
On the function, why has Bruce add () at the end of 'tillXmas' ?
Habits of a .NET developer, I imagine. 🙂 It's just an empty parameter list, and it's optional. (If you use a param() block inside the function, such as for advanced functions, then you can't have the parentheses after the name; they're exclusive.)
Thanks Dave. ☺
It's used as an indicator for us to tell that the script was copied off the internet:-)
I am going to assume Bruce did it because it's faster. In my testing, you save an average 0.0008 milliseconds at runtime if you include the otherwise superfluous parentheses. : )
Jokes aside.. I do a lot of forms based scripts and I regularly use the parens after function names where I'm not taking params from user input.
Use param() inside the function if you need to set validation, switch, pipeline etc. settings.
The topic ‘Brackets at the end of a function’ is closed to new replies.