Skip to content

proposal: Better way of handling nil maps #68805

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

Closed
guettli opened this issue Aug 9, 2024 · 4 comments
Closed

proposal: Better way of handling nil maps #68805

guettli opened this issue Aug 9, 2024 · 4 comments
Labels
Milestone

Comments

@guettli
Copy link

guettli commented Aug 9, 2024

Proposal Details

For slices, the handling of nil is easy:

s = append(s, foo)

Above code works fine if s is nil.

But for maps, this does not work.

Checking if a map is nil, and if it is, doing make(...) is not convenient.

I propose to extend append() to maps:

m = append(m, key, value)

Above should work, even if m is nil.

I am looking to a solution to the overall goal (Better way of handling nil maps).

Maybe there is a better syntax to do that....

What alternatives to m = append(m, key, value) do you suggest?

@gopherbot gopherbot added this to the Proposal milestone Aug 9, 2024
@gabyhelp
Copy link

gabyhelp commented Aug 9, 2024

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@seankhliao
Copy link
Member

Duplicate of #17350

@seankhliao seankhliao marked this as a duplicate of #17350 Aug 9, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2024
@guettli
Copy link
Author

guettli commented Aug 9, 2024

The duplicate is eight years old. Maybe it’s time to think about this again? Why not make Go more newbie-friendly?

@seankhliao
Copy link
Member

While the previous issue is old, the points discussed there still hold. Without significant new information, a rehash of a previous discussion is just going to end up with the same decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants