What is a term for a function that when called repeatedly, has the same effect as calling once?
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
|
show 10 more comments
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
23
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
9 hours ago
15
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
8 hours ago
1
How can a function with no arguments be idempotent?
– Walter Mitty
2 hours ago
2
@WalterMitty: The same way a function with arguments is idempotent; it produces the same result, given the same input (which, in this case, is no input). I do hear what you are saying, though; it's clearly less useful with parameterless functions, but the examples do clearly illustrate the concept.
– Robert Harvey
2 hours ago
2
@glglgl: I agree, for questions with merit. What merit has this question? I'm seriously concerned that we'll start getting every CS 101 question asked and immediately answered by the OP, every single CS term asked and immediately defined by the OP, and every basic algorithm's pros and cons questioned then immediately answered by the OP (not necessarily this OP). Is that the site that we want softwareengineering.SE to be?
– dotancohen
1 hour ago
|
show 10 more comments
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 6 hours ago
Erel Segal-Halevi
4681612
4681612
asked 14 hours ago
WoofasWoofas
39947
39947
23
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
9 hours ago
15
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
8 hours ago
1
How can a function with no arguments be idempotent?
– Walter Mitty
2 hours ago
2
@WalterMitty: The same way a function with arguments is idempotent; it produces the same result, given the same input (which, in this case, is no input). I do hear what you are saying, though; it's clearly less useful with parameterless functions, but the examples do clearly illustrate the concept.
– Robert Harvey
2 hours ago
2
@glglgl: I agree, for questions with merit. What merit has this question? I'm seriously concerned that we'll start getting every CS 101 question asked and immediately answered by the OP, every single CS term asked and immediately defined by the OP, and every basic algorithm's pros and cons questioned then immediately answered by the OP (not necessarily this OP). Is that the site that we want softwareengineering.SE to be?
– dotancohen
1 hour ago
|
show 10 more comments
23
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
9 hours ago
15
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
8 hours ago
1
How can a function with no arguments be idempotent?
– Walter Mitty
2 hours ago
2
@WalterMitty: The same way a function with arguments is idempotent; it produces the same result, given the same input (which, in this case, is no input). I do hear what you are saying, though; it's clearly less useful with parameterless functions, but the examples do clearly illustrate the concept.
– Robert Harvey
2 hours ago
2
@glglgl: I agree, for questions with merit. What merit has this question? I'm seriously concerned that we'll start getting every CS 101 question asked and immediately answered by the OP, every single CS term asked and immediately defined by the OP, and every basic algorithm's pros and cons questioned then immediately answered by the OP (not necessarily this OP). Is that the site that we want softwareengineering.SE to be?
– dotancohen
1 hour ago
23
23
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
9 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
9 hours ago
15
15
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
8 hours ago
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
8 hours ago
1
1
How can a function with no arguments be idempotent?
– Walter Mitty
2 hours ago
How can a function with no arguments be idempotent?
– Walter Mitty
2 hours ago
2
2
@WalterMitty: The same way a function with arguments is idempotent; it produces the same result, given the same input (which, in this case, is no input). I do hear what you are saying, though; it's clearly less useful with parameterless functions, but the examples do clearly illustrate the concept.
– Robert Harvey
2 hours ago
@WalterMitty: The same way a function with arguments is idempotent; it produces the same result, given the same input (which, in this case, is no input). I do hear what you are saying, though; it's clearly less useful with parameterless functions, but the examples do clearly illustrate the concept.
– Robert Harvey
2 hours ago
2
2
@glglgl: I agree, for questions with merit. What merit has this question? I'm seriously concerned that we'll start getting every CS 101 question asked and immediately answered by the OP, every single CS term asked and immediately defined by the OP, and every basic algorithm's pros and cons questioned then immediately answered by the OP (not necessarily this OP). Is that the site that we want softwareengineering.SE to be?
– dotancohen
1 hour ago
@glglgl: I agree, for questions with merit. What merit has this question? I'm seriously concerned that we'll start getting every CS 101 question asked and immediately answered by the OP, every single CS term asked and immediately defined by the OP, and every basic algorithm's pros and cons questioned then immediately answered by the OP (not necessarily this OP). Is that the site that we want softwareengineering.SE to be?
– dotancohen
1 hour ago
|
show 10 more comments
4 Answers
4
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.
17
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, thePUTandDELETEHTTP 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 "executingfhas 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
9 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
9 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
9 hours ago
6
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 hours ago
add a comment |
In physics I've heard this referred to as a projection:
a projection is a linear transformation P from a vector space to itself such that P2 = P. That is, whenever P is applied twice to any value, it gives the same result as if it were applied once (idempotent).
Graphically, this makes sense if you look at a cartoon of a vector projection:

In the picture, a1 is the projection of a on to b, which is like the first application of your function. Subsequent projections of a1 on to b give the same result a1. In other words, when you call a projection repeatedly, it has the same effect as calling it once.
Fair warning: I've never heard this used outside of physics, so unless you've got of those types on your team you might confuse everyone.
add a comment |
I would call it a stateless function. While the term idempotent is correct, I think stateless would be more widely understood.
7
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 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
4 Answers
4
active
oldest
votes
4 Answers
4
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 14 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.
17
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, thePUTandDELETEHTTP 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 "executingfhas 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
9 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
9 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
9 hours ago
6
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 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.
17
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, thePUTandDELETEHTTP 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 "executingfhas 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
9 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
9 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
9 hours ago
6
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 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 4 hours ago
yoozer8
5721520
5721520
answered 10 hours ago
NeilNeil
19.9k3667
19.9k3667
17
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, thePUTandDELETEHTTP 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 "executingfhas 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
9 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
9 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
9 hours ago
6
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 hours ago
add a comment |
17
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, thePUTandDELETEHTTP 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 "executingfhas 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
9 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
9 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
9 hours ago
6
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 hours ago
17
17
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
9 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
9 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
9 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
9 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
9 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
9 hours ago
6
6
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 hours ago
@Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
– opa
3 hours ago
add a comment |
In physics I've heard this referred to as a projection:
a projection is a linear transformation P from a vector space to itself such that P2 = P. That is, whenever P is applied twice to any value, it gives the same result as if it were applied once (idempotent).
Graphically, this makes sense if you look at a cartoon of a vector projection:

In the picture, a1 is the projection of a on to b, which is like the first application of your function. Subsequent projections of a1 on to b give the same result a1. In other words, when you call a projection repeatedly, it has the same effect as calling it once.
Fair warning: I've never heard this used outside of physics, so unless you've got of those types on your team you might confuse everyone.
add a comment |
In physics I've heard this referred to as a projection:
a projection is a linear transformation P from a vector space to itself such that P2 = P. That is, whenever P is applied twice to any value, it gives the same result as if it were applied once (idempotent).
Graphically, this makes sense if you look at a cartoon of a vector projection:

In the picture, a1 is the projection of a on to b, which is like the first application of your function. Subsequent projections of a1 on to b give the same result a1. In other words, when you call a projection repeatedly, it has the same effect as calling it once.
Fair warning: I've never heard this used outside of physics, so unless you've got of those types on your team you might confuse everyone.
add a comment |
In physics I've heard this referred to as a projection:
a projection is a linear transformation P from a vector space to itself such that P2 = P. That is, whenever P is applied twice to any value, it gives the same result as if it were applied once (idempotent).
Graphically, this makes sense if you look at a cartoon of a vector projection:

In the picture, a1 is the projection of a on to b, which is like the first application of your function. Subsequent projections of a1 on to b give the same result a1. In other words, when you call a projection repeatedly, it has the same effect as calling it once.
Fair warning: I've never heard this used outside of physics, so unless you've got of those types on your team you might confuse everyone.
In physics I've heard this referred to as a projection:
a projection is a linear transformation P from a vector space to itself such that P2 = P. That is, whenever P is applied twice to any value, it gives the same result as if it were applied once (idempotent).
Graphically, this makes sense if you look at a cartoon of a vector projection:

In the picture, a1 is the projection of a on to b, which is like the first application of your function. Subsequent projections of a1 on to b give the same result a1. In other words, when you call a projection repeatedly, it has the same effect as calling it once.
Fair warning: I've never heard this used outside of physics, so unless you've got of those types on your team you might confuse everyone.
answered 2 hours ago
user1717828user1717828
1347
1347
add a comment |
add a comment |
I would call it a stateless function. While the term idempotent is correct, I think stateless would be more widely understood.
7
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 hours ago
add a comment |
I would call it a stateless function. While the term idempotent is correct, I think stateless would be more widely understood.
7
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 hours ago
add a comment |
I would call it a stateless function. While the term idempotent is correct, I think stateless would be more widely understood.
I would call it a stateless function. While the term idempotent is correct, I think stateless would be more widely understood.
answered 3 hours ago
Walter MittyWalter Mitty
758413
758413
7
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 hours ago
add a comment |
7
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 hours ago
7
7
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
3 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
2 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
23
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
9 hours ago
15
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
8 hours ago
1
How can a function with no arguments be idempotent?
– Walter Mitty
2 hours ago
2
@WalterMitty: The same way a function with arguments is idempotent; it produces the same result, given the same input (which, in this case, is no input). I do hear what you are saying, though; it's clearly less useful with parameterless functions, but the examples do clearly illustrate the concept.
– Robert Harvey
2 hours ago
2
@glglgl: I agree, for questions with merit. What merit has this question? I'm seriously concerned that we'll start getting every CS 101 question asked and immediately answered by the OP, every single CS term asked and immediately defined by the OP, and every basic algorithm's pros and cons questioned then immediately answered by the OP (not necessarily this OP). Is that the site that we want softwareengineering.SE to be?
– dotancohen
1 hour ago