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

Add info on Snowhouse stringizers for C++ #115

Closed
hobovsky opened this issue Aug 3, 2020 · 6 comments · Fixed by #138
Closed

Add info on Snowhouse stringizers for C++ #115

hobovsky opened this issue Aug 3, 2020 · 6 comments · Fixed by #138
Labels
documentation Improvements or additions to documentation kind/recipe New Recipe

Comments

@hobovsky
Copy link
Contributor

hobovsky commented Aug 3, 2020

C++ kata often produce unhelpful assertion messages, because authors do not know how to work with stringizers and other mechanisms of Snowhouse framework.

See Getting better output for your types for reference and provide some example how to create a stringizer for custom or library types (std::pair<int, int> being quite common), and where to put it in the kata (preloaded, tests?)

@hobovsky hobovsky added documentation Improvements or additions to documentation kind/snippet New Snippet labels Aug 3, 2020
@kazk
Copy link
Member

kazk commented Aug 4, 2020

I also want to update it to 4.0+ so we get booleans and strings correct (https://github.com/codewars/codewars-runner-cli/issues/827).
I have it working locally, but need to test more against the existing kata.

I haven't checked if any stringizer APIs have changed.

@hobovsky
Copy link
Contributor Author

Since the issue of missing stringizers popped up again a couple of days ago, and I expect it will come back again, I'd be willing to provide such snippet. Any suggestion on format and location of such doc entry? Where to put it in directory structure, how to mark it, what tags to use, etc?

@kazk if you have any suggestions, or even better if you could provide some template somewhere in repository I could fill in with actual explanation and code, it would be great.

Thanks

@kazk
Copy link
Member

kazk commented Oct 28, 2020

We should have a recipe for adding custom Stringizers. We can also add snippet (just copy and paste-able code with some explanation) for each of them and link to those from the recipe.

For location, I think under content/languages/cpp/igloo/ will be the best. I'll move the current content/languages/cpp/igloo.md stub to content/languages/cpp/igloo/index.md first.

kazk added a commit that referenced this issue Oct 28, 2020
@kazk
Copy link
Member

kazk commented Oct 28, 2020

Done. We should add a reference for Igloo too.


Igloo isn't great and it's unfortunately no longer maintained, but it will require a significant effort for Codewars to switch to something else at this point. Runner supports Criterion and Google Test as well, but Codewars doesn't have an option to choose a test framework, so I'll need to figure that out first to enable them.

@hobovsky hobovsky linked a pull request Oct 30, 2020 that will close this issue
@hobovsky
Copy link
Contributor Author

@error256 , @kazk , anyone familiar with C++:

If you could take a look at this kumite: https://www.codewars.com/kumite/5f9b749a9cd7a8002dfa2f34/ or this file: https://github.com/codewars/docs/blob/snowhouse-stringizers/content/languages/cpp/igloo/stringizers.md and explain me one thing:

Why for my custom classes (Point2d) it's enough if I define std::ostream& operator<<(std::ostream& stream, const Point2d& a) and stringification mechanism kicks in, while for std::pair<int, std::string>> it's not enough to define std::ostream& operator<<(std::ostream& stream, const std::pair<int, std::string>>& a) (it's compiles, but it's not used by the framework to stringify instances), but I need to provide full specialization of template<> struct Stringizer<std::pair<int, std::string>> ?
I think it could have something to do with the fact that Point2d class is "mine", and std::pair is not, and some aspect of this fact impacts the resolution of applicable functions and classes, but I do not know what part is that exactly. Is it anything related to overload matching? Koenigs lookup? Do you have any idea?

@error256
Copy link
Contributor

error256 commented Oct 30, 2020

I think it's Koenig lookup. ::operator<< works for ::Point2d, but std::pair<> needs std::operator<<. While implementing std::operator<< often works in practice, adding your own code to std:: is undefined behaviour, so it shouldn't be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation kind/recipe New Recipe
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants