Answer the question
In order to leave comments, you need to log in
If the algorithm depends on the order of function calls in the block, is that not good?
If the algorithm depends on the order of function calls in the block, is that not good?
For example:
{
SendABC();
ShowWindow();
}
{
ShowWindow();
SendABC();
}
Answer the question
In order to leave comments, you need to log in
it's pretty logical actually:
Backup()
Remove()
and
Remove()
Backup()
will give a slightly different result
The order of execution of operations within one function plays a role in 90% of cases. If we first do actions, and then initialize the values, then we should not be surprised at errors and constantly the same results. But there are exceptions. 1) I recommend minimizing the dependence on the order of execution of event handlers. It is not necessary to do 2 handlers for one event, and then pray that one will be executed first, and then the other. 2) Parallel execution of several tasks. Again - data initialization in one thread, processing in another .. The fact that you launched the first thread first cannot give a 100% guarantee that by the time the second thread is launched, the data will be initialized.
It's called Side Effect .
In imperative programming, when working with mutable structures / objects, nothing guarantees against side effect, that is, the order of calls can always matter (at least you should always expect this from someone else's code).
The opposite is "pure" computing, which guarantees no side effect. This is achieved:
- in imperative programming: by switching to using only immutable structures/objects.
- in declarative programming: many languages are "clean" out of the box, this is their inherent property.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question