I saw the Go 1.26 release notes about new(expr) and immediately thought: great, I can delete all those generic ptr[T] helpers scattered through my codebase. Not quite.

The syntax works, but it gets weird with untyped constants in deeply nested AWS SDK structs. The compiler usually figures it out, but I hit snags where it complained about untyped string literals until I cast them explicitly. So I still need some helpers, just fewer of them.

If you've written Go for more than a week, you've hit the wall trying to get a pointer to a string literal. The AWS SDK and every database ORM want optional primitive pointers. You can't write &"us-east-1". The workarounds were: write a local ptr generic, import aws.String(), or do the v := "us-east-1"; p := &v dance that litters your code with single-use variables.

The stubborn compromise

Here's what bugs me. Why did we wait 15 years for new(42) when &42 is what everyone tries first? They could have made the ampersand work on literals. Instead we got a function call that feels like it's catering to parser edge cases, not humans.

I'll probably phase out my pointer utilities eventually. Not rushing into it though. I want to see how gofmt handles huge nested structs full of new() calls before I run a massive search-and-replace across everything.

If your code is full of aws.String() or custom ptr helpers, this upgrade is worth it.

FAQ

Q Does new(expr) work with structs?
A Yes, but for structs you usually just use &StructName{} anyway. The real power is function call expressions like new(yearsSince(born)) where the type is inferred from the return value.
Q Will this break backwards compatibility?
A No, the old new(Type) syntax is still completely valid.
Asaduzzaman Pavel

About the Author

Asaduzzaman Pavel is a Software Engineer who actually enjoys the friction of a well-architected system. He has over 15 years of experience building high-performance backends and infrastructure that can actually handle the real-world chaos of scale.

Currently looking for new opportunities to build something amazing.