-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go language
Description
by JQBalter:
The language specification doesn't say what happens if new() fails to allocate memory. Here are three ways to fix this: 1) Make new() return nil upon failure. This will introduce a bug into every current call of new() (except those that checked new() for nil for no documented reason). It also requires a coding style that is verbose and known to be error-prone. And it wouldn't work well if nonnullable pointer types were ever added to the language. 2) Make new() return res, ok. Calls that don't check the second return value could result in a fatal error if new() fails. This avoids introducing a bug into every current call, but turns local failures into global ones -- not a good design for systems programming or servers. This approach also requires a verbose coding style in code that checks for allocation failure (which rarely happens, discouraging programmers from checking). 3) Introduce exceptions into the language and issue an exception if new() fails.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go language