Skip to content

Conversation

@dorin-iancu
Copy link
Contributor

Description of the pull request (what is new / what has changed)

Did you test the changes locally ?

  • yes
  • no

Which category (categories) does this pull request belong to?

  • document new feature
  • update documentation that is not relevant anymore
  • add examples or more information about a component
  • fix grammar issues
  • other

mihaicalinluca
mihaicalinluca previously approved these changes Jun 17, 2024

## Code Placement

The lib.rs file should contain only the init and upgrade functions most of the time. Sometimes it's tempting to bundle a bunch of unrelated functions there, but don't. You'll end up with a lib.rs file of 500 lines.
Copy link
Contributor

Choose a reason for hiding this comment

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

Code formatting, NTH. E.g. init instead of init etc.


## Code Placement

The lib.rs file should contain only the init and upgrade functions most of the time. Sometimes it's tempting to bundle a bunch of unrelated functions there, but don't. You'll end up with a lib.rs file of 500 lines.
Copy link
Contributor

Choose a reason for hiding this comment

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

of 500 lines -> be less specific e.g. "with a unreasonably large file".


## Function Size

Each function should be 30-50 lines. Any more than that and it's really hard to navigate the file.
Copy link
Contributor

Choose a reason for hiding this comment

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

... at most 30-50 (actually, even 30-line functions are extremely large).


## Module Placement

Each module can be placed in its own folder along with other related modules. Sure, splitting the code is nice, but having to navigate through 20 files, all at the level of lib.rs, doesn't help at all. This makes it even easier to search for specific features.
Copy link
Contributor

Choose a reason for hiding this comment

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

through 20 - be less specific e.g. "through a large number of files".

doesn't help at all - maybe replace with "might be cumbersome" (somehow friendlier).


## Error Messages

If you have the same error message in multiple places, it's better to declare a static with the message and use that instead of copy-pasting the message. If you have the same condition too, consider having a separate `require_X` function.
Copy link
Contributor

Choose a reason for hiding this comment

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

A short snippet below the guideline would be helpful.


## Small PRs

Unless you're mass-upgrading everything, in which case you really have no other choice, it's much better to keep your PRs focused on one specific task. Also much easier for reviewers to spot issues instead of simply giving you a green and moving on.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe drop the "instead of simply giving you a green and moving on" - its' sufficient to say: "Also it's much easier for reviewers to spot issues".

@dorin-iancu dorin-iancu merged commit d5ee8d8 into development Jun 19, 2024
@dorin-iancu dorin-iancu deleted the best-practices-update branch June 19, 2024 06:11
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.

5 participants