Could the go Tour be clearer on WHY recent make := zeroes

124 views
Skip to first unread message

Kevin Chadwick

unread,
Jun 20, 2019, 12:56:11 PM6/20/19
to golang-nuts
Hi

"https://tour.golang.org/moretypes/13"

"The make function allocates a zeroed array and returns a slice that refers to
that array."

Yet more detailed literature states that make does not zero whilst new does.

I gather this is because the shorthand used in the tour, instantiates new in the
background and wants to be as simple as possible for new users?

I am not sure if that is actually most helpful. To avoid confusion, should it be
something like:

The shorthand make := syntax allocates a zeroed array (akin to automatically
invoking new) and returns a slice that refers to that array?

Regards, Kc

fge...@gmail.com

unread,
Jun 20, 2019, 3:30:56 PM6/20/19
to Kevin Chadwick, golang-nuts
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e045f1c3-782f-f733-73a0-16eccf908ef4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

I'm not sure what you are asking for, but 
the spec on initialization is quite clear:

I'm curious which detailed literature are you referring to?

Kevin Chadwick

unread,
Jun 20, 2019, 3:51:01 PM6/20/19
to golang-nuts
On 6/20/19 8:30 PM, fge...@gmail.com wrote:
> I'm not sure what you are asking for, but 
> the spec on initialization is quite clear:
> https://golang.org/ref/spec#The_zero_value
>
> I'm curious which detailed literature are you referring to?

I was prompted by atleast a couple of books but also the spec.

Indeed the spec is clearer than I realised, had I clicked through on the link
you sent "initial values", here.

https://golang.org/ref/spec#Allocation

Perhaps the tour could link to that section of the spec?

https://tour.golang.org/moretypes/13

"allocates a zeroed array" -> "https://golang.org/ref/spec#The_zero_value"

fge...@gmail.com

unread,
Jun 21, 2019, 5:42:52 AM6/21/19
to Kevin Chadwick, golang-nuts
(I forgot in my previous message: the email subject seems to imply
that := or make() was changed since 1.0. No it wasn't.)

This for later reference: new and make and initialization is very easy
to parse in the faq in the spec and in the effective go document:
https://golang.org/doc/faq#new_and_make

I'm not sure about the tour recommendation change, if you are curious
I recommend you to file an issue, to see what others with commit
rights think about the change.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/982d264d-0e52-ad9e-775b-55172f06d29d%40gmail.com.

Kevin Chadwick

unread,
Jun 21, 2019, 8:14:14 AM6/21/19
to golang-nuts
On 6/21/19 10:42 AM, fge...@gmail.com wrote:
> (I forgot in my previous message: the email subject seems to imply
> that := or make() was changed since 1.0. No it wasn't.)

That was simply based on this, perhaps prior to 1.0?:

"https://groups.google.com/forum/#!searchin/golang-nuts/make$20new$20zeroed|sort:date/golang-nuts/793ZF_yeqbk/norrWEAyVTcJ"


"we have both make and new mainly for
pragmatic reasons.
new(T) returns *T.
so it can't return chan int, which doesn't have the form *T.
so another operator is needed.

for a short time, we tried getting by with just make,
and make(*T) was like new(T) is today.
people found it too surprising coming from
c, c++, and java.

russ"

On reflection, I guess the subject line is inaccurate. When I find the time I
will suggest a patch for the tour. I Just wondered if it may be a cause of list
noise, but probably not.

I just created noise instead, ;)

Regards, KC
Reply all
Reply to author
Forward
0 new messages