Mmastodon TechnologySoftware first seen 1 d ago, last 1 d ago, peak #11
Why Go needs both make and new
Original: You want to create a slice: numbers := make([]int, 3) But for a struct, you might see: user := new(User) Both seem to "c
A programming explainer on Go's memory allocation is circulating among developers, addressing a common point of confusion for newcomers: why the language has two built-in functions that both seem to create values. The piece contrasts make([]int, 3), used to initialise slices and other composite types, with new(User), which allocates a struct and returns a pointer, arguing the two solve fundamentally different problems rather than overlapping.
Why now: Go beginners regularly trip over the make versus new distinction, so clear explainers on the topic draw attention.
Evidence
- You want to create a slice: numbers := make([]int, 3) But for a struct, you might see: user := new(User) Both seem to "create" something. So why does Go need two built-in functions? The answer is that make and new solve two very different problems. The Concept The simplest… · hackaday@www.urbanmind.net · 2
API: https://socialmediatrends-api.osmike.com/v1/trends/1065266