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 STYLEGUIDE.md and update some other md files on best practices #7347

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

Conversation

onurctirtir
Copy link
Member

@onurctirtir onurctirtir commented Nov 15, 2023

No description provided.

@onurctirtir onurctirtir marked this pull request as ready for review November 15, 2023 09:40
Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Merging #7347 (39cf4bb) into main (3ce731d) will increase coverage by 0.00%.
Report is 1 commits behind head on main.
The diff coverage is n/a.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7347   +/-   ##
=======================================
  Coverage   89.60%   89.60%           
=======================================
  Files         282      282           
  Lines       60311    60311           
  Branches     7512     7512           
=======================================
+ Hits        54042    54044    +2     
+ Misses       4114     4113    -1     
+ Partials     2155     2154    -1     

CONTRIBUTING-development.md Outdated Show resolved Hide resolved
CONTRIBUTING-development.md Outdated Show resolved Hide resolved
..
}

* We **start functions with a comment**:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add comment if there is specific functionality that needs to be expressed in comments. Good naming should not require a comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah but this is such an important development-convention change that needs to be taken in a team-wide discussion, would you like to initiate this? :)

Copy link
Contributor

@JelteF JelteF Dec 11, 2023

Choose a reason for hiding this comment

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

I agree good naming is does not really require a comment always. But based on my experience with different codebases having a bit of useless comments in a codebase is much better than having to few comments. If we allow functions without comments, then I believe people will often stop adding comments to functions, even for functions that would benefit from it. Also by forcing writing a comment, people will try their best to make it non-useless and reviewers can easier add suggestions if they think it can be improved. So I think keeping this requirement for a comment would be the best option.


* Your PR doesn't introduce a typo or something that you can easily fix yourself.

* After all CI jobs pass, code-coverage measurement job (CodeCov as of today) then kicks in. That's why it's important to make the **tests passing** first. At that point, you're expected to check **CodeCov annotations** that can be seen in the **Files Changed** tab and expected to make sure that it doesn't complain about any lines that are not covered. For example, it's ok if CodeCov complains about an `ereport()` call that you put for an "unexpected-but-better-than-crashing" case, but it's not ok if it complains about an uncovered `if` branch that you added.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that if only ereport is the case. Today, I see that EnsurePropagationToCoordinator is not tested however I think it is tested. I see that in some cases I see the output but still codecov complains

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, there are such cases where codecov unnecessarily complains, this requires spending some time to understand how code-coverage measurement is done via code-cov.


* If you're adding a new file, consider using `src/test/regress/bin/create_test.py` to create the file. Or if you want to manually create it, make sure that your test file creates a schema and that it drops the schema at the end of the test to make sure that it doesn't leak any objects behind. See which lines `src/test/regress/bin/create_test.py` adds to the test file to understand what you need to do.

For the object that are not bound to a schema, make sure to drop them at the end of the test too, such as databases and roles.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think our tests should release all the resources it allocated and should not have a dependency other tests. If required, we can copy paste dependency to the new test or we can build an include mechanism if required

Copy link
Member Author

Choose a reason for hiding this comment

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

I think our tests should release all the resources it allocated

Yeah, this is what line 149 is talking about?

should not have a dependency other tests.

Open to your suggestions for that, that you can add via Add suggestion button :)

Let's collaboratively work on this PR together! :)

Copy link
Contributor

@gurkanindibay gurkanindibay left a comment

Choose a reason for hiding this comment

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

Thanks to you to step up and define standards.
I added some comments. Could you evaluate those comments


But when you're asking for a review, you're asking for someone to review your work and provide feedback. So, when you're asking for a review, you're expected to make sure that:

* Your changes don't perform **unnecessary line addition / deletions / style changes on unrelated files / lines**.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we had a tool like black in python to standardize emtpty spaces and lines

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use below formatter?

https://clang.llvm.org/docs/ClangFormat.html

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't know, do you have any observations about the usages of that tool that you'd like to share?

Copy link
Contributor

@JelteF JelteF Dec 11, 2023

Choose a reason for hiding this comment

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

clang-format doesn't work well with our current codestyle the times I tried it. But maybe it's possible to only use it for newlines.

