Basic function question

This topic contains 3 replies, has 3 voices, and was last updated by  Richard Siddaway 1 year, 5 months ago.

  • Author
  • #63325

    Tony Antony


    This question applies to all programming not just Power shell. Besides reducing the number of lines in a code if you're entering the same code more than once, is there any other benefits to using functions?

    For example, does it make the program any faster? Any other advantages / Disadvantages?

    Thank you,


  • #63327


    A couple that immediately come to mind.

    Re-usability. A function can be like a tool you've built and tested. You copy it out of one script and put it in another.

    Readability. Sometimes you need a large block of code to perform a seemingly simple action. By creating a function with meaningful name, you can make your code easier to follow.

  • #63330

    Tony Antony

    Thank you

  • #63391

    Richard Siddaway

    I'd also add that if your code is created as Advanced functions it can be packaged as a module

You must be logged in to reply to this topic.