Skip to content

update gen.Gen function#447

Merged
robphoenix merged 2 commits intoexercism:masterfrom
robphoenix:update/gen.go
Jan 16, 2017
Merged

update gen.Gen function#447
robphoenix merged 2 commits intoexercism:masterfrom
robphoenix:update/gen.go

Conversation

@robphoenix
Copy link
Copy Markdown
Contributor

No description provided.

Rob Phoenix added 2 commits January 16, 2017 11:40
fixes exercism#357

Since the re-organised exercises directory (exercism#224) the test generator
filepaths have been broken. This commit changes `gen.Gen` to take care
of locating the `canonical-data.json` file, allowing each exercises
`example_gen.go` file to just pass in the exercise name. This should
also help with any future changes that affect the filepaths.
this change ensures the commit mentioned in the generated cases_test.go
files is relevant to the exercise. closes exercism#445
Comment thread gen/gen.go
if dirMetadata == "" {
return errors.New("unable to determine current path")
}
jFile := filepath.Join("exercises", exercise, "canonical-data.json")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how idiomatic this is. Is it worth moving the "exercises" and "canonical-data.json" strings into variables within the function or even package level so they're further up the file, making them more obvious and potentially easier to change in the future?? or not??

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.

For me personally, I would 100% do it if either of the following were true:

  1. they were magic numbers; numbers without explanations/names seem much harder to understand
  2. A line containing "exercises" and "canonical-data.json" appeared more than once, since I don't like repetition.

I feel less stringent about these... I guess you call these magic strings? I would definitely not oppose creating a jsonPath(exercise string) string function (you can name that whatever you want, I'm not insistent on that name), but I also don't mind having it inlined.

Also part of my decision is that it doesn't seem very likely to change, and it is also not very hard to understand what it is doing by reading it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, super, I'll leave it as is, as you say it's not hard to understand nor is it repeated. I do like the idea of a jsonPath function but it also feels like maybe one layer of abstraction too many.

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.

All seems reasonable. I definitely feel like #357 and #445 should get mentioned. Haven't run it myself to test, but I feel like this should just work.

The change to make all generators pass in just the exercuse slug rather than the filename would want to either reference this PR... or just be added as another commit in this PR.

Comment thread gen/gen.go
if dirMetadata == "" {
return errors.New("unable to determine current path")
}
jFile := filepath.Join("exercises", exercise, "canonical-data.json")
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.

For me personally, I would 100% do it if either of the following were true:

  1. they were magic numbers; numbers without explanations/names seem much harder to understand
  2. A line containing "exercises" and "canonical-data.json" appeared more than once, since I don't like repetition.

I feel less stringent about these... I guess you call these magic strings? I would definitely not oppose creating a jsonPath(exercise string) string function (you can name that whatever you want, I'm not insistent on that name), but I also don't mind having it inlined.

Also part of my decision is that it doesn't seem very likely to change, and it is also not very hard to understand what it is doing by reading it.

@robphoenix
Copy link
Copy Markdown
Contributor Author

#357 & #445 do both get mentioned in the commits. I've tested this and it works as before. If you're happy with this I'll merge and update my other open PR's.

@petertseng
Copy link
Copy Markdown
Member

#357 & #445 do both get mentioned in the commits. I've tested this and it works as before. If you're happy with this I'll merge and update my other open PR's.

Oops, that's what I get for not expanding the commit messages. I'm usually better about this, I have no excuse (I'm in a bit of a hurry, but no excuse).

OK, given that you've tested it go ahead and merge. I may not get to review your other PRs for a few hours, depending. We'll see.

@petertseng
Copy link
Copy Markdown
Member

Oh yeah, those commit messages do a good job of explaining why the change is made. I definitely shouldn't have missed them!

@robphoenix
Copy link
Copy Markdown
Contributor Author

hey, no worries, don't feel obliged at all, I'm going to just update them and then work on other things, so whenever you get a chance, and no excuse needed, c'est la vie y'know. 😄

@robphoenix robphoenix merged commit f0c6dbe into exercism:master Jan 16, 2017
@robphoenix robphoenix deleted the update/gen.go branch January 16, 2017 12:03
robphoenix pushed a commit to robphoenix/exercism-go that referenced this pull request Jan 16, 2017
reference: exercism#447

README details on generating tests updated to reflect moving
exercises into exercises subdirectory
robphoenix pushed a commit to robphoenix/exercism-go that referenced this pull request Jan 17, 2017
reference: exercism#447

README details on generating tests updated to reflect moving
exercises into exercises subdirectory
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