-
Notifications
You must be signed in to change notification settings - Fork 18.1k
proposal: Go 2: delete init functions #25885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If I remember correctly, the init function is also used for initialising globals, such as:
How would these be handled without an init function? Unless this suggestion is only about the init function that the user can write, not the init function that the compiler can generate. |
@mvdan
var _ = someFunc() |
I don't find your disadvantages to be so bad that it is worth giving up initialization. Yes, one can write bad initialization functions. One can a
8000
lways write bad code. It's not possible for the language to prevent that. If we removed init functions the bad package would switch to using |
@ianlancetaylor I have found that not easy read code lead to a lots of bugs. |
This would be a huge change with far reaching ramifications. IMO it needs a much stronger argument for why we should remove it. If a package has an Your argument would be stronger if you showed a case where there was a library that you could not remove or downgrade and it caused a real world problem that affected users. |
Thanks, @mbyio After all those arguments. So I think I should close this issue. |
Uh oh!
There was an error while loading. Please reload this page.
After meeting the same bug google/gopacket#101 3 years later.
The rule that
the special init function in a package will be run before main function
should be deleted.example
Following code should be invalid if this proposal is accept:
Following code should be valid if this proposal is accept:
disadvantage of init functions
It make the code more difficult to read, review and debug:
sync
have a init function run before your main package. I need to use go tool objdump the binary file to collect all the init functions.It make the compiler harder:
It encourage programer to write slow code:
init
function in layers.init cost too much time google/gopacket#101 when 99% of processes of my binary do not use touch any gopacket function.advantage of init functions
The problem after init function is removed:
sync.runtime_registerPoolCleanup
in sync package,crypto.RegisterHash
in md5 package. This problem can be solved partly by delete those register stuff, and ask caller to use the md5 package.cpuid
general solution to init problem without init functions:
The text was updated successfully, but these errors were encountered: