Priority of different Init functions

Hello Everyone

I am working on a basic project,
In my project inside the package, I have two more sub-packages.
And each sub-packages has it’s own init() function.
Here is my folder structure
Screenshot from 2020-07-05 13-20-59

the 2nd file is the main package.
Here is the full detail of both files

I searched but didn’t find a proper answer explaining which INIT() fn will run first and why?
Thanks in Advance.

  1. init should be written in a way that it doesn’t matter.
  2. It is a known implementation detail of the official compiler, that imports will be loaded in lexical order per Package. Within each package each file is loaded in lexical order as well, so you can infer the order of init execution by manually resolving those import steps.
  3. Any alternative implementation of the compiler could behave differently than what I’ve said in 2, therefore its better to adhere to 1.

What you can rely on though is, that potential inits of packages you import have been run, before you get into the init of the current file. Due to this, it is kind of guaranteed that init of the main package will always be the last init to be run.

2 Likes

Thank you.!!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.