Why is there a "new" keyword in Go?
Posted
by
dystroy
on Programmers
See other posts from Programmers
or by dystroy
Published on 2013-09-04T07:31:19Z
Indexed on
2013/11/03
16:10 UTC
Read the original article
Hit count: 423
go
|instantiation
I'm still puzzled as why we have new
in Go.
&Thing{}
is as clear and concise as new(Thing)
to Go coders and it uses only constructs you often use elsewhere. It's also more extensible as you might change it to &Thing{3}
or &Thing{Feets:7}
.
In my opinion, having a supplementary keyword is costly, it makes the language more complex and adds to what you must know. And it might mask to newcomers what's behind instantiating a struct. It also makes one more reserved word.
So what's the reasoning behind new
? Is it something useful ? Should we use it ?
© Programmers or respective owner