| 12-14-2009, 11:34 PM | #1 |
I have noticed a trend occuring where everyone must initialize their libraries in struct onInit methods, otherwise they face the possibility of something like this occuring: JASS:library A initializer Foo requires Table globals private Table t endglobals public function UseTable takes nothing returns nothing set t[0] = 777 endfunction private function Foo takes nothing returns nothing set t = Table.create() endfunction endlibrary library B requires A private struct DoInit private static method onInit takes nothing returns nothing call A_UseTable() //Thread crashes, Foo hasn't run yet. endmethod endstruct endlibrary Notice that if A wants to be usable by libraries that initialize stuff in a struct onInit, it must upgrade its own initializer to a struct onInit. Several libraries have fallen prey to this anti-trend: Table, AbilityPreload... I was just about to ask Dusk to change IntuitiveDamageDetection to use a struct onInit before I realized this. Eventually, every library for which it could cause issues winds up using a struct onInit, and we're back to square one, with the libraries initializing in the same order, but now with mangled code. So what I'm proposing is that struct onInits no longer take precedence over EVERY library initializer. Only the ones within its own library/scope. Example below: JASS:library A initializer Init struct AFoo private method onInit takes nothing returns nothing call BJDebugMsg("This prints 1st") endmethod endstruct private method Init takes nothing returns nothing call BJDebugMsg("This prints 2nd") endmethod endlibrary library B initializer Init requires A private method Init takes nothing returns nothing call BJDebugMsg("This prints 5th") endmethod struct BFoo private method onInit takes nothing returns nothing call BJDebugMsg("This prints 3rd") endmethod endstruct struct BFoo2 private method onInit takes nothing returns nothing call BJDebugMsg("This prints 4th") endmethod endstruct endlibrary This is a change that affects existing code, but as far as I can tell it should not cause any adverse effects. If anyone can find an example where it would cause issues, please post an example. Basically, I have realized that once you allow different priority levels for initialization, you're going to wind up with a slippery slope effect where everyone has to compensate. It would be much better if you can assume that your required libraries are done initializing by the time yours starts. |
| 12-15-2009, 12:00 AM | #2 |
Imo, A should be fully initialized, before B starts initializing, because B requires A. When requirements are the highest priority for initializing, I don't see any possible problems. |
| 12-15-2009, 09:39 AM | #3 |
vJass do not support priority settings... best way to comment init line and init your systems inside other system. |
| 12-20-2009, 09:57 AM | #4 |
grim +1 |
| 12-20-2009, 10:48 AM | #5 |
I support this. I remember when I first figured out about the priority stuff and wondered why the heck it wasn't like you suggest in the first place. |
| 01-01-2010, 05:23 PM | #6 |
Personally when i have the feeling this thing can happen, i use a dummy struct initializer instead, but i'm totally agree that it doesn't make any sense. So what's new with that, someone asked it to Vexorian ? |
