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

Basic Refactoring: Type Annotations, Final & Const Usage #33

Merged
merged 15 commits into from
Nov 2, 2024

Conversation

Marc-R2
Copy link
Contributor

@Marc-R2 Marc-R2 commented Oct 12, 2024

This PR introduces some basic refactoring to improve code readability and maintainability:

  • Added type annotations where possible for better static typing
  • Replaced variables with final where applicable to ensure immutability
  • Used const for constant values (optimize performance)

These changes don't affect the functionality of the package but should improve the overall code quality.

I will continue to break down the larger changes into smaller PRs for easier review and integration.

Thanks!

@lamnhan066
Copy link
Owner

lamnhan066 commented Oct 20, 2024

Hi @Marc-R2

Please let me know if a package or your opinion suggests those changes?

I'm on the way to find a package that has better suggestions than regular lints so we have better code even when adding new code.

Thank you for your PR.

@Marc-R2
Copy link
Contributor Author

Marc-R2 commented Oct 20, 2024

@lamnhan066

These changes are based on some lint-rules from the very_good_analysis 6.0.0 (rules) package.

I like this package, but sometimes some of the rules are a bit harsh. I usually disable (or ignore) at least avoid_print, comment_references and no_duplicate_case_values.
In my experience, code with these lints is very consistent, easy to read, and prevents many problems at compile-time.

I would be happy to add more of these lints if you want.

# Conflicts:
#	test/isolate_manager_shared_test.dart
@lamnhan066
Copy link
Owner

Thank you.

I’ll merge your code and add the very_good_analysis as a dependency after reviewed and all the tests are passed. Sometimes the compiled Worker will have unexpected behaviors when we use a static type instead of a dynamic one.

// Mark the current isolate as busy.
_isolates[isolate] = true;

// Send the `param` to the isolate and wait for the result.
isolate.sendMessage(queue.params).then((value) {
await isolate.sendMessage(queue.params).then((value) {
Copy link
Owner

Choose a reason for hiding this comment

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

We should wrap this code with unawaited instead of using await here because we already used queue.completer.future in return.

We should wrap this code with unawaited instead of using await here because we already used queue.completer.future in return.
@Marc-R2 Marc-R2 requested a review from lamnhan066 November 2, 2024 16:47
@lamnhan066
Copy link
Owner

LGTM!

Thank you for your contributions.

@lamnhan066 lamnhan066 merged commit 6f51f78 into lamnhan066:main Nov 2, 2024
1 check passed
@Marc-R2 Marc-R2 deleted the refactor branch November 3, 2024 00:47
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.

2 participants