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 Best Practices chapter #107

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kadet1090
Copy link
Member

This is followup for the #101 (Add chapter with C++ recomended practices) PR with aim to make the proposed document more welcoming to new users and easier to enforce by providing set of quite concrete rules that should be possible to check on code review. This is joint effort of @hyarion, me and authors of the original PR: worser (forum) and @3x380V as this one is based on it. We are doing it as separate PR as this is easiest way to propose changes, but the original commits were left intact.

Instead of putting it inside code formatting, content is placed in its own chapter so it is hopefully easier to find.

By no means this is a finished piece of work - I think of it as the start point to which we all should contribute and extend it together. Python section is still missing so if we have some people that are good with this language - we would appreciate your help!

worser and others added 2 commits August 29, 2024 13:03
@kadet1090 kadet1090 changed the title Code review guidelines design Add Best Practices chapter Nov 19, 2024
Comment on lines 104 to 127
```cpp
using PrefixSpec = struct {
char prefix;
unsigned long long factor;
};

auto prefix = spec->first;
static constexpr std::array<PrefixSpec, 7> sortedPrefixes {
{{'E', 1ULL << 60}, // 1 << 60 = 2^60
{'P', 1ULL << 50},
{'T', 1ULL << 40},
{'G', 1ULL << 30},
{'M', 1ULL << 20}, // 1 << 20 = 2^20 = 1024
{'k', 1ULL << 10}, // 1 << 10 = 2^10 = 1024
{'\0', 0}}};

const auto res = std::find_if(prefixes, [&](const auto& spec) {
return spec.factor <= size;
});

// Add one digit after the decimal place for all prefixed sizes
return res->factor
? fmt::format("{:.1f} {}B", static_cast<double>(size) / res->factor, res->prefix)
: fmt::format("{} B", size);
```
Copy link
Contributor

Choose a reason for hiding this comment

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

This example should be replaced with outcome from this pr: FreeCAD/FreeCAD#17817

@3x380V
Copy link

3x380V commented Nov 19, 2024

I'm happy someone is looking int this. Just a minor note:
Diffs are very hard to read and also introduced few whitespace changes pre-commit is not happy about.
Original is a formatted text document with line breaks up to 80 characters. The changes are somewhat autoformated text flow which makes diff too noisy. Could that be changed (if you really insist on this modern way of text formatting) so that reformat without changes goes first and changes follows in separate commits?

@hyarion
Copy link
Contributor

hyarion commented Nov 19, 2024

I'm happy someone is looking int this. Just a minor note: Diffs are very hard to read and also introduced few whitespace changes pre-commit is not happy about. Original is a formatted text document with line breaks up to 80 characters. The changes are somewhat autoformated text flow which makes diff too noisy.

I'm sorry, the markdown editor I use in vscode has a preview that break lines on newlines, so I removed them to avoid some lines breaking in odd places. It didn't occur to me that it might be a bug in my tool. I thought the line endings was a mistake.

Could that be changed (if you really insist on this modern way of text formatting) so that reformat without changes goes first and changes follows in separate commits?

Github can hide some white space changes, here's a link which should do it automatically for the commit: a08f820?diff=unified&w=1

Does that work for you @3x380V or do you want me to reformat the changes to make it as close as possible?

@3x380V
Copy link

3x380V commented Nov 19, 2024

@hyarion, I can deal with that diff using various tips and tricks to make it more readable, but it is rather unexpected from editor to randomly break lines in C++ or Python code, so why is that default here? Why do we have ~500 character long lines in this document? It breaks each and every line based tool. And both patch and diff are line based tools. Could be VSCode told just not trying to be smart?

@hyarion
Copy link
Contributor

hyarion commented Nov 19, 2024

It is a third party preview extension that I use in vscode. It is probably just a slightly different dialect of markdown.

@3x380V
Copy link

3x380V commented Nov 19, 2024

Ok. Let me put it this way: this chapter had no formatting, it is just a conversion of PDF uploaded to the forum, which itself was created in wisiwig editor. So formatting is mine (and done the way I'm used to format such documents). If you are familiar with whatever extension you are using, just reformat that commit the way you like and which is for most people here easy to work with. I'll probably close original PR as it served its purpose already.

@kadet1090 kadet1090 force-pushed the code-review-guidelines-design branch 3 times, most recently from d94cf5e to 4a81308 Compare November 19, 2024 23:19
hyarion and others added 4 commits November 20, 2024 23:55
This change aims to improve language of the C++ practices so it is more
welcoming for newcomers. Wording is different, but the ideals presented were
kept as they were good.
This adds a guide aimed more at reviewers that takes the guide and tries
to extract from it steps that are easy to follow and check. This commit
also reorganizes the structure so everything lives in a new
bestpractices folder.

Co-Authored-By: Benjamin Nauck <[email protected]>
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.

4 participants