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

Suggest refactor plan #21

Open
KedoKudo opened this issue Nov 20, 2024 · 0 comments
Open

Suggest refactor plan #21

KedoKudo opened this issue Nov 20, 2024 · 0 comments

Comments

@KedoKudo
Copy link
Collaborator

I would like to suggest the following refactor plan for PLEIADES as the current code architecture is a bit difficult to maintain and extend with new features:

High-Level Refactor Plan for PLEIADES Project

Importance Ranking Task Difficulty Description
High Introduce Classes for Modularization Medium Encapsulate key functionalities in classes such as PleiadesConfig (to handle configuration) and classes like SammyInputHandler, SammyOutputHandler, and SimDataProcessor to organize logic and responsibilities. This will simplify code reuse, testing, and maintenance.
High Refactor Large Functions into Smaller Sub-Functions Medium Break down large functions into smaller, focused sub-functions that each perform a single task. This will improve code readability, testability, and reduce the risk of errors. Prioritize functions with deeply nested loops and conditionals.
High Centralize Configuration Handling Medium Create a PleiadesConfig class that reads configurations from .ini files and makes them easily accessible. Ensure each module accesses configuration through this centralized point rather than reading the .ini files directly. This will eliminate redundant configuration access code and potential inconsistencies. See pydantics at the bottom for more info.
High Enhance Error Handling Medium-High Implement consistent error handling across file I/O, parsing, and data processing using try-except blocks and informative logging. This will enhance robustness, making it easier to diagnose issues when they arise.
High Expand Unit Test Coverage and Add Integration Tests High Improve the current test suite to include more comprehensive unit tests and integration tests that verify modules working together correctly. Emphasize testing of edge cases, exception handling, and configuration validation. This is essential to ensure code correctness as the refactoring proceeds.
Medium Introduce Type Hinting for Functions Low-Medium Add type hints to functions to make it easier for developers to understand input and output types. This will also help with static analysis tools like mypy and improve the overall quality of the codebase.
Medium Create Utility Modules for Common Operations Medium Create dedicated utility modules, such as file_utils.py for file handling, plot_utils.py for plotting, and data_utils.py for common data manipulations. This will reduce code redundancy and centralize key functionalities for easier updates.
Medium Standardize Code Formatting and Naming Conventions Low We are already using pre-commit with ruff for code formatting, but the naming convention needs to be enforced for better readability.
Medium Introduce Logging for Debugging Medium Replace print() statements with Python’s logging library for better control over the logging levels (INFO, DEBUG, WARNING). This will allow for better debugging and give users a better understanding of what is happening during runtime.
Low Refactor Plotting Functions for Consistency Low-Medium If the code includes visualization, refactor all plotting functions to use a consistent style (e.g., colors, labels, and titles). Use helper functions in a utility module to avoid repeated code. This will improve consistency across the visual output.
Low Adopt dataclasses for Simple Data Structures Low-Medium Replace simple data classes in sammyStructures.py or other files with Python’s dataclasses (if no validation required) or pydantic (validation needed). This will reduce boilerplate code and make data structures more readable and concise.
Low Automate Configuration Validation Using Pydantic Medium Use a library like pydantic for validation of configuration parameters to make sure input configurations are validated before they are used. This is particularly helpful in catching incorrect or missing values early.

In addition to the code refactoring above, I would also like to suggest enable Github action for this repo (after unit tests are added and configured).

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

No branches or pull requests

1 participant