Skip to content

Code cleanup#26

Closed
GregEakin wants to merge 5 commits into
davidrmiller:mainfrom
GregEakin:user/eakin-6
Closed

Code cleanup#26
GregEakin wants to merge 5 commits into
davidrmiller:mainfrom
GregEakin:user/eakin-6

Conversation

@GregEakin

Copy link
Copy Markdown

These are the code changes from review #7. The remaining changes in that review are const variables, and type specifications on constantans.

@venzen venzen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 for the use of .empty() - looked into this issue today for another project and am convinced empty() is the most salient way to kick a tyre :)

Comment thread src/peeps.cpp
{
for (auto moveRecord : moveQueue) {
for (auto& moveRecord : moveQueue) {
auto & indiv = peeps[moveRecord.first];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reference instead of value copy - is the space between auto and & here intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For me, the ampersand on the right looks like the address-operator, and I avoid that.
I don't see spaces on both sides very often. So, I always put them on the left.
I'll go along with the convention.

Comment thread src/survival-criteria.cpp
const std::vector<Coord> barrierCenters = grid.getBarrierCenters();
float minDistance = 1e8;
for (Coord center : barrierCenters) {
for (auto& center : barrierCenters) {

@venzen venzen Nov 27, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so, a barrier center can have a type other than Coord?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, it's just a Coord. In this case, the auto reference type for center is a const Coord&.
I thought was saving a copy, by using an auto-reference, but I don't think it helps.
I guess the coding standards from my day job got in the way: "Always use auto& as the foreach variable."

// possibly do a move here instead of copy, although it's doubtful that
// the optimization would be noticeable.
if (passed.first && peeps[index].nnet.connections.size() > 0) {
if (passed.first && !peeps[index].nnet.connections.empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sometimes I don't notice the negation because ! is so slender and easy to overlook, In most cases (other than !=) using not is preferable IMO. Just saying. I'm happy to go along with any convention that is agreed on.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll go with the convention too.

@davidrmiller

Copy link
Copy Markdown
Owner

Some very nice improvements in this collection. I look forward to examining them in detail, but at first cursory glance, they look great.

@venzen

venzen commented Nov 28, 2021

Copy link
Copy Markdown
Contributor

General question that I think is on-topic here:

What coding standard are you guys using? I work in VS Code and most of the IntelliSense C-standards create a lot of "Problems" noise with code that is perfectly fine. The Gnu standards are more reasonable and only highlight blatant syntax errors and declaration issues. Any suggestions?

@davidrmiller

Copy link
Copy Markdown
Owner

@venzen , thanks for asking that. There are many good, common-sense guidelines in the GNU Coding Standards and GCC Coding Conventions, but the nature of this project doesn't require overscrupulousness.

When reviewing PRs, my concerns will be algorithm correctness, *nix portability, and no warnings with gcc -pedantic -Wextra -Wall -std=c++17.

As far as I'm concerned, you can be informal about syntax formatting when submitting PRs. When it's time to publicly review a feature branch, I can tweak the spaces and braces to be consistent with the predominately K&R style of the existing code.

@davidrmiller davidrmiller mentioned this pull request Dec 11, 2021
@davidrmiller

Copy link
Copy Markdown
Owner

This PR was incorporated in #37. Thanks to @GregEakin for these nice improvements to the code.

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.

3 participants