-
Notifications
You must be signed in to change notification settings - Fork 224
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
Conversation
Co-authored-by: awesome A.D. <[email protected]>
There was a problem hiding this 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.
Co-authored-by: awesome A.D. <[email protected]>
Co-authored-by: kazk <[email protected]>
|
||
## 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andsolution.cpp
, the test can includesolution.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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: error256 <[email protected]>
Co-authored-by: hobovsky <[email protected]>
Discussion: #208
Deployment preview: here