54 minutes ago · 6 min read1173 words · Tech · hide

Damien Neil’s proposal for type-inferred composite literals was accepted back in April. He filed it in October 2015, so it took more than ten years and about 260 comments to get there. It’s now on track for Go 1.28, and it lets you drop the type of a composite literal when Go already knows what that type must be. You can already do this inside slice, array, and map literals. Go gets the type from the outer literal, so you don’t have to repeat it: // Slices and arrays points := []Point{{1, 2}, {3, 4}} corners := [2]Point{{0, 0}, {1, 1}} // Map keys and values byName := map[string]Point{"origin": {0, 0}} byPoint := map[Point]string{{0, 0}: "origin"} // Pointers: {1, 2} means &Point{1, 2} ptrs := []*Point{{1, 2}} Everywhere else, you have to write the type, and that gets noisy when the surrounding code makes it obvious. Take a function that returns a zero value with an error. The signature says the first result is a time.Time, but the return statement has to say it again: func…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town