Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/blog: short code snippet in tutorial written pre-go1 no longer compiles #34232

Open
lazybutbusy opened this issue Sep 11, 2019 · 5 comments
Open
Labels
Documentation NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@lazybutbusy
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.13 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\DELL\AppData\Local\go-build
set GOENV=C:\Users\DELL\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\go-work
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\DELL\AppData\Local\Temp\go-build164497938=/tmp/go-build -gno-record-gcc-switches

What did you do?

I think the example on the tutorial is wrong

https://blog.golang.org/gos-declaration-syntax
At the end sector 'Pointer':
they declare a variable that i think it a integer nil pointer like this: []int("hi")
but i think the author is mistook with the : []int(nil)

What did you expect to see?

It run, cause it's a tutorial

What did you see instead?

the compiler throw back with the error:

command-line-arguments

.\test.go:10:14: cannot convert "hi" (type string) to type []int

@gopherbot gopherbot added this to the Unreleased milestone Sep 11, 2019
@ALTree
Copy link
Member

ALTree commented Sep 11, 2019

Back in 2010, when that article was written, there was no rune, and unicode strings were made of ints.

So in pre-1 Go releases, []int("hi") was perfectly valid. Then in Go1 rune was introduced as an alias for int32, so today you would write []rune("hi") (which works), and now []int("hi") is a compilation error.

@ALTree
Copy link
Member

ALTree commented Sep 11, 2019

A (very old) blog post is not really a tutorial, so I'm not sure we want to go back and retroactively change posts that were correct at the time but are not now. Labelling this as "NeedsDecision".

cc @robpike

@ALTree ALTree added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Documentation labels Sep 11, 2019
@edulopezTriv
Copy link

A (very old) blog post is not really a tutorial, so I'm not sure we want to go back and retroactively change posts that were correct at the time but are not now. Labelling this as "NeedsDecision".

cc @robpike

I think if those post are still used as "valid and formal documentation" they should be updated. When I say "Formal" I mean that is given by a reliable source as google, not just a dev that works with the language. If is that not the case, I give a +1 to close the issue.

@robpike
Copy link
Contributor

robpike commented Sep 11, 2019

I'd leave it alone for historical reasons and also because that whole section is built around int and introducing rune might be distracting. But I'm not certain about that decision, so other opinions welcome.

@go101
Copy link

go101 commented Sep 12, 2019

How about adding a note box for all old blog articles before Go 1 to address such problems?

@ALTree ALTree changed the title x/blog:Tutorial not working x/blog: short code snippet in tutorial written pre-go1 no longer compiles Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants