There is nothing wrong. If you have a function that returns a value, but also somehow changes the state of the program (called a side effect ), calling the function, but ignoring the return value will just cause all the side effects applied. Of course, you cannot use the return value if you do not store it, but sometimes all you need is side effects of the call.
There are some people who believe in designing the API in such a way that the functions that cause their side effects (commands) and the functions that are called to monitor some state of the program (requests) are separated as much as possible. This principle is called Separation of request commands . The idea is that all functions that return something should not change the state of the program, because they observe it, and the act of observation should not affect the observed state. All functions that return nothing are then treated as commands called solely for their side effects.
Therefore, people who follow these principles might think that since your function explicitly applies a side effect (or why do you call it and don't care about the return value?), It should not observe any state (have a return value). Please note, however, that this principle should not always be respected in the letter, and there is not much agreement on it.
Why are some proponents of requesting a team request? Because it ensures that consecutive requests return the same response if no command was applied between requests. This is a kind of weaker form of immutability and bears a weakened form of advantages that immutability can have for reasoning about the logic of a program. In a sequential application, objects are immutable between commands.
In my opinion, maintaining this principle often leads to less confusing APIs and clearer programming logic, but it cannot be carried too far. There are times when you may need to apply a side effect and return a value. However, when the return value is only a success value, consider throwing an exception on error.
Gravity
source share