* We also have the habits of using a **lowerCamelCase** for some variables named from their type or from their function name, as shown in the examples:

```c
AlterTableCmd *alterTableCommand = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Global variables use UpperCamelCase, locals variables use lowerCamelCase.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I now understand that this is some special case for a global where we don't, because the typename is so similar. Let's make it clear that this is a special case by showing an example of a normal global too.

}
```

* `#includes` needs to be sorted based on below ordering and then alphabetically and we should not include what we don't need in a file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `#includes` needs to be sorted based on below ordering and then alphabetically and we should not include what we don't need in a file:
* `#includes` needs to be sorted based on below ordering and then alphabetically and we should not include what we don't need in a file:

@@ -0,0 +1,150 @@
# Coding style
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think a better name for this file would be: CONTRIBUTING-styleguide.md (feel free to suggest an even better one)

Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed over chat. Let's go for STYLEGUIDE.md

@@ -0,0 +1,150 @@
# Coding style
Copy link
Contributor

@JelteF JelteF Dec 11, 2023

Choose a reason for hiding this comment

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

I think it's good to prefix this whole file with a disclaimer, saying something like:

The existing codestyle in our codebase is not super consistent. There are multiple reasons for that. One mic reason is because our codebase is relatively old and our standards have changed over time. The second big reason is that our styleguide is different from Postgres its styleguide and some code is copied from postgres source code and slightly modified. The below rules are for new code. If you're changing existing code that uses a different style, use your best judgement to decide if you use the rules here or if you match the existing style.

@@ -1749,8 +1749,6 @@ The reason for handling dependencies and deparsing in post-process step is that

Not all table DDL is currently deparsed. In that case, the original command sent by the client is used. That is a shortcoming in our DDL logic that causes user-facing issues and should be addressed. We do not directly construct a separate DDL command for each shard. Instead, we call the `worker_apply_shard_ddl_command(shardid bigint, ddl_command text)` function which parses the DDL command, replaces the table names with shard names in the parse tree according to the shard ID, and then executes the command. That also has some shortcomings, because we cannot support more complex DDL commands in this manner (e.g. adding multiple foreign keys). Ideally, all DDL would be deparsed, and for table DDL the deparsed query string would have shard names, similar to regular queries.

`markDistributed` is used to indicate whether we add a record to `pg_dist_object` to mark the object as "distributed".
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move all changes to this file to a separate PR. Since it's unrelated (they seem like good changes though).

Copy link
Member Author

Choose a reason for hiding this comment

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

@JelteF
Copy link
Contributor

JelteF commented Jan 10, 2024

Let's update this and get this merged.

* If-and-only-if you're **introducing a user facing change / bugfix**, your PR has a line that starts with `DESCRIPTION: <Present simple tense word that starts with a capital letter, e.g., Adds support for / Fixes / Disallows>`.
* **Commit messages** are clear enough if the commits are doing logically different things.

# Regression test best practices
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this section should go into src/test/regress/README.md

}
```

# Making a pull request ready for reviews
Copy link
Contributor

Choose a reason for hiding this comment

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

This can go to the normal CONTRIBUTING.md file

@@ -0,0 +1,150 @@
# Coding style

* We almost always use **CamelCase**, when naming functions, variables etc., **not snake_case**.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should contain a section at the start about citus_indent, there's currently a good one on this in CONTRIBUTING.md. Let's move that to the top of STYLEGUIDE.md instead.

@onurctirtir onurctirtir dismissed gurkanindibay’s stale review January 31, 2024 08:31

addressed all the comments

@onurctirtir onurctirtir changed the title Add CONTRIBUTING-development.md Add STYLEGUIDE.md and update some other md files on best practices Jan 31, 2024
@onurctirtir onurctirtir enabled auto-merge (squash) January 31, 2024 08:32
CONTRIBUTING.md Outdated
Comment on lines 176 to 178
### Following our coding conventions

CI pipeline will automatically reject any PRs which do not follow our coding
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should at least keep a link to the styleguide here, otherwise people might not find it themselves.

CONTRIBUTING.md Outdated Show resolved Hide resolved
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.

None yet

4 participants