-
Notifications
You must be signed in to change notification settings - Fork 52
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
This issue is for tracking the code refactoring status of this repo. The main goal is to improve
- Overall code quality
- Readability and maintainability
- Consistency
of all C++ code.
Here are some general rules for styling the code:
- Everything from the Google C++ Style Guide.
- Structure:
- If the plugin class (which defines the
RegisterWithRegistrarmethod) is too large (over 150 lines), consider breaking it into multiple classes.- The classes should have a clean design so that their roles can be easily known from their signatures. Ideally, the plugin class should be the only one that interacts with the underlying platform channel (processes method arguments and generates results), and other classes should not touch any Flutter API (
flutter/*.h).
- The classes should have a clean design so that their roles can be easily known from their signatures. Ideally, the plugin class should be the only one that interacts with the underlying platform channel (processes method arguments and generates results), and other classes should not touch any Flutter API (
- Enclose the plugin class within an anonymous namespace.
- If you're writing a Tizen C API wrapper, avoid exposing Tizen-defined types (including enums) in its public interface.
- Minimize use of output parameters when writing a function that returns a value. Consider using the
GetLastErrorpattern (example) or defining your own result type such asTizenResult.- Consider making use of C++ exceptions if they make the code simpler and easier to understand (e.g. multiple platform API invocations per single method call). See this comment for other available options.
- Consider creating an explicit stream handler class that extends
flutter::StreamHandlerif the plugin makes use of event channels. (example)
- If the plugin class (which defines the
- Logging (
log.h):- Avoid unnecessary logging. Minimize use of debug logs (
LOG_DEBUG) in the final code. - Every log should provide useful information. Any information that is already known to the caller (through a
PlatformExceptionobject) is redundant. Instead, provide some additional context about the error so that the developer can easily debug the underlying issue.
- Avoid unnecessary logging. Minimize use of debug logs (
- Method call handling:
- Consider using
GetValueFromEncodableMapto extract arguments from anEncodableMap. - Prefer
==over.compare()when comparing strings.const auto &method_name = method_call.method_name(); if (method_name == "wifiName") { ... }
- An error code (the first argument of
result->Error()) should be either:- A return code (number converted to a string)
- Invalid argument
- Invalid operation
- Operation failed/cancelled
- Permission denied
- Internal error
- etc.
- Do not skip the second argument (error message) of
result->Error()whenever possible.
- Consider using
- Variable naming convention:
- Use a local variable
retto store the return code of a Tizen API call. - Use a local variable
selforpluginto store a pointer to the current class.
- Use a local variable
- Other recommendations:
- Remove any unused includes (especially standard library headers).
- Prefer
if (value)overif (value != nullptr). - Consider inlining a C-style callback using a lambda expression if it makes the code cleaner.
- Prefer fixed-width integer types (
int32_t,int64_t) over plain old integer types (int,long long). This is not a strict requirement, and there are places where a plainintfits best. Also, you should avoid use of unsigned integer types.
I will start with 1st-party plugins and plus package implementations (there are already some PRs open). If you want to contribute to this project, you may start with 3rd-party plugins and Tizen-only plugins, or plugins authored by you if you have any.
Any comments are welcome. Please let me know if anything in the above is unclear.
bbrto21, HakkyuKim, bwikbs, JRazek and xiaowei-guan