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

Issues/97 append non destructive #101

Merged

Conversation

Deleplace
Copy link
Contributor

@Deleplace Deleplace commented May 5, 2019

See #97


This change is Reviewable

@Deleplace
Copy link
Contributor Author

Oops, I must have a discrepancy somewhere, sorry about that. I'll make the necessary changes.

@Deleplace
Copy link
Contributor Author

The failing tests say that empty slice and nil are "not equal". This is a great philosophical debate, I'll check if the distinction is meaningful here.

@codecov-io
Copy link

codecov-io commented May 5, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@aa52e36). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##             master   #101   +/-   ##
=======================================
  Coverage          ?   100%           
=======================================
  Files             ?      7           
  Lines             ?   1019           
  Branches          ?      0           
=======================================
  Hits              ?   1019           
  Misses            ?      0           
  Partials          ?      0
Impacted Files Coverage Δ
pie/float64s_pie.go 100% <100%> (ø)
pie/carpointers_pie.go 100% <100%> (ø)
pie/cars_pie.go 100% <100%> (ø)
pie/ints_pie.go 100% <100%> (ø)
pie/strings_pie.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa52e36...cfce981. Read the comment docs.

Copy link
Owner

@elliotchance elliotchance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8 of 8 files at r1, 5 of 5 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Deleplace)


functions/append.go, line 7 at r2 (raw file):

// It is acceptable to provide zero arguments.
func (ss SliceType) Append(elements ...ElementType) (result SliceType) {
	return append(append(result, ss...), elements...)

Someone looking at the this for the first time may not know why it was done this way (and be tempted to undo it). Please put a comment that links the issue.


pie/append_test.go, line 9 at r2 (raw file):

// Make sure that Append never alters the receiver, or other
// slices sharing the same memory, unlike the built-in append.
func TestAppendNonDestructive(t *testing.T) {

I don't want to put tests in this package. Also, I would rather test the functions generated from the templates and not the templates themselves​. You can move this to strings_test.go.


pie/carpointers_test.go, line 340 at r2 (raw file):

	assert.Equal(t,
		len((carPointers)(nil).Append()),
		0,

Is this trying to get around the result now being non-nil? It's better to put a check in Append() and avoid the allocation if it's​ not needed.

Same thing for the other cases of this.

@Deleplace
Copy link
Contributor Author

Is this trying to get around the result now being non-nil? It's better to put a check in Append() and avoid the allocation if it's​ not needed.

No, this is intentional. In go there is no meaningful difference between nil slice and empty slice, so it would be a mistake to have rigid tests on a too strict equality check. This is part of why slices are not comparable in the language, even if we desire to compare for testing purpose.

Allocating a slice of size zero doesn't take any memory and afaik is free (no allocation).

@Deleplace
Copy link
Contributor Author

You can move this to strings_test.go.

Yes

@Deleplace
Copy link
Contributor Author

Please put a comment that links the issue.

Yes

Copy link
Owner

@elliotchance elliotchance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 9 files at r3, 11 of 11 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Deleplace)

Copy link
Contributor Author

@Deleplace Deleplace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 12 files reviewed, 1 unresolved discussion (waiting on @elliotchance)


pie/carpointers_test.go, line 340 at r2 (raw file):

Previously, elliotchance (Elliot Chance) wrote…

Is this trying to get around the result now being non-nil? It's better to put a check in Append() and avoid the allocation if it's​ not needed.

Same thing for the other cases of this.

No, this is intentional. In go there is no meaningful difference between nil slice and empty slice, so it would be a mistake to have rigid tests on a too strict equality check. This is part of why slices are not comparable in the language, even if we desire to compare for testing purpose.

Allocating a slice of size zero doesn't take any memory and afaik is free (no allocation).

Copy link
Owner

@elliotchance elliotchance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 11 of 11 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@elliotchance elliotchance merged commit 532d43b into elliotchance:master May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants