Thanks to visit codestin.com
Credit goes to github.com

Skip to content

C++ authoring tutorial #311

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

Merged
merged 36 commits into from
May 3, 2021
Merged

C++ authoring tutorial #311

merged 36 commits into from
May 3, 2021

Conversation

hobovsky
Copy link
Contributor

@hobovsky hobovsky commented Apr 27, 2021

Discussion: #208
Deployment preview: here

Copy link
Contributor

@awesomeAD1 awesomeAD1 left a comment

Choose a reason for hiding this comment

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

I made some suggestions in the example code sections as well: use a space after the double-backslashes in comments:

\\ good comment.
\\bad comment

This is preference, I'm sure, thus safely ignored.

@hobovsky hobovsky requested a review from error256 April 29, 2021 23:54
@hobovsky hobovsky requested a review from DonaldKellett April 30, 2021 22:53

## Kata snippets and template

Due to the complicated compilation model of C++ code, paired with the fact that Codewars strictly enforces the names, amount, and meaning of source files, the code runner uses a [template](/languages/cpp/solution_template) to concatenate all kata snippets into a single translation unit. This fact has various consequences on the code, some positive, and some negative: namespace pollution, symbols introduced by one snippet being visible in other snippets, etc. However, in the majority of cases, it does not affect kata in any way, and whenever possible, this behavior should be treated as an implementation detail of the C++ code runner. Kata snippets should be treated as separate source files, if possible.
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why it was decided to concatenate at first, but I don't think there's any reason to do this (other than we have 1K+ kata that relies on the setup). Maybe I'm missing something.

Copy link
Contributor Author

@hobovsky hobovsky Apr 30, 2021

Choose a reason for hiding this comment

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

I can see a few reasons for this, but I believe the most probable one is handling of templates in C++. Templates have to be defined in every translation unit, and that's why they're always located in header files. If a solution would need to define a template, it would be not enough for a solution to be a cpp file (i.e. a separate translation unit), because tests would not be able to use it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. If it was possible to have solution.h and solution.cpp, the test can include solution.h to be compiled separately and linked. Since we can't do that, we don't have a choice.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need a separate page for the template snippet. There's nothing much to explain further, and the new reusable one is self-explanatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solution snippet is not the only one affected by this issue. It applies also to, for example, preloaded, which might want to define global/static data in a cpp part, and declare it in a header file.

Ah, I see. If it was possible to have solution.h and solution.cpp, the test can include solution.h to be compiled separately and linked. Since we can't do that, we don't have a choice.

It could be done, but in kinda awkward way: snippets could contain some kind of markers which would separate "header" part and ".cpp part", and runner would split them into files appropriately. It's clunky, awkward, but in 99% not necessary, and some default behavior would suffice (no markers and store everything as a cpp file, compile, and link). Only those who need it, could use something like:

/*============ solution.h ============*/
// ... declarations, template definitions

/*===========solution.cpp============*/
// ... implementation part

Not that I like this solution, but it is one of solutions.

I don't think we need a separate page for the template snippet. There's nothing much to explain further, and the new reusable one is self-explanatory.

Ok so I will remove the link to the "solution template" page for now, and later I will turn the "solution template" page into "how to train on cpp kata locally" and add the link back.


C++ programmers have many sets of naming conventions or code style guides. Some of them can be found for example [here](https://isocpp.org/wiki/faq/coding-standards), or [here](https://google.github.io/styleguide/cppguide.html). Codewars does not strictly enforce any of them, just use whatever set of guidelines you like, but when you do, use it consistently.

There are a few C++ coding guidelines which are violated by kata authors and translators particularly often:
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this contradict with the above?

Codewars does not strictly enforce any of them, just use whatever set of guidelines you like, but when you do, use it consistently.

Maybe we should have a small set of rules that content creators are expected to follow based on this list.

Copy link
Contributor Author

@hobovsky hobovsky Apr 30, 2021

Choose a reason for hiding this comment

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

I meant the first paragraph to be related to things like naming conventions, placement of braces, and other minuscule things people like to fight about over the Internet.
The latter paragraph i meant to relate to more serious / not just aestethic language best practices.
Maybe my wording is off, and just do not know how to express myself clearly. One is code style, and the other is language practices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to reword both points, I am not sure if it's better though.

@hobovsky hobovsky requested a review from kazk May 1, 2021 00:57
@hobovsky hobovsky requested a review from error256 May 1, 2021 10:10
@hobovsky hobovsky requested a review from kazk May 2, 2021 15:28
@hobovsky hobovsky merged commit c2479de into master May 3, 2021
@hobovsky hobovsky deleted the cpp-authoring branch May 3, 2021 08:22
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.

Create a guide for authoring in C++
4 participants