-
-
Notifications
You must be signed in to change notification settings - Fork 359
Standardize on style #18
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
Comments
Hey ubsan. This is a discussion we definitely need to have. I sent you a twitter message asking if you would join the discord channel discussion (if only for a brief bit) because we had a pretty lengthy discussion on this topic and your PR's. I guess I should have sent you an e-mail instead, sorry about that! |
But I guess it's fine to have the convo here. As far as style is concerned, I can only really speak to the languages I know (C / C++, Fortran, Julia, and Python). To me, readability is most important, but I also think the code should compile as-is (if possible). There will come a time when it is too difficult to do this, simply because the algorithms require too much code, but we can deal with that when the time comes. Here's what makes code readable (to me):
Because of the nature of the book, it's alright for people to have different styles, but the cleanest implementation will be accepted. When reading the code, I should never have to ask the following questions:
If these questions come up to the reader, there better be a comment nearby justifying why it is unclear. And if people submit versions of the code that are different, they should justify why their code is better and should be used instead of the code already present. I fully intend to have a Please let me know your thoughts. Algorithms are (mostly) language independent. The reader should be able grab an implementation in their favorite language, immediately understand it, and then play with it on their own to understand how it works. |
Alright, after a bit of internal discussion, I think the comment block is unnecessary in this case. Everyone knows the purpose of the code (because it's in the above article) and compile instructions are only really complicated if you want to avoid making makefiles. If we have a good chapter on all the different languages, then compilation should be straightforward. Also: Comments in general should probably be used mainly to answer language-specific ambiguities. The rest of the questions should be answered in the accompanying article. I think this can be summed up as: Follow the style guide for the language you are writing in, but remember that there will be newbies reading, so keep it simple. |
So, as someone who writes a lot of C++, I'd like to base the style on these two things: https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/ https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md The latter's formatting is not my favorite, but I think it's reasonable enough, and has support of the committee, and is, I think, a good base. Some highlights (with my own spin where the guidelines are inconsistent):
(I'm not happy about this one, but that's how the C++ core guidelines and the standard write their code)
|
Side note, on comments: imo, the first thing in order of importance is accessibility. this means:
this looks like:
|
Alright, we've agreed to use stroustrup style, with #include <iostream>
#include <cmath>
// Euclidean algorithm using modulus
int euclid_mod(int a, int b)
{
a = std::abs(a);
b = std::abs(b);
while (b != 0) {
auto temp = b;
b = a%b;
a = temp;
}
return a;
}
// Euclidean algorithm with subtraction
int euclid_sub(int a, int b)
{
a = std::abs(a);
b = std::abs(b);
while (a != b) {
if (a > b) {
a -= b;
}
else {
b -= a;
}
}
return a;
}
int main()
{
int check1 = euclid_mod(64*67, 64*81);
int check2 = euclid_sub(128*12, 128*77);
std::cout << check1 << '\n';
std::cout << check2 << '\n';
} |
Yeah, I think there are times when Also: Leaving this discussion open in case further discussion is needed down the line. |
I'll just take the initiative and close this one. There hasn't been any activity for quite some time now and I think everything here has been resolved. If not, then feel free to reopen the issue or create a new one. |
* Added cpp file * Added Gorzoid to CONTRIBUTORS.md * Fixed style to conform with guidelines #18 * Removed unnecessary define * Added entry to jarvis_march.md * Added check for empty array edge case. Changed Iterators to single vector reference * Changed to resolve edge case of duplicate points.
No description provided.
The text was updated successfully, but these errors were encountered: