What is a term for a function that when called repeatedly, has the same effect as calling once?2019 Community...
How to get the sitecore field updated date instead of item updated date?
80’s/90’s fantasy book where men travelled across the land and inhabited creatures such as deer, beavers and pixies
Wanted: 5.25 floppy to usb adapter
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
What to do when being responsible for data protection in your lab, yet advice is ignored?
Auto Insert date into Notepad
How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?
What am I? I am in theaters and computer programs
Meth dealer reference in Family Guy
Is there a better way to make addon working on both blender 2.80 and 2.79?
What can I substitute for soda pop in a sweet pork recipe?
Returning to Programming after 6 years. A little lost on how to start brushing up, what to focus on
What is the purpose of easy combat scenarios that don't need resource expenditure?
g++ and clang++ different behaviour with recursive initialization of a static member
Do my Windows system binaries contain sensitive information?
Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?
Copying files interactively: "cp: overwrite"
Making a ball pass through a ring using css
Why is commutativity optional in multiplication for rings?
What's the difference between a cart and a wagon?
What do the pedals on grand pianos do?
Do commercial flights continue with an engine out?
Why can I easily sing or whistle a tune I've just heard, but not as easily reproduce it on an instrument?
How to satisfy a player character's curiosity about another player character?
What is a term for a function that when called repeatedly, has the same effect as calling once?
2019 Community Moderator ElectionWhat is the name for a NON-self-calling function?Changing a variable through a series of statements … What is this technique called?Short function names for often used function or general conceptAre closures considered impure functional style?Is splitting up a function into several inner functions an anti-pattern?Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?Is there a commonly accepted name for functions that are only called in one other function?What is the term used to describe a function/method that modifies the object it's called on?Avoiding variables/functions only referenced onceWhat is a Function that Creates Functions Called?
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
add a comment |
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
13
To the close voter(s): while it is true that 99.999% (rough estimate) of all "name-that-thing" questions are off-topic because they don't have a single, correct, unambiguous, objective answer and the naming is purely subjective and opinion-based, this one does have a single, correct, unambiguous, objective answer, which was given by the OP himself.
– Jörg W Mittag
6 hours ago
7
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
4 hours ago
add a comment |
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
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
naming functions
edited 2 hours ago
Erel Segal-Halevi
4681612
4681612
asked 10 hours ago
WoofasWoofas
39947
39947
13
To the close voter(s): while it is true that 99.999% (rough estimate) of all "name-that-thing" questions are off-topic because they don't have a single, correct, unambiguous, objective answer and the naming is purely subjective and opinion-based, this one does have a single, correct, unambiguous, objective answer, which was given by the OP himself.
– Jörg W Mittag
6 hours ago
7
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
4 hours ago
add a comment |
13
To the close voter(s): while it is true that 99.999% (rough estimate) of all "name-that-thing" questions are off-topic because they don't have a single, correct, unambiguous, objective answer and the naming is purely subjective and opinion-based, this one does have a single, correct, unambiguous, objective answer, which was given by the OP himself.
– Jörg W Mittag
6 hours ago
7
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
4 hours ago
13
13
To the close voter(s): while it is true that 99.999% (rough estimate) of all "name-that-thing" questions are off-topic because they don't have a single, correct, unambiguous, objective answer and the naming is purely subjective and opinion-based, this one does have a single, correct, unambiguous, objective answer, which was given by the OP himself.
– Jörg W Mittag
6 hours ago
To the close voter(s): while it is true that 99.999% (rough estimate) of all "name-that-thing" questions are off-topic because they don't have a single, correct, unambiguous, objective answer and the naming is purely subjective and opinion-based, this one does have a single, correct, unambiguous, objective answer, which was given by the OP himself.
– Jörg W Mittag
6 hours ago
7
7
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
4 hours ago
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
4 hours ago
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
10
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, thePUT
andDELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency meansf∘f = f
", whereas in programming, we mean "executingf
has the same effect has executingf; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.
– Jörg W Mittag
6 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
1
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f387990%2fwhat-is-a-term-for-a-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
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.
add a comment |
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.
add a comment |
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.
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.
answered 10 hours ago
WoofasWoofas
39947
39947
add a comment |
add a comment |
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.
10
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, thePUT
andDELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency meansf∘f = f
", whereas in programming, we mean "executingf
has the same effect has executingf; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.
– Jörg W Mittag
6 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
1
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
add a comment |
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.
10
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, thePUT
andDELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency meansf∘f = f
", whereas in programming, we mean "executingf
has the same effect has executingf; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.
– Jörg W Mittag
6 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
1
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
add a comment |
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.
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.
edited 1 hour ago
yoozer8
5721520
5721520
answered 6 hours ago
NeilNeil
19.9k3567
19.9k3567
10
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, thePUT
andDELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency meansf∘f = f
", whereas in programming, we mean "executingf
has the same effect has executingf; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.
– Jörg W Mittag
6 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
1
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
add a comment |
10
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, thePUT
andDELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency meansf∘f = f
", whereas in programming, we mean "executingf
has the same effect has executingf; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.
– Jörg W Mittag
6 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
1
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
10
10
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, the
PUT
and DELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency means f∘f = f
", whereas in programming, we mean "executing f
has the same effect has executing f; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.– Jörg W Mittag
6 hours ago
I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, the
PUT
and DELETE
HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency means f∘f = f
", whereas in programming, we mean "executing f
has the same effect has executing f; f
". Note that you can easily transform the second meaning into the former by adding a "world" parameter.– Jörg W Mittag
6 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
@JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
– Neil
5 hours ago
1
1
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
@JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
– David Arno
5 hours ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f387990%2fwhat-is-a-term-for-a-function-that-when-called-repeatedly-has-the-same-effect-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
13
To the close voter(s): while it is true that 99.999% (rough estimate) of all "name-that-thing" questions are off-topic because they don't have a single, correct, unambiguous, objective answer and the naming is purely subjective and opinion-based, this one does have a single, correct, unambiguous, objective answer, which was given by the OP himself.
– Jörg W Mittag
6 hours ago
7
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
4 hours ago