What is the class of function that when called repeatedly, has the same effect as calling once?












1















A function that fulfills this criteria is



int var = 0;

void func1()
{
var = 10;
}


As you can see, calling fun1 10 times has the same effect as calling it once (assigns 10 to var)



A function that does not fulfill this criteria is



int var = 0;

void func2()
{
var++;
}


Calling func2 10 times results in var being assigned a different value as compared to calling func2 once










share|improve this question



























    1















    A function that fulfills this criteria is



    int var = 0;

    void func1()
    {
    var = 10;
    }


    As you can see, calling fun1 10 times has the same effect as calling it once (assigns 10 to var)



    A function that does not fulfill this criteria is



    int var = 0;

    void func2()
    {
    var++;
    }


    Calling func2 10 times results in var being assigned a different value as compared to calling func2 once










    share|improve this question

























      1












      1








      1








      A function that fulfills this criteria is



      int var = 0;

      void func1()
      {
      var = 10;
      }


      As you can see, calling fun1 10 times has the same effect as calling it once (assigns 10 to var)



      A function that does not fulfill this criteria is



      int var = 0;

      void func2()
      {
      var++;
      }


      Calling func2 10 times results in var being assigned a different value as compared to calling func2 once










      share|improve this question














      A function that fulfills this criteria is



      int var = 0;

      void func1()
      {
      var = 10;
      }


      As you can see, calling fun1 10 times has the same effect as calling it once (assigns 10 to var)



      A function that does not fulfill this criteria is



      int var = 0;

      void func2()
      {
      var++;
      }


      Calling func2 10 times results in var being assigned a different value as compared to calling func2 once







      naming functions






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      WoofasWoofas

      27713




      27713






















          2 Answers
          2






          active

          oldest

          votes


















          7














          This type of function / operation is called Idempotent




          Idempotence (UK: /ˌɪdɛmˈpoʊtəns/,[1] US: /ˌaɪdəm-/)[2] is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.







          share|improve this answer































            1














            The precise term for this is as @Woofas mentions, is idempotence. I wanted to add that while you could call your func1 method idempotent, you could not call it a pure function. The properties of a pure function are two: it must be idempotent and it must not have side effects, which is to say, no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams.



            The reason I mention this is that a idempotent function with side effects is not good either, since technically idempotent refers to the return ouptut of the function, and not to the side effects. So technically your func2 method is idempotent, as the output doesn't change according to the input.



            You most likely want to specify that you want a pure function. An example of a pure function might be as follows:



            int func1(int var)
            {
            return var + 1;
            }


            More reading can be found here.





            share























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "131"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f387990%2fwhat-is-the-class-of-function-that-when-called-repeatedly-has-the-same-effect-a%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              7














              This type of function / operation is called Idempotent




              Idempotence (UK: /ˌɪdɛmˈpoʊtəns/,[1] US: /ˌaɪdəm-/)[2] is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.







              share|improve this answer




























                7














                This type of function / operation is called Idempotent




                Idempotence (UK: /ˌɪdɛmˈpoʊtəns/,[1] US: /ˌaɪdəm-/)[2] is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.







                share|improve this answer


























                  7












                  7








                  7







                  This type of function / operation is called Idempotent




                  Idempotence (UK: /ˌɪdɛmˈpoʊtəns/,[1] US: /ˌaɪdəm-/)[2] is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.







                  share|improve this answer













                  This type of function / operation is called Idempotent




                  Idempotence (UK: /ˌɪdɛmˈpoʊtəns/,[1] US: /ˌaɪdəm-/)[2] is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 4 hours ago









                  WoofasWoofas

                  27713




                  27713

























                      1














                      The precise term for this is as @Woofas mentions, is idempotence. I wanted to add that while you could call your func1 method idempotent, you could not call it a pure function. The properties of a pure function are two: it must be idempotent and it must not have side effects, which is to say, no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams.



                      The reason I mention this is that a idempotent function with side effects is not good either, since technically idempotent refers to the return ouptut of the function, and not to the side effects. So technically your func2 method is idempotent, as the output doesn't change according to the input.



                      You most likely want to specify that you want a pure function. An example of a pure function might be as follows:



                      int func1(int var)
                      {
                      return var + 1;
                      }


                      More reading can be found here.





                      share




























                        1














                        The precise term for this is as @Woofas mentions, is idempotence. I wanted to add that while you could call your func1 method idempotent, you could not call it a pure function. The properties of a pure function are two: it must be idempotent and it must not have side effects, which is to say, no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams.



                        The reason I mention this is that a idempotent function with side effects is not good either, since technically idempotent refers to the return ouptut of the function, and not to the side effects. So technically your func2 method is idempotent, as the output doesn't change according to the input.



                        You most likely want to specify that you want a pure function. An example of a pure function might be as follows:



                        int func1(int var)
                        {
                        return var + 1;
                        }


                        More reading can be found here.





                        share


























                          1












                          1








                          1







                          The precise term for this is as @Woofas mentions, is idempotence. I wanted to add that while you could call your func1 method idempotent, you could not call it a pure function. The properties of a pure function are two: it must be idempotent and it must not have side effects, which is to say, no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams.



                          The reason I mention this is that a idempotent function with side effects is not good either, since technically idempotent refers to the return ouptut of the function, and not to the side effects. So technically your func2 method is idempotent, as the output doesn't change according to the input.



                          You most likely want to specify that you want a pure function. An example of a pure function might be as follows:



                          int func1(int var)
                          {
                          return var + 1;
                          }


                          More reading can be found here.





                          share













                          The precise term for this is as @Woofas mentions, is idempotence. I wanted to add that while you could call your func1 method idempotent, you could not call it a pure function. The properties of a pure function are two: it must be idempotent and it must not have side effects, which is to say, no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams.



                          The reason I mention this is that a idempotent function with side effects is not good either, since technically idempotent refers to the return ouptut of the function, and not to the side effects. So technically your func2 method is idempotent, as the output doesn't change according to the input.



                          You most likely want to specify that you want a pure function. An example of a pure function might be as follows:



                          int func1(int var)
                          {
                          return var + 1;
                          }


                          More reading can be found here.






                          share











                          share


                          share










                          answered 6 mins ago









                          NeilNeil

                          19.7k3566




                          19.7k3566






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Software Engineering Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f387990%2fwhat-is-the-class-of-function-that-when-called-repeatedly-has-the-same-effect-a%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Liste der Baudenkmale in Friedland (Mecklenburg)

                              Single-Malt-Whisky

                              Czorneboh