Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not a Go expert, but I think it has to do with global variables/constants in modules. In C, what can run before main() is extremely limited. In C++, much more can happen before main(), i.e. running constructors for static objects, and the initialization order is undefined (this is a pretty well known problem).

I guess in Go you can also have relatively elaborate static initialization, so it has a similar problem as C++? Interested if any Go users can elaborate on this.



Like in the Object Pascal/Modula-2 language family, you can define a package initialization sections.

There are executed before control reaches main, and you need to have import relationships into consideration.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: