-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
provide implementation file #97
Comments
+1 I think this would be helpful. |
Does this need to be done with every exercise? While I agree that providing a template would be helpful for the first exercise, providing the API's may accidentally discourage newbies from considering how to name the inputs and outputs of their functions. If an API is provided for every exercise, then there needs to be more thought about the names used, especially if the existing examples are converted. Let's take the first exercise as an example: func IsLeapYear(i int) bool ... was the API used in the example file. Should "i" be renamed "year"? Or "inputYear"? Also, some of the example implementations make use of named results: The choice of whether to use that feature should be up to the participant, and providing an API might make some reluctant to take the alternate approach of returning results. I think a compromise is to provide some tutorial comments with a first and only implementation template. Something like: // For each exercise, create an implementation file with the same package name as the provided tests.
package leap
func IsLeapYear(i int) bool {
// To run the unit tests, run "go test" in the exercise directory, without quotes.
// Many exercises come with benchmarks, which can be run with "go test -bench ."
// Use the unit test results and the tests themselves to determine which function API's to implement.
// Please run "go fmt" on your code before submitting it.
} The potential downside of such tutorial comments is that they need to be maintained, along with the existing exercism help documentation. That, and the first exercise could change with the config. |
Another quirk with providing a template and API: Continuing with the "leap" example, example.go and leap.go would collide with each other:
https://travis-ci.org/exercism/xgo/builds/31483810 This could change, but it's another thing to consider. |
I hear you, regarding naming the arguments, the following code is valid: func IsLeapYear(int) bool { I'm not sure that all exercises need that but in this specific exercise it
|
That works. Still need to consider the case where Travis tries to test out both example.go and leap.go. Is changing the Travis CI behavior worth it for one exception? Or would it be better to figure out a workaround? |
The idea of providing the API has come up before. Some exercises currently have the API documented in comments in the test code and the Go help page says to read the test code. We could add similar comments for Leap, but I'm not sure we need it in all cases. Even without looking at the test code, fetch then go test without even writing anything and the compiler tells you "undefined: IsLeapYear" for example. The read me says "Write a program that will take a year and report if it is a leap year." It doesn't seem too much guess that in Go you have to write a function that takes an Also we can't ask much more from Submitting Exercises - the presented example is for Go and Leap! |
This is an old issue and I'm not sure if it's intended to still be open, but I just wanted to add that the problem with having both a stub file and an example is easy to solve by using build tags. The ledger test has that problem on steroids since it has two full implementations (a crappy one that the user has to refactor and a less crappy example). What I did there was to add at the top of the example.go file a comment line |
Good point. I'm not actually sure if we came to any conclusion with this. I think it could be useful to do it only for the first exercise to help first-time users / first-time Go programmers, but I actually like that most of the time it's up to the user to read the error messages and look at the test code to figure out what to do. |
The first few exercises have stub files now. I think we can finally close this one. |
As a new user, I found confusing that I didn't have a blank file with the package name and the basic API to implement.
The text was updated successfully, but these errors were encountered: