# Tag Info

### If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?

The function you reference is idempotent. The relevant definition of idempotent is (per Wikipedia): a subroutine with side effects is idempotent if multiple calls to the subroutine have the same ...
• 27.7k

### If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?

Timing and system clock state are important in context of this question. I therefore reject hypotheticals about mathematical purity. If our only concern is inexact system clock which can't measure 1ms ...
• 2,263

### If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?

In short Depending on your definition, either your function is idempotent or no function at all is idempotent. Some more arguments Idempotence is about producing the same result even when applied ...
• 78.7k

### If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?

This is really a matter of definition, but to me if the execution time matters at all for idempotence then to be most strictly idempotent the second call to the function should take zero or negligible ...
• 3,726

### If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?

Clearly this is depends on magnitude. For some tasks, a speed difference of one second might be a difference like night and day (or even between life and death). For others it could be totally ...
• 110k
1 vote

### If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?

Yes, the function itself is idempotent because there are seemingly no additional unintended side-effects when the function is called repeatedly - i.e. final state of the program is the same after ...
• 12k
1 vote

### When should a function be given an argument vs getting the data itself?

It is a good practice to separate your core/business logic from IO, parsing, serializing, deserializing and other technical staffs. Then you can write unit tests against the core logic only and verify ...
• 9,462

### Is a callback function with `this` as an argument a bad practice?

It isn't that passing this is problematic. Variation number 1 is making some assumptions that are not immediately apparent — assumptions that variation number 2 does not make. Variation 1: Publisher ...
• 39.1k

### Is a callback function with `this` as an argument a bad practice?

You do what you need to do, and preferably you use a pattern that others use successfully. The pattern depends on your environment. An example: On macOS and iOS you have fields in the UI that allow ...
• 46k

### Is a callback function with `this` as an argument a bad practice?

The key difference between the two can be summarized as the "this" being injected versus captured. Typically, there are two points to be considered: The first point is the benefit of ...
• 16.9k

### Is a callback function with `this` as an argument a bad practice?

Passing an object as an callback argument is a common practice in languages without closures/lambdas/context capture. For example, in C there is no way to make a callback enhanced with any kind of ...
• 2,263

### Is a callback function with `this` as an argument a bad practice?

The example is artificial enough to make the answer clearly "it depends". Ask yourself: will code like this.foo2 = new Foo(); this.callback(foo2, this.n); result in correctly working ...
• 210k

### When should a function be given an argument vs getting the data itself?

From "The Clean Code": Statements in a function should be the same level of abstraction If you follow this rules, your functions will either be functions that do one low-level thing or ...
• 1,301
Accepted

### Is a callback function with `this` as an argument a bad practice?

No I think it's fairly common for events to pass the object raising the event and the event arguments to a handler. I've seen it said that this is so events can be bubbled up through several handlers ...
• 77.4k

### When should a function be given an argument vs getting the data itself?

If performance is not a concern, which sure is not in 99 percent of cases, then you should just strive for writing maintainable code. There is, I dare to say, only one rule to follow when writing ...
• 163

### When should a function be given an argument vs getting the data itself?

The problem with simplified examples is that, being simple and straightforward, they don't press against the relevant sensory and cognitive limitations that we're trying to deal with by folding things ...
• 9,232

### When should a function be given an argument vs getting the data itself?

There are plenty of situations where the called function cannot know certain data. Let’s say I have a function returning my income tax. The tax depends on my circumstances and my income. So you think ...
• 46k

### When should a function be given an argument vs getting the data itself?

There can be a lot of reasons to chose the one or the other. The main drivers are: Separation of concerns: When the function gets the data itself, it constraints itself to one single way of getting ...
• 78.7k
Accepted

### When should a function be given an argument vs getting the data itself?

When should a function be given an argument vs getting the data itself? When it has a job besides getting the data. I can see why you'd be confused about this. None of your functions are named after ...
• 111k

### When should a function be given an argument vs getting the data itself?

As usual, there are various influences on whether to do one or the other. Is it likely that you will at some point have to do the same processing on different data (or some other processing on the ...
• 110k

### In C++, why shouldn't all function parameters be references?

Pass by value gives you a copy of the value, pass by reference gives you a reference to the value. If you have a value on the register, you can use that directly, if it is a reference to a value, you ...
• 723

### Is there a reason to not modify values of parameters passed by value?

Because of pointers. A pointer maybe passed by value but the object can be mutable. To stay in the contrived example: public double GetArea(Circle C) { C.radius = C.radius * C.radius; C.radius ...
• 13.2k
1 vote

### Is there a reason to not modify values of parameters passed by value?

I very rarely find myself re-assigning parameters in the method body. That's not because I have an objection to that per-se, but because of naming considerations. In a well-designed method, parameter ...
• 159
1 vote

### Is there a reason to not modify values of parameters passed by value?

In C++, a parameter can have type (for example) int i, const int i, int& i, and const int& i. References obviously work different, but if you want to prevent assignment to i, you just make it ...
• 46k

### Why do you need to use pass by reference in C++ to change the value of the arguments inside the function?

Going back to the good old analogy of notes written on bits of paper and put in pockets. Call by value int i = 42; This means "find a new bit of paper, write "42" on it, and put it in ...
• 24.4k