Skip to content

Update/sum of multiples#427

Merged
petertseng merged 4 commits intoexercism:masterfrom
robphoenix:update/sum-of-multiples
Dec 22, 2016
Merged

Update/sum of multiples#427
petertseng merged 4 commits intoexercism:masterfrom
robphoenix:update/sum-of-multiples

Conversation

@robphoenix
Copy link
Copy Markdown
Contributor

No description provided.

Rob Phoenix added 3 commits December 22, 2016 12:22
default values are no longer mentioned in the README, so this note is no
longer necessary.

exercism#256
As there is no longer any consideration for default values having a
separate test for 3 and 5 as divisors is unnecessary and could
potentially confuse.
fixes exercism#340
Instead of returning a function, MultipleSummer() now returns an
integer. This change acknowledges that while higher-order functions have
a valuable place, the higher-order function here was rather shoe-horned
in and made the exercise slightly confusing.
@robphoenix
Copy link
Copy Markdown
Contributor Author

I've left the example function as variadic. I quite like it, and like the original exercise implementer in #53 think it could be a good opportunity to introduce variadic functions. Though I do also realise this goes against the recommendation from @petertseng to just take a slice instead, and could very well be considered inappropriate. I'm happy to change to a slice if preferred.

Copy link
Copy Markdown
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

These changes are all welcome, and some are way overdue! Thanks for putting in the work.

Before merging, I have one question about whether the function should be renamed to something other than MultipleSummer, take a look.

I've left the example function as variadic.
Though I do also realise this goes against the recommendation

I should really reconsider that part of the recommendation. Of the two changes:

  • Make the function takes all of its parameters at once, rather than a function that returns a function [1]
  • slice vs variadic

The former is definitely the much more important part of the recommendation. In fact, I may have made the slice suggestion without truly thinking about it. I am happy to keep it variadic, and if someone really wants to use a slice, they can make another PR arguing why that should be.

[1] Aside for those who are interested in studying languages: See languages that support partial application by making all their functions take only one argument at a time: Haskell and OCaml both do this by default, and Scala has special syntax for multiple argument lists.

Comment thread exercises/sum-of-multiples/example.go Outdated
}
// MultipleSummer returns the sum of the multiples of the given divisors
// up to, but not including, the given limit.
func MultipleSummer(limit int, divisors ...int) (sum int) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it looks like historically it made sense to call this MultipleSummer because it would be used like MultipleSummer(3, 5).sum(4) or something.

At this point, now it is being used like MultipleSummer(4, 3, 5), in which case I think it is better to give it a verb name than a noun name. I am thinking of SumMultiples. go lint may complain about summultiples.SumMultiples being redundant, but maybe someone else has a better suggestion.

What say you? I can't find justification for this in either https://github.com/golang/go/wiki/CodeReviewComments or https://golang.org/doc/effective_go.html so it may be a personal thing, but I usually see function names as verbs.

Copy link
Copy Markdown
Contributor Author

@robphoenix robphoenix Dec 22, 2016

Choose a reason for hiding this comment

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

Yeah, summultiples.SumMultiples isn't perfect but will do for now, no complaints from go lint.

}
}

func TestVar(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the removal of Test35 we could rename this, since the Var is no longer needed to distinguish it from the 35. I'm not sure that simply Test will be accepted, but maybe TestSum will suffice. Optional change.

}
}

func BenchmarkVar(b *testing.B) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same idea, maybe this can get renamed now.

Copy link
Copy Markdown
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

Fantastic. Let's take it.

In case anyone wonders about test version... remember that its purpose is to let reviewers know what version of the tests a given submission is written against. In that light, it may not be necessary to bump it here, since a reviewer might be able to tell by seeing the difference in function name.

If someone thinks it is very important to let reviewers see this at a single glance at one line (it is certainly the case that not all reviewers follow the developments in this repository, so it can aid them), we can add them in.

@petertseng petertseng merged commit bb6c2ad into exercism:master Dec 22, 2016
@robphoenix
Copy link
Copy Markdown
Contributor Author

oh gosh yeah, I totally overlooked the test version, sorry!
Thanks for merging, happy holidays @petertseng! 🎆

@robphoenix robphoenix deleted the update/sum-of-multiples branch January 10, 2017 11:52
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.

2 participants