Timeline for Term (or "pattern"?) for "Do something if it's not already done"
Current License: CC BY-SA 3.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 29, 2017 at 19:31 | comment | added | gnasher729 | @Kaz: I think "idempotence" is actually very similar to the mathematical meaning, if you interpret any statement as a mathematical function which takes the complete state of the program and returns a new one. | |
| Aug 29, 2017 at 13:36 | comment | added | Kaz | @PeterCordes A non-overlapping memcpy is just a form of assignment with distracting details. Assignment is generally idempotent: executing x = y twice is the same as executing it once. (Obviously not if x is some hardware register which triggers an external effect.) | |
| Aug 29, 2017 at 8:24 | history | edited | Nick Williams | CC BY-SA 3.0 | Made quote clearer |
| Aug 29, 2017 at 5:59 | comment | added | Peter Cordes | side-note: A simple example of an idempotent function is memcpy(dst, src, len) with non-overlapping memory ranges. A memcpy implementation can copy 8 (or 16 or 32) bytes at a time, and instead of copying the last up to 7 bytes one at a time, can do a possibly-overlapping copy of the last 8 bytes (if len >= 8). If re-copying overlapping bytes wasn't idempotent, you couldn't do this optimization. (Real implementations often use the same code as for memmove, so they check for overlap and copy up / down as required.) | |
| Aug 27, 2017 at 20:01 | comment | added | Voo | @Kaz I just explained the origin of the term and how you have to adapt the definition to make it work for a non-functional programming language with side effects. And no the function absolutely is idempotent. There is one relevant metastate in the environment: httpServerIsRunning. Evaluating the given function the first time will set this variable to true, evaluating it again won't change the state again. But I think we're in agreement on this, you just didn't read the question carefully enough: The whole thing is about not starting a second server if the function is called a second time. | |
| Aug 27, 2017 at 17:37 | comment | added | Kaz | In other words, mathematics functions and operators are all idempotent in the software engineering sense. Those which are computable can have counterparts in a functional programming language. Those computational counterparts will be effect free; effect free implies idempotent (in the software sense) because if something has no effect, evaluating it two or more times still has that same null effect. | |
| Aug 27, 2017 at 17:32 | comment | added | Kaz | @Voo Idempotence in this context isn't the mathematical concept; it's just the same word being used in a different context. Mathematical functions don't require this software engineering version of idempotence because they do not have side effects. Idempotence in software is a sometimes useful property of a procedure which mutates state: executing it two or more times has the same net effect on the state. Or at least the same effect as far as some particular point of view is concerned (which cares about some effects but possibly not some others). | |
| Aug 27, 2017 at 17:29 | comment | added | Kaz | @Polygnome Sorry, you are wrong. Idempotent means that the request has the same effect whether it is executed once, or more than once. Starting N http servers if N duplicates of the request are received is definitely not idempotent. | |
| Aug 27, 2017 at 12:09 | comment | added | Voo | The confusion comes from the fact that idempotence at its core is a mathematical concept applied to functions. The definition is nice and simple for those and also works well for pure functional languages. As soon as you introduce side effects it gets complicated - you have to consider the environment you execute the function in as an (implicit) argument and output of the function. If that state is not modified by further calls to the function it is idempotent, otherwise it isn't. In this case the relevant state is "is http server running" - so the function is idempotent. | |
| Aug 27, 2017 at 11:02 | comment | added | Doc Brown | @Polygnome: this answer is correct, idempotency refers to functions for which it does not matter if they are called once or more than once, the result keeps always the same. Here, the result is one running http service, independently from the number of times the function is called. | |
| Aug 27, 2017 at 11:01 | comment | added | amon | @Polygnome Wikipedia defines idempotence as f(f(x)) = f(x) which generally matches Nick's description. Here the function input and output would be the implicit server state, so the “server is running” state would be a fixed point for this function. Maybe I'm misunderstanding the Wikipedia article here, could you link to other references? | |
| Aug 27, 2017 at 10:28 | comment | added | Polygnome | The function is not idempotent if calling it once starts the http server, and calling it a second time doesn't. Thats literally the opposite of idempotence. It would be idempotent if every call started a new http server. | |
| Aug 27, 2017 at 7:12 | history | answered | Nick Williams | CC BY-SA 3.0 |