Remove println
jcbwlkr opened this issue · comments
Let's get rid of all usages of println
and use the fmt
versions. I have students copying and pasting from the examples that use it.
Are there any reasons to keep it in any examples? Like in the escape analysis code or something?
i just started to do this work to maybe help out - and then realized you'd also have to update all the play.golang.org
links to new code. How certain are we about wanting to do this work?
and/or have we considered getting off the dependency of play.golang.org
?
Hi, Alan. Thanks for helping out!
You are right that changes to the examples need to be updated on the playground as well. There is a tool that can automate posting to the playground for you. If you run
go install github.com/ardanlabs/gotraining/tools/mpl
then you will have the mpl
tool available. You can use it like
mpl ./topics/go/language/pointers/README.md
and it will update any of the example links that are mirrored to the playground.
Now for your more important question about how certain we are about doing this: it is going to depend on if any behavior changes. I spoke with Bill about this topic and it might matter when it comes to pointers example 4: escape analysis. It needs to be tested with both println
and fmt.Println
to see if the escape analysis differs at all.
@flyinprogrammer thanks for helping as well. Please dont change any code under the pointers section. That must use the builtin function println
here's the proof for why we must use the builtin functions:
When you change println
to fmt.Println
you'll get this for example4.go:
11:40 $ go build -gcflags "-m -m"
# github.com/ardanlabs/gotraining/topics/go/language/pointers/example4
./example4.go:26:6: cannot inline createUserV1: marked go:noinline
./example4.go:40:6: cannot inline createUserV2: marked go:noinline
./example4.go:16:6: cannot inline main: non-leaf function
./example4.go:32:14: "V1" escapes to heap
./example4.go:32:14: from ... argument (arg to ...) at ./example4.go:32:13
./example4.go:32:14: from *(... argument) (indirection) at ./example4.go:32:13
./example4.go:32:14: from ... argument (passed to call[argument content escapes]) at ./example4.go:32:13
./example4.go:32:20: &u escapes to heap
./example4.go:32:20: from ... argument (arg to ...) at ./example4.go:32:13
./example4.go:32:20: from *(... argument) (indirection) at ./example4.go:32:13
./example4.go:32:20: from ... argument (passed to call[argument content escapes]) at ./example4.go:32:13
./example4.go:32:20: &u escapes to heap
./example4.go:32:20: from &u (interface-converted) at ./example4.go:32:20
./example4.go:32:20: from ... argument (arg to ...) at ./example4.go:32:13
./example4.go:32:20: from *(... argument) (indirection) at ./example4.go:32:13
./example4.go:32:20: from ... argument (passed to call[argument content escapes]) at ./example4.go:32:13
./example4.go:27:2: moved to heap: u
./example4.go:32:13: createUserV1 ... argument does not escape
./example4.go:46:14: "V2" escapes to heap
./example4.go:46:14: from ... argument (arg to ...) at ./example4.go:46:13
./example4.go:46:14: from *(... argument) (indirection) at ./example4.go:46:13
./example4.go:46:14: from ... argument (passed to call[argument content escapes]) at ./example4.go:46:13
./example4.go:46:20: &u escapes to heap
./example4.go:46:20: from ... argument (arg to ...) at ./example4.go:46:13
./example4.go:46:20: from *(... argument) (indirection) at ./example4.go:46:13
./example4.go:46:20: from ... argument (passed to call[argument content escapes]) at ./example4.go:46:13
./example4.go:46:20: &u escapes to heap
./example4.go:46:20: from &u (interface-converted) at ./example4.go:46:20
./example4.go:46:20: from ... argument (arg to ...) at ./example4.go:46:13
./example4.go:46:20: from *(... argument) (indirection) at ./example4.go:46:13
./example4.go:46:20: from ... argument (passed to call[argument content escapes]) at ./example4.go:46:13
./example4.go:41:2: moved to heap: u
./example4.go:48:9: &u escapes to heap
./example4.go:48:9: from ~r0 (return) at ./example4.go:48:2
./example4.go:46:13: createUserV2 ... argument does not escape
./example4.go:20:14: "u1" escapes to heap
./example4.go:20:14: from ... argument (arg to ...) at ./example4.go:20:13
./example4.go:20:14: from *(... argument) (indirection) at ./example4.go:20:13
./example4.go:20:14: from ... argument (passed to call[argument content escapes]) at ./example4.go:20:13
./example4.go:20:20: &u1 escapes to heap
./example4.go:20:20: from ... argument (arg to ...) at ./example4.go:20:13
./example4.go:20:20: from *(... argument) (indirection) at ./example4.go:20:13
./example4.go:20:20: from ... argument (passed to call[argument content escapes]) at ./example4.go:20:13
./example4.go:20:20: &u1 escapes to heap
./example4.go:20:20: from &u1 (interface-converted) at ./example4.go:20:20
./example4.go:20:20: from ... argument (arg to ...) at ./example4.go:20:13
./example4.go:20:20: from *(... argument) (indirection) at ./example4.go:20:13
./example4.go:20:20: from ... argument (passed to call[argument content escapes]) at ./example4.go:20:13
./example4.go:17:2: moved to heap: u1
./example4.go:20:25: "u2" escapes to heap
./example4.go:20:25: from ... argument (arg to ...) at ./example4.go:20:13
./example4.go:20:25: from *(... argument) (indirection) at ./example4.go:20:13
./example4.go:20:25: from ... argument (passed to call[argument content escapes]) at ./example4.go:20:13
./example4.go:20:31: &u2 escapes to heap
./example4.go:20:31: from ... argument (arg to ...) at ./example4.go:20:13
./example4.go:20:31: from *(... argument) (indirection) at ./example4.go:20:13
./example4.go:20:31: from ... argument (passed to call[argument content escapes]) at ./example4.go:20:13
./example4.go:20:31: &u2 escapes to heap
./example4.go:20:31: from &u2 (interface-converted) at ./example4.go:20:31
./example4.go:20:31: from ... argument (arg to ...) at ./example4.go:20:13
./example4.go:20:31: from *(... argument) (indirection) at ./example4.go:20:13
./example4.go:20:31: from ... argument (passed to call[argument content escapes]) at ./example4.go:20:13
./example4.go:18:2: moved to heap: u2
./example4.go:20:13: main ... argument does not escape
Having u
moved to the heap defeats the entire point (puns!) of the exercise.
👍