Questions tagged [order-of-execution]

Questions about the order in which various events occur in a software system. For example, the order in which queued asynchronous tasks are executed in JavaScript or the order in which triggers are called and constraints are checked in SQL. Distinct from [operator-precedence], which covers the order in which operators are applied when evaluating an expression in a programming language.

Many software systems provide for the automatic and/or event driven execution of software in response to some event or in some other way in which it may not be obvious in which order the various pieces are executed, or if there even is a defined order. This tag is for questions about the rules or behavior of those kinds of systems. It is distinct from , which covers the order in which operators are applied when evaluating an expression in a programming language.

Examples of questions include:

  • In JavaScript, if there are multiple event handlers handling the same event, in which order are they called?
  • In SQL, are triggers called before or after constraints are applied?
  • In Rails ActiveRecord, if multiple callbacks are registered on the same event, e.g. before_create, in which order will they be called?
  • In JavaScript, what is the difference between a "task" and a "microtask" and when are they executed?
183 questions
189
votes
4 answers

How to define servlet filter order of execution using annotations in WAR

If we define webapp specific servlet filters in WAR's own web.xml, then the order of execution of the filters will be the same as the order in which they are defined in the web.xml. But, if we define those filters using @WebFilter annotation, what…
siva636
  • 16,109
  • 23
  • 97
  • 135
107
votes
3 answers

Why do these snippets of JavaScript behave differently even though they both encounter an error?

var a = {} var b = {} try{ a.x.y = b.e = 1 // Uncaught TypeError: Cannot set property 'y' of undefined } catch(err) { console.error(err); } console.log(b.e) // 1 var a = {} var b = {} try { a.x.y.z = b.e = 1 // Uncaught…
Kevin Askin
  • 883
  • 1
  • 6
  • 9
84
votes
17 answers

Order of execution of tests in TestNG

How to customize the order of execution of tests in TestNG? For example: public class Test1 { @Test public void test1() { System.out.println("test1"); } @Test public void test2() { System.out.println("test2"); } @Test …
Badri
  • 2,212
  • 3
  • 25
  • 26
72
votes
3 answers

Does the order of functions in a Python script matter?

Let's say I have two functions in my script: sum_numbers and print_sum. Their implementation is like this: def sum_numbers(a, b): return a + b def print_sum(a, b): print(sum_numbers(a, b)) So my question is: does the order in which the…
flpn
  • 1,868
  • 2
  • 19
  • 31
47
votes
5 answers

Order of evaluation of array indices (versus the expression) in C

Looking at this code: static int global_var = 0; int update_three(int val) { global_var = val; return 3; } int main() { int arr[5]; arr[global_var] = update_three(2); } Which array entry gets updated? 0 or 2? Is there a part in…
Jiminion
  • 5,080
  • 1
  • 31
  • 54
45
votes
6 answers

Order of calling constructors/destructors in inheritance

A little question about creating objects. Say I have these two classes: struct A{ A(){cout << "A() C-tor" << endl;} ~A(){cout << "~A() D-tor" << endl;} }; struct B : public A{ B(){cout << "B() C-tor" << endl;} ~B(){cout << "~B()…
Bug
  • 475
  • 1
  • 5
  • 4
43
votes
5 answers

Reading files in a particular order in python

Lets say I have three files in a folder: file9.txt, file10.txt and file11.txt and i want to read them in this particular order. Can anyone help me with this? Right now I am using the code import glob, os for infile in glob.glob(os.path.join(…
user1620012
  • 433
  • 1
  • 4
  • 4
33
votes
5 answers

jQuery: Enforce order of execution of document.ready() calls

I'm working on a codebase with multiple blocks of code setting some behavior on document.ready() (jQuery). Is there a way to enforce that one specific block is called before any of the others? Background: I need to detect JS errors in an automated…
ankit
  • 3,328
  • 3
  • 26
  • 39
30
votes
5 answers

Calling non-static member function outside of object's lifetime in C++17

Does the following program have undefined behavior in C++17 and later? struct A { void f(int) { /* Assume there is no access to *this here */ } }; int main() { auto a = new A; a->f((a->~A(), 0)); } C++17 guarantees that a->f is…
walnut
  • 21,629
  • 4
  • 23
  • 59
25
votes
9 answers

How do you make javascript code execute *in order*

Okay, so I appreciate that Javascript is not C# or PHP, but I keep coming back to an issue in Javascript - not with JS itself but my use of it. I have a function: function updateStatuses(){ showLoader() //show the 'loader.gif' in the…
Ed.
  • 251
  • 1
  • 3
  • 3
24
votes
1 answer

Order between destruction of global object and atexit in C++

I wonder that can sure order between destruction of global object and atexit in C++ I have a global object and register atexit function like below: static MyClass g_class; void onExit() { // do some destruction } int main() { …
zelon
  • 297
  • 2
  • 8
21
votes
3 answers

What does seq actually do in Haskell?

From Real World Haskell I read It operates as follows: when a seq expression is evaluated, it forces its first argument to be evaluated, then returns its second argument. It doesn't actually do anything with the first argument: seq exists solely as…
19
votes
5 answers

Do external stylesheets get loaded before the HTML?

If I have external stylesheets being included in the section of my HTML page, will they be loaded before the HTML and immediately applied upon rendering? Let me present my specific use case. External styles.css file: form label { …
Stephen Watkins
  • 25,047
  • 15
  • 66
  • 100
19
votes
2 answers

Does Java reordering affect System.currentTimeMillis()?

According to Java Memory Model, instructions can be reordered as long as the execution is well-formed. So I wonder, is it possible that the following codes produces the following output? [codes][in a same thread] long a =…
Kurtt.Lin
  • 289
  • 1
  • 8
18
votes
3 answers

Are multidimensional array accesses sequenced?

Take the following: int a(void) { puts("a"); return 0; } int b(void) { puts("b"); return 1; } int c(void) { puts("c"); return 2; } int d(void) { puts("d"); return 3; } Will the following have predictable…
1
2 3
12 13