Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(133)

Issue 7304056: code review 7304056: go-tour: Adding new slices to the tour. (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 8 months ago by francesc
Modified:
11 years, 2 months ago
Reviewers:
adg, kisielk
CC:
golang-dev
Visibility:
Public.

Description

go-tour: Adding new slices to the tour.

Patch Set 1 #

Patch Set 2 : diff -r 15a487571fd0 https://code.google.com/p/go-tour/ #

Patch Set 3 : diff -r 15a487571fd0 https://code.google.com/p/go-tour/ #

Patch Set 4 : diff -r 15a487571fd0 https://code.google.com/p/go-tour/ #

Patch Set 5 : diff -r 15a487571fd0 https://code.google.com/p/go-tour/ #

Total comments: 14

Patch Set 6 : diff -r 15a487571fd0 https://code.google.com/p/go-tour/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+211 lines, -9 lines) Patch
prog/append.go View 1 2 3 4 1 chunk +30 lines, -0 lines 0 comments Download
prog/appendcopy.go View 1 2 3 4 1 chunk +19 lines, -0 lines 0 comments Download
prog/arrays.go View 1 2 3 4 1 chunk +21 lines, -0 lines 0 comments Download
prog/maprange.go View 1 2 3 4 1 chunk +17 lines, -0 lines 0 comments Download
prog/maprange-continued.go View 1 2 3 4 1 chunk +23 lines, -0 lines 0 comments Download
tour.article View 1 2 3 4 5 5 chunks +101 lines, -9 lines 0 comments Download

Messages

Total messages: 4
francesc
Hello adg@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go-tour/
12 years, 8 months ago (2013-02-06 19:40:31 UTC) #1
kisielk
https://codereview.appspot.com/7304056/diff/3002/tour.article File tour.article (right): https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode405 tour.article:405: copy := orig Maybe give this a different name ...
12 years, 8 months ago (2013-02-06 21:21:14 UTC) #2
adg
On 7 February 2013 06:40, <campoy@golang.org> wrote: > go-tour: Adding new slices to the tour. ...
12 years, 8 months ago (2013-02-06 22:53:34 UTC) #3
adg
12 years, 8 months ago (2013-02-06 23:37:54 UTC) #4
https://codereview.appspot.com/7304056/diff/3002/tour.article
File tour.article (right):

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode298
tour.article:298: * Arrays
I don't think this slide belongs in the tour at all. They are rarely used by
most Go programmers. I could see an argument for discussing them as a preamble
to help the programmer understand slices, but that's not how they're presented
here.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode304
tour.article:304: a := make([4]int)
Make doesn't work for arrays.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode310
tour.article:310: Both lines of code above create a new
create a new what?

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode339
tour.article:339: Arrays can be sliced, and slices can be re-sliced, creating a
new slice value that points to the same array.
This is way too pithy a connection between arrays and slices.

We link to the slices article on this slide; I think that's enough discussion of
arrays and slices. The tour doesn't need to be a comprehensive tutorial of all
aspects of the language. It should just get programmers started writing code.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode384
tour.article:384: The variadic function `append` appends a list of elements of
type `T` to a slice of type `[]T`.
you don't mention allocation at all. append is more subtle than this. it returns
a potentially new slice.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode386
tour.article:386: For a given type T, append would look like this:
Delete this line entirely.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode390
tour.article:390: Appending elements to a nil slice works normally.
normally? I think this will be easier to express when you have explained append
more thoroughly up front.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode398
tour.article:398: * Copying slices
This should be about copy(), not append(). You can mention that append may be
used for copying.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode412
tour.article:412: orig := []int{1, 2, 3, 4}
On 2013/02/06 21:21:14, kisielk wrote:
> Wouldn't 
> 
> dupe := make([]int, len(orig))
> copy(dupe, orig)
> 
> be the more typical way to do this?

Indeed.

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode502
tour.article:502: When iterating over a map, `range` provides two values
:

https://codereview.appspot.com/7304056/diff/3002/tour.article#newcode505
tour.article:505: - and a copy of the value for that key.
"a copy" is misleading. It's just the value. The pass-by-value semantics of the
language are a given.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b