What is a term for a function that when called repeatedly, has the same effect as calling once?2019 Community...
Why zero tolerance on nudity in space?
g++ and clang++ different behaviour with recursive initialization of a static member
Is there a low-level alternative to Animate Objects?
You'll find me clean when something is full
Book where the good guy lives backwards through time and the bad guy lives forward
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
Should I choose Itemized or Standard deduction?
The change directory (cd) command is not working with a USB drive
How can atoms be electrically neutral when there is a difference in the positions of the charges?
Creature spells vs. ability to convert a permanent into a creature
What type of postprocessing gives the effect of people standing out
Replacement ford fiesta radiator has extra hose
Where is this triangular-shaped space station from?
How can I be pwned if I'm not registered on that site?
How to count occurrences of Friday 13th
CBP Reminds Travelers to Allow 72 Hours for ESTA. Why?
Reason Why Dimensional Travelling Would be Restricted
What is the difference between throw e and throw new Exception(e)?
Did 5.25" floppies undergo a change in magnetic coating?
How do I implement simple JS code to deploy a compiled smart contract to ganache-cli?
Why proton concentration is divided by 10⁻⁷?
Whom do I have to contact for a ticket refund in case of denied boarding (in the EU)?
What is this waxed root vegetable?
It took me a lot of time to make this, pls like. (YouTube Comments #1)
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 criterion 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 criterion 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 11 more comments
A function that fulfills this criterion 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 criterion 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
37
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
14 hours ago
21
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
13 hours ago
4
Why was this question asked, if the OP knew the answer at the time of asking? Is there any reason other than rep/points/karma building?
– dotancohen
6 hours ago
8
@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
6 hours ago
4
@dotancohen: To be honest, the top-voted answer doesn't have much merit. It would be better if the answer included examples illustrating why idempotence is important. This isn't Jeopardy.
– Robert Harvey
5 hours ago
|
show 11 more comments
A function that fulfills this criterion 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 criterion 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 criterion 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 criterion 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 3 hours ago
psmears
1834
1834
asked 19 hours ago
WoofasWoofas
399147
399147
37
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
14 hours ago
21
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
13 hours ago
4
Why was this question asked, if the OP knew the answer at the time of asking? Is there any reason other than rep/points/karma building?
– dotancohen
6 hours ago
8
@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
6 hours ago
4
@dotancohen: To be honest, the top-voted answer doesn't have much merit. It would be better if the answer included examples illustrating why idempotence is important. This isn't Jeopardy.
– Robert Harvey
5 hours ago
|
show 11 more comments
37
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
14 hours ago
21
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
13 hours ago
4
Why was this question asked, if the OP knew the answer at the time of asking? Is there any reason other than rep/points/karma building?
– dotancohen
6 hours ago
8
@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
6 hours ago
4
@dotancohen: To be honest, the top-voted answer doesn't have much merit. It would be better if the answer included examples illustrating why idempotence is important. This isn't Jeopardy.
– Robert Harvey
5 hours ago
37
37
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
14 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
14 hours ago
21
21
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
13 hours ago
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
13 hours ago
4
4
Why was this question asked, if the OP knew the answer at the time of asking? Is there any reason other than rep/points/karma building?
– dotancohen
6 hours ago
Why was this question asked, if the OP knew the answer at the time of asking? Is there any reason other than rep/points/karma building?
– dotancohen
6 hours ago
8
8
@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
6 hours 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
6 hours ago
4
4
@dotancohen: To be honest, the top-voted answer doesn't have much merit. It would be better if the answer included examples illustrating why idempotence is important. This isn't Jeopardy.
– Robert Harvey
5 hours ago
@dotancohen: To be honest, the top-voted answer doesn't have much merit. It would be better if the answer included examples illustrating why idempotence is important. This isn't Jeopardy.
– Robert Harvey
5 hours ago
|
show 11 more comments
7 Answers
7
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.
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour 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.
23
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
14 hours ago
1
@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
14 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
14 hours ago
12
@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
8 hours ago
2
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent becausefunc1(1) != func1(func1(1))
.
– Tezra
2 hours ago
|
show 1 more 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.
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins ago
add a comment |
The Term is Idempotence. Note below that there is a distinct difference between an Idempotent function (Called recursively on itself; Second code block and the Mathematical definition), and functional idempotence (Called repeatedly with same input sequentially; First code block and often the term meant in Programming).
A function f with side effects is said to be idempotent under sequential composition f; f if, when called twice with the same list of arguments, the second call has no side effects and returns the same value as the first call[citation needed] (assuming no other procedures were called between the end of the first call and the start of the second call).
For instance, consider the following Python code:
x = 0
def setx(n):
global x
x = n
setx(5)
setx(5)
Here, setx is idempotent because the second call to setx (with the same argument) does not change the visible program state: x was already set to 5 in the first call, and is again set to 5 in the second call, thus keeping the same value. Note that this is distinct from idempotence under function composition f ∘ f. For example, the absolute value is idempotent under function composition:
def abs(n):
if n < 0:
return -n
else:
return n
abs(-5) == abs(abs(-5)) == abs(5) == 5
add a comment |
It is a Deterministic algorithm because given the same input (in this case no input), it will always produce the same output.
In computer science, a deterministic algorithm is an algorithm which, given a particular input, will always produce the same output, with the underlying machine always passing through the same sequence of states. Deterministic algorithms are by far the most studied and familiar kind of algorithm, as well as one of the most practical, since they can be run on real machines efficiently.
SQL databases are interested in Deterministic functions.
A deterministic function always gives the same answer when it has the same inputs. Most built-in SQL functions in SQLite are deterministic. For example, the abs(X) function always returns the same answer as long as its input X is the same.
A function must be deterministic if it's used in calculating an index.
For instance, in SQLite, the following non-deterministic functions cannot be used in an index: random()
, changes()
, last_insert_rowid()
and sqlite3_version()
.
1
The asker'sfunc2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.
– Draco18s
58 mins ago
add a comment |
In addition to the other answers, if there is a specific input to the functon that has this property, it is a fixed point, invariant point or fixpoint of the function. For example, 1 to any power is equal to 1, so (1ⁿ)ⁿ = 1ⁿ = 1.
The special case of a program that produces itself as output is a quine.
add a comment |
I would call it a stateless function. While the term idempotent is correct, I think stateless would be more widely understood.
10
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 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: false,
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
StackExchange.ready(function () {
$("#show-editor-button input, #show-editor-button button").click(function () {
var showEditor = function() {
$("#show-editor-button").hide();
$("#post-form").removeClass("dno");
StackExchange.editor.finallyInit();
};
var useFancy = $(this).data('confirm-use-fancy');
if(useFancy == 'True') {
var popupTitle = $(this).data('confirm-fancy-title');
var popupBody = $(this).data('confirm-fancy-body');
var popupAccept = $(this).data('confirm-fancy-accept-button');
$(this).loadPopup({
url: '/post/self-answer-popup',
loaded: function(popup) {
var pTitle = $(popup).find('h2');
var pBody = $(popup).find('.popup-body');
var pSubmit = $(popup).find('.popup-submit');
pTitle.text(popupTitle);
pBody.html(popupBody);
pSubmit.val(popupAccept).click(showEditor);
}
})
} else{
var confirmText = $(this).data('confirm-text');
if (confirmText ? confirm(confirmText) : true) {
showEditor();
}
}
});
});
7 Answers
7
active
oldest
votes
7 Answers
7
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.
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour ago
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.
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour ago
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 19 hours ago
WoofasWoofas
399147
399147
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour ago
add a comment |
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour ago
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
Right word, technically wrong/incomplete definition as it applies to programming. Please see the wiki on Side Effects for computer science => en.wikipedia.org/wiki/…
– Tezra
2 hours ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour ago
@Tezra: Both definitions are acceptable.
– Dietrich Epp
1 hour 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.
23
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
14 hours ago
1
@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
14 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
14 hours ago
12
@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
8 hours ago
2
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent becausefunc1(1) != func1(func1(1))
.
– Tezra
2 hours ago
|
show 1 more 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.
23
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
14 hours ago
1
@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
14 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
14 hours ago
12
@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
8 hours ago
2
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent becausefunc1(1) != func1(func1(1))
.
– Tezra
2 hours ago
|
show 1 more 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 9 hours ago
yoozer8
5721620
5721620
answered 15 hours ago
NeilNeil
19.9k3667
19.9k3667
23
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
14 hours ago
1
@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
14 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
14 hours ago
12
@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
8 hours ago
2
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent becausefunc1(1) != func1(func1(1))
.
– Tezra
2 hours ago
|
show 1 more comment
23
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
14 hours ago
1
@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
14 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
14 hours ago
12
@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
8 hours ago
2
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent becausefunc1(1) != func1(func1(1))
.
– Tezra
2 hours ago
23
23
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
14 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
14 hours ago
1
1
@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
14 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
14 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
14 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
14 hours ago
12
12
@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
8 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
8 hours ago
2
2
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent because
func1(1) != func1(func1(1))
.– Tezra
2 hours ago
You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent because
func1(1) != func1(func1(1))
.– Tezra
2 hours ago
|
show 1 more 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.
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins 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.
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins 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.
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 7 hours ago
user1717828user1717828
1327
1327
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins ago
add a comment |
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins ago
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins ago
This is indeed a nice concrete example of how an idempotent function can be visualized (mathematically, and especially in the vector geometry / linear algebra field). While software function's "idempotence" is a really close concept, I don't think developers / computer scientist often use the word "projection" in this context (a "projection function" in software engineering would rather refer to a function that take an object and returns a new object derived from it, or a property of that object, for instance)
– Pac0
28 mins ago
add a comment |
The Term is Idempotence. Note below that there is a distinct difference between an Idempotent function (Called recursively on itself; Second code block and the Mathematical definition), and functional idempotence (Called repeatedly with same input sequentially; First code block and often the term meant in Programming).
A function f with side effects is said to be idempotent under sequential composition f; f if, when called twice with the same list of arguments, the second call has no side effects and returns the same value as the first call[citation needed] (assuming no other procedures were called between the end of the first call and the start of the second call).
For instance, consider the following Python code:
x = 0
def setx(n):
global x
x = n
setx(5)
setx(5)
Here, setx is idempotent because the second call to setx (with the same argument) does not change the visible program state: x was already set to 5 in the first call, and is again set to 5 in the second call, thus keeping the same value. Note that this is distinct from idempotence under function composition f ∘ f. For example, the absolute value is idempotent under function composition:
def abs(n):
if n < 0:
return -n
else:
return n
abs(-5) == abs(abs(-5)) == abs(5) == 5
add a comment |
The Term is Idempotence. Note below that there is a distinct difference between an Idempotent function (Called recursively on itself; Second code block and the Mathematical definition), and functional idempotence (Called repeatedly with same input sequentially; First code block and often the term meant in Programming).
A function f with side effects is said to be idempotent under sequential composition f; f if, when called twice with the same list of arguments, the second call has no side effects and returns the same value as the first call[citation needed] (assuming no other procedures were called between the end of the first call and the start of the second call).
For instance, consider the following Python code:
x = 0
def setx(n):
global x
x = n
setx(5)
setx(5)
Here, setx is idempotent because the second call to setx (with the same argument) does not change the visible program state: x was already set to 5 in the first call, and is again set to 5 in the second call, thus keeping the same value. Note that this is distinct from idempotence under function composition f ∘ f. For example, the absolute value is idempotent under function composition:
def abs(n):
if n < 0:
return -n
else:
return n
abs(-5) == abs(abs(-5)) == abs(5) == 5
add a comment |
The Term is Idempotence. Note below that there is a distinct difference between an Idempotent function (Called recursively on itself; Second code block and the Mathematical definition), and functional idempotence (Called repeatedly with same input sequentially; First code block and often the term meant in Programming).
A function f with side effects is said to be idempotent under sequential composition f; f if, when called twice with the same list of arguments, the second call has no side effects and returns the same value as the first call[citation needed] (assuming no other procedures were called between the end of the first call and the start of the second call).
For instance, consider the following Python code:
x = 0
def setx(n):
global x
x = n
setx(5)
setx(5)
Here, setx is idempotent because the second call to setx (with the same argument) does not change the visible program state: x was already set to 5 in the first call, and is again set to 5 in the second call, thus keeping the same value. Note that this is distinct from idempotence under function composition f ∘ f. For example, the absolute value is idempotent under function composition:
def abs(n):
if n < 0:
return -n
else:
return n
abs(-5) == abs(abs(-5)) == abs(5) == 5
The Term is Idempotence. Note below that there is a distinct difference between an Idempotent function (Called recursively on itself; Second code block and the Mathematical definition), and functional idempotence (Called repeatedly with same input sequentially; First code block and often the term meant in Programming).
A function f with side effects is said to be idempotent under sequential composition f; f if, when called twice with the same list of arguments, the second call has no side effects and returns the same value as the first call[citation needed] (assuming no other procedures were called between the end of the first call and the start of the second call).
For instance, consider the following Python code:
x = 0
def setx(n):
global x
x = n
setx(5)
setx(5)
Here, setx is idempotent because the second call to setx (with the same argument) does not change the visible program state: x was already set to 5 in the first call, and is again set to 5 in the second call, thus keeping the same value. Note that this is distinct from idempotence under function composition f ∘ f. For example, the absolute value is idempotent under function composition:
def abs(n):
if n < 0:
return -n
else:
return n
abs(-5) == abs(abs(-5)) == abs(5) == 5
answered 2 hours ago
TezraTezra
1308
1308
add a comment |
add a comment |
It is a Deterministic algorithm because given the same input (in this case no input), it will always produce the same output.
In computer science, a deterministic algorithm is an algorithm which, given a particular input, will always produce the same output, with the underlying machine always passing through the same sequence of states. Deterministic algorithms are by far the most studied and familiar kind of algorithm, as well as one of the most practical, since they can be run on real machines efficiently.
SQL databases are interested in Deterministic functions.
A deterministic function always gives the same answer when it has the same inputs. Most built-in SQL functions in SQLite are deterministic. For example, the abs(X) function always returns the same answer as long as its input X is the same.
A function must be deterministic if it's used in calculating an index.
For instance, in SQLite, the following non-deterministic functions cannot be used in an index: random()
, changes()
, last_insert_rowid()
and sqlite3_version()
.
1
The asker'sfunc2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.
– Draco18s
58 mins ago
add a comment |
It is a Deterministic algorithm because given the same input (in this case no input), it will always produce the same output.
In computer science, a deterministic algorithm is an algorithm which, given a particular input, will always produce the same output, with the underlying machine always passing through the same sequence of states. Deterministic algorithms are by far the most studied and familiar kind of algorithm, as well as one of the most practical, since they can be run on real machines efficiently.
SQL databases are interested in Deterministic functions.
A deterministic function always gives the same answer when it has the same inputs. Most built-in SQL functions in SQLite are deterministic. For example, the abs(X) function always returns the same answer as long as its input X is the same.
A function must be deterministic if it's used in calculating an index.
For instance, in SQLite, the following non-deterministic functions cannot be used in an index: random()
, changes()
, last_insert_rowid()
and sqlite3_version()
.
1
The asker'sfunc2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.
– Draco18s
58 mins ago
add a comment |
It is a Deterministic algorithm because given the same input (in this case no input), it will always produce the same output.
In computer science, a deterministic algorithm is an algorithm which, given a particular input, will always produce the same output, with the underlying machine always passing through the same sequence of states. Deterministic algorithms are by far the most studied and familiar kind of algorithm, as well as one of the most practical, since they can be run on real machines efficiently.
SQL databases are interested in Deterministic functions.
A deterministic function always gives the same answer when it has the same inputs. Most built-in SQL functions in SQLite are deterministic. For example, the abs(X) function always returns the same answer as long as its input X is the same.
A function must be deterministic if it's used in calculating an index.
For instance, in SQLite, the following non-deterministic functions cannot be used in an index: random()
, changes()
, last_insert_rowid()
and sqlite3_version()
.
It is a Deterministic algorithm because given the same input (in this case no input), it will always produce the same output.
In computer science, a deterministic algorithm is an algorithm which, given a particular input, will always produce the same output, with the underlying machine always passing through the same sequence of states. Deterministic algorithms are by far the most studied and familiar kind of algorithm, as well as one of the most practical, since they can be run on real machines efficiently.
SQL databases are interested in Deterministic functions.
A deterministic function always gives the same answer when it has the same inputs. Most built-in SQL functions in SQLite are deterministic. For example, the abs(X) function always returns the same answer as long as its input X is the same.
A function must be deterministic if it's used in calculating an index.
For instance, in SQLite, the following non-deterministic functions cannot be used in an index: random()
, changes()
, last_insert_rowid()
and sqlite3_version()
.
edited 1 hour ago
answered 2 hours ago
Stephen QuanStephen Quan
1713
1713
1
The asker'sfunc2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.
– Draco18s
58 mins ago
add a comment |
1
The asker'sfunc2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.
– Draco18s
58 mins ago
1
1
The asker's
func2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.– Draco18s
58 mins ago
The asker's
func2
is deterministic (there are no random effects involved), but already declared as violating the property he is looking for.– Draco18s
58 mins ago
add a comment |
In addition to the other answers, if there is a specific input to the functon that has this property, it is a fixed point, invariant point or fixpoint of the function. For example, 1 to any power is equal to 1, so (1ⁿ)ⁿ = 1ⁿ = 1.
The special case of a program that produces itself as output is a quine.
add a comment |
In addition to the other answers, if there is a specific input to the functon that has this property, it is a fixed point, invariant point or fixpoint of the function. For example, 1 to any power is equal to 1, so (1ⁿ)ⁿ = 1ⁿ = 1.
The special case of a program that produces itself as output is a quine.
add a comment |
In addition to the other answers, if there is a specific input to the functon that has this property, it is a fixed point, invariant point or fixpoint of the function. For example, 1 to any power is equal to 1, so (1ⁿ)ⁿ = 1ⁿ = 1.
The special case of a program that produces itself as output is a quine.
In addition to the other answers, if there is a specific input to the functon that has this property, it is a fixed point, invariant point or fixpoint of the function. For example, 1 to any power is equal to 1, so (1ⁿ)ⁿ = 1ⁿ = 1.
The special case of a program that produces itself as output is a quine.
answered 55 mins ago
DavislorDavislor
1,026610
1,026610
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.
10
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 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.
10
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 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 8 hours ago
Walter MittyWalter Mitty
752413
752413
10
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 hours ago
add a comment |
10
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 hours ago
10
10
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
Since OP's function exclusively alters state calling it stateless seems wrong to me.
– Taemyr
8 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 hours ago
I missed the fact that var is external to the function. Sorry.
– Walter Mitty
7 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
37
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
14 hours ago
21
Calling it multiple times does have an effect, as there could be other code that changed 'var' in between.
– RemcoGerlich
13 hours ago
4
Why was this question asked, if the OP knew the answer at the time of asking? Is there any reason other than rep/points/karma building?
– dotancohen
6 hours ago
8
@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
6 hours ago
4
@dotancohen: To be honest, the top-voted answer doesn't have much merit. It would be better if the answer included examples illustrating why idempotence is important. This isn't Jeopardy.
– Robert Harvey
5 hours ago