Basic function question

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 3 months, 2 weeks ago.

  • Author
    Posts
  • #63325
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Hello,

    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,

    Tony

  • #63327
    Profile photo of Ron
    Ron
    Participant

    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
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Thank you

  • #63391
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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.