15:52 | <Jack Works> | why class field initialization order is all field initializers runs first, then the constructor? |
15:53 | <Jack Works> | i thought it is more intuitive to run in source text order? |
15:54 | <Jack Works> | like this:
|
15:55 | <Jack Works> | spec order is 1-2-4-3 |
16:06 | <bakkot> | generally it's more useful to have fields set up before the constructor runs |
16:06 | <Jack Works> | is there some design principles behind this? |
16:06 | <Jack Works> | and is it related to decorators? |
16:32 | <ljharb> | if it ran in source text order then the this it installs field2 on might not be the actual instance, since the constructor could have returned any object |
16:33 | <ljharb> | it's pretty important for private fields imo, at least, that all of them are installed on the same object, so you can never observe a partially "set up" instance |
16:33 | <Jack Works> | source text order 1-2-3-4 also installed on the correct this value IMO |
16:35 | <ljharb> | if line 6.5 did return {} which object would get field2? |
16:35 | <Jack Works> | oh... |
16:36 | <Jack Works> | ok I understand now